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

Outcomes