cancel
Showing results for 
Search instead for 
Did you mean: 

bor stm32 programming

Luis Ber
Associate II
Posted on May 09, 2018 at 18:12

Can someone show me a simple program to read and write the option bytes on the STM32L476VGT using the STM32 HAL libraries? I only want to change USER parameters values, as the BOR level.

I'm trying the following code, but the microprocessor is continuosly reset:

FLASH_OBProgramInitTypeDef optionsBytes;

/* Unlock the Flash to enable the flash control register access *************/

HAL_FLASH_Unlock();

/* Unlock the Options Bytes *************************************************/

HAL_FLASH_OB_Unlock();

/* Get pages write protection status ****************************************/

HAL_FLASHEx_OBGetConfig(&optionsBytes);

/* Check if readoutprtection is enabled ***********************/

if((optionsBytes.USERConfig) != OB_BOR_LEVEL_1)

{

   optionsBytes.OptionType = OPTIONBYTE_USER; /* Option byte to be configured: */

   optionsBytes.USERConfig = OB_BOR_LEVEL_2;

   optionsBytes.USERType = OB_USER_BOR_LEV;

   

   if(HAL_FLASHEx_OBProgram(&optionsBytes) != HAL_OK)

   {

      /* Error occurred while options bytes programming. **********************/

      while (1)

      {

      }

   }

   /* Generate System Reset to load the new option byte values ***************/

   HAL_FLASH_OB_Launch();

}

/* Lock the Options Bytes *************************************************/

HAL_FLASH_OB_Lock();

Can someone explains why is the microprocessor continuously reset? The parameter USERType of the options byte must be used?

Any suggestions or examples would be greatly appreciated. 

Thank you in advance,

Luis

#bor #stm32l4+ #flash #option-bytes
0 REPLIES 0