AnsweredAssumed Answered

STM32L1xx SPL 1.3.0: Bug - FLASH_OB_GetUser() shifts too many bits right

Question asked by Phil Pemberton on Dec 18, 2014
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();
          }

Outcomes