Answers for "stm32 bor example"

0

stm32 bor example

#define BOR_LEVEL_MASK                                          ((uint32_t)0x0000FF00)

#define BOR_LEVEL_1_7V                                          ((uint32_t)0xF800)
#define BOR_LEVEL_2_0V                                          ((uint32_t)0xF900)
#define BOR_LEVEL_2_2V                                          ((uint32_t)0xFA00)
#define BOR_LEVEL_2_5V                                          ((uint32_t)0xFB00)
#define BOR_LEVEL_2_8V                                          ((uint32_t)0xFC00)

/*
* chnage the brown out reset to another level
* device stm32l4
* whne the bor chnage the MCU reset, for the second time will not enter to the function because already saved
* By ABDERAHMAN HAOUDI
*/
uint8_t changeBrownOutReset(uint32_t bor_level){

    FLASH_OBProgramInitTypeDef pOBInit;
  
    HAL_FLASHEx_OBGetConfig(&pOBInit);

    if((pOBInit.USERConfig & BOR_LEVEL_MASK) != BOR_LEVEL_2_2V){ //0xFFBFFB00
      
          HAL_FLASH_Unlock();
          ///__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR); 
          HAL_FLASH_OB_Unlock();
          
          pOBInit.OptionType  = OPTIONBYTE_USER;
          pOBInit.USERType    = OB_USER_BOR_LEV;
          pOBInit.USERConfig  = bor_level;
          
          //FLASH_OB_UserConfig(pOBInit.USERType, pOBInit.USERConfig);
            
          if(HAL_FLASHEx_OBProgram(&pOBInit) != HAL_OK){
              return 0;
          }
          
          HAL_FLASH_OB_Launch();
          HAL_FLASH_OB_Lock();
          HAL_FLASH_Lock();
          
          return 1;
          
    }else return 0;
}
Posted by: Guest on August-30-2021

Browse Popular Code Answers by Language