AnsweredAssumed Answered

bor stm32 programming

Question asked by Luis Ber on May 9, 2018

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 *************/


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


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


/* 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 ***************/


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


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,