2014-12-18 02:40 AM
Yet another bug / gotcha with the SPL...
FLASH_OB_GetUser() shifts the User option bits right 20 bits, which means that if you try to compare against the OB_IWDG_SW/HW, OB_STOP_RST or OB_STDBY_RST constants, you'll never get a comparison match.The workaround for this one is to do an additional shift of 4 bits before comparing: // Make sure the IWDG watchdog is enabled on startup if (((FLASH_OB_GetUser() << 4) & OB_IWDG_SW) == OB_IWDG_SW) { printf(''OptionBytes: IWDG not enabled, updating...\n''); // Unlock option bytes and set IWDG, Reset-on-STOP and Reset-on-Standby FLASH_OB_Unlock(); FLASH_OB_UserConfig(OB_IWDG_HW, OB_STOP_RST, OB_STDBY_RST); FLASH_OB_Launch(); }