/** * @brief Get the Option byte configuration * @note The parameter Banks of the pOBInit structure must be exclusively FLASH_BANK_1 or FLASH_BANK_2 as this parameter is use to get the given Bank WRP, PCROP and secured area. * @param pOBInit pointer to an FLASH_OBInitStruct structure that * contains the configuration information for the programming. * * @retval None */ void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) { /* Check the parameters */ assert_param(IS_FLASH_BANK_EXCLUSIVE(pOBInit->Banks)); pOBInit->OptionType = (OPTIONBYTE_WRP | OPTIONBYTE_RDP | \ OPTIONBYTE_USER | OPTIONBYTE_PCROP | \ OPTIONBYTE_BOR | OPTIONBYTE_BOOTADD | \ OPTIONBYTE_SECURE_AREA); /* Get write protection on the selected area */ FLASH_OB_GetWRP(&(pOBInit->WRPState), &(pOBInit->WRPSector), pOBInit->Banks); /* Get Read protection level */ pOBInit->RDPLevel = FLASH_OB_GetRDP(); /* Get the user option bytes */ pOBInit->USERConfig = FLASH_OB_GetUser(); /* Get the Proprietary code readout protection */ FLASH_OB_GetPCROP(&(pOBInit->PCROPConfig), &(pOBInit->PCROPStartAddr), &(pOBInit->PCROPEndAddr), pOBInit->Banks); /*Get BOR Level*/ pOBInit->BORLevel = FLASH_OB_GetBOR(); /*Get Boot Address*/ FLASH_OB_GetBootAdd(&(pOBInit->BootAddr0), &(pOBInit->BootAddr1)); /*Get Bank Secure area*/ FLASH_OB_GetSecureArea(&(pOBInit->SecureAreaConfig), &(pOBInit->SecureAreaStartAddr), &(pOBInit->SecureAreaEndAddr), pOBInit->Banks); }
/** * Check the brown out reset threshold is 2.7 volts and if not * resets it. This solves an issue that can prevent boards * powering up with some BEC */ void check_bor() { uint8_t bor = FLASH_OB_GetBOR(); if(bor != OB_BOR_LEVEL3) { FLASH_OB_Unlock(); FLASH_OB_BORConfig(OB_BOR_LEVEL3); FLASH_OB_Launch(); while(FLASH_WaitForLastOperation() == FLASH_BUSY); FLASH_OB_Lock(); while(FLASH_WaitForLastOperation() == FLASH_BUSY); } }
TM_BOR_Level_t TM_BOR_Get(void) { /* Get BOR value */ switch (FLASH_OB_GetBOR()) { case OB_BOR_LEVEL3: return TM_BOR_Level_3; case OB_BOR_LEVEL2: return TM_BOR_Level_2; case OB_BOR_LEVEL1: return TM_BOR_Level_1; case OB_BOR_OFF: default: return TM_BOR_Level_None; } }
/** * @brief Get the Option byte configuration * @param pOBInit: pointer to an FLASH_OBInitStruct structure that * contains the configuration information for the programming. * * @retval None */ void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) { pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_BOR; /*Get WRP*/ pOBInit->WRPSector = (uint32_t)FLASH_OB_GetWRP(); /*Get RDP Level*/ pOBInit->RDPLevel = (uint32_t)FLASH_OB_GetRDP(); /*Get USER*/ pOBInit->USERConfig = (uint8_t)FLASH_OB_GetUser(); /*Get BOR Level*/ pOBInit->BORLevel = (uint32_t)FLASH_OB_GetBOR(); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* Initialize LED1 on EVAL board */ STM_EVAL_LEDInit(LED1); /* Initialize Key Button mounted on EVAL board */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* Test if Key push-button on EVAL Board is pressed */ if (STM_EVAL_PBGetState(BUTTON_KEY) == 0x00) { /* Get BOR Option Bytes */ if((FLASH_OB_GetBOR() & 0x0C) != BOR_LEVEL) { /* Unlocks the option bytes block access */ FLASH_OB_Unlock(); /* Select the desired V(BOR) Level */ FLASH_OB_BORConfig(BOR_LEVEL); /* Launch the option byte loading */ FLASH_OB_Launch(); /* Locks the option bytes block access */ FLASH_OB_Lock(); } } while (1) { /* Toggle LED1 */ STM_EVAL_LEDToggle(LED1); /* Inserted Delay */ for(uwCounter = 0; uwCounter < 0x5FFFF; uwCounter++); } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32l1xx_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ /* Initialize LED1 */ STM_EVAL_LEDInit(LED1); /* Get BOR Option Bytes */ BOROptionBytes = FLASH_OB_GetBOR(); #ifdef BOR_MODIFY if((BOROptionBytes & 0x0F) != BOR_LEVEL) { /* Unlocks the option bytes block access */ FLASH_OB_Unlock(); /* Clears the FLASH pending flags */ FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR); /* Select the desired V(BOR) Level ---------------------------------------*/ FLASH_OB_BORConfig(BOR_LEVEL); /* Launch the option byte loading */ FLASH_OB_Launch(); } #endif while (1) { /* Toggle The LED1 */ STM_EVAL_LEDToggle(LED1); /* Inserted Delay */ for(Counter = 0; Counter < 0x5FFFF; Counter++); } }
void set_bor(void) { __IO uint32_t BOROptionBytes = 0; /* Get BOR Option Bytes */ BOROptionBytes = FLASH_OB_GetBOR(); if((BOROptionBytes & 0x0F) != BOR_LEVEL) { /* Unlocks the option bytes block access */ FLASH_OB_Unlock(); /* Clears the FLASH pending flags */ FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR); /* Select the desired V(BOR) Level ---------------------------------------*/ FLASH_OB_BORConfig(BOR_LEVEL); /* Launch the option byte loading */ FLASH_OB_Launch(); FLASH_OB_Lock(); } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32l1xx_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ /* Enable PWR APB1 Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_RTCAccessCmd(ENABLE); /* Reset RTC Domain */ RCC_RTCResetCmd(ENABLE); RCC_RTCResetCmd(DISABLE); #ifdef BOR_MODIFY /* Get BOR Option Bytes */ BOROptionBytes = FLASH_OB_GetBOR(); if((BOROptionBytes & 0x0F) != BOR_LEVEL) { /* Unlocks the option bytes block access */ FLASH_OB_Unlock(); /* Clears the FLASH pending flags */ FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR); /* Select the desired V(BOR) Level ---------------------------------------*/ FLASH_OB_BORConfig(BOR_LEVEL); /* Launch the option byte loading */ FLASH_OB_Launch(); } #endif #if defined (LP_RUN_SRAM_MODE) /* Low Power Run Mode Entry: - System Running at MSI (~32KHz) - Flash 0 wait state - Voltage Range 2 - Code running from Internal SRAM - All peripherals OFF - FLASH switched OFF - VDD from 1.65V to 3.6V - Current Consumption ~10.5uA - Wakeup using Key Button PA.00 */ LowPowerRunMode_Measure(); #elif defined (LP_RUN_FLASH_MODE) /* Low Power Run Mode Entry: - System Running at MSI (~32KHz) - Flash 0 wait state - Voltage Range 2 - Code running from Internal FLASH - All peripherals OFF - VDD from 1.65V to 3.6V - Current Consumption ~25uA - Wakeup using Key Button PA.00 */ LowPowerRunMode_Measure(); #elif defined (SLEEP_MODE) /* Sleep Mode Entry - System Running at HSI (16MHz) - Flash 1 wait state - Voltage Range 2 - Code running from Internal FLASH - Current Consumption ~1mA - Wakeup using EXTI Line (Key Button PA.00) */ SleepMode_Measure(); #elif defined (LP_SLEEP_MODE) /* Low Power Sleep Mode Entry - System Running at MSI (~32KHz) - Flash 0 wait state - Voltage Range 2 - Code running from Internal FLASH - All peripherals OFF - VDD from 1.65V to 3.6V - Current Consumption ~4.07uA - Wakeup using EXTI Line (Key Button PA.00) */ LowPowerSleepMode_Measure(); #elif defined (STOP_MODE) /* STOP Mode Entry - Regulator in LP mode - LSI, HSI and HSE OFF - No IWDG - Current Consumption ~0.5uA - Wakeup using EXTI Line (Key Button PA.00) */ StopMode_Measure(); #elif defined (STOP_RTC_LSE_MODE) /* STOP Mode with RTC on LSE Entry - RTC Clocked by LSE external Clock (32.768KHz) - Regulator in LP mode - LSI, HSI and HSE OFF - No IWDG - Current Consumption ~1.6uA - Automatic Wakeup using RTC on LSE (4s) */ StopRTCLSEMode_Measure(); #elif defined (STOP_RTC_LSI_MODE) /* STOP Mode with RTC on LSI Entry - RTC Clocked by LSI - Regulator in LP mode - HSI and HSE OFF - No IWDG - Current Consumption ~1.3uA - Automatic Wakeup using RTC on LSI (after ~4s) */ StopRTCLSIMode_Measure(); #elif defined (STANDBY_MODE) /* STANDBY Mode Entry - IWDG and LSI OFF - Current Consumption ~0.3uA - Wakeup using WakeUp Pin 1 (PA.00) */ StandbyMode_Measure(); #elif defined (STANDBY_RTC_LSE_MODE) /* STANDBY Mode with RTC on LSE Entry - RTC Clocked by LSE external Clock (32.768KHz) - IWDG and LSI OFF - Current Consumption ~1.3uA - Automatic Wakeup using RTC on LSE (after 4s) */ StandbyRTCLSEMode_Measure(); #elif defined (STANDBY_RTC_LSI_MODE) /* STANDBY Mode with RTC on LSI Entry - RTC Clocked by LSI - IWDG OFF - Current Consumption ~1.1uA - Automatic Wakeup using RTC on LSI (after ~4s) */ StandbyRTCLSIMode_Measure(); #else /* Initialize LED1 on STM32L152-EVAL board */ STM_EVAL_LEDInit(LED1); /* Infinite loop */ while (1) { /* Toggle The LED1 */ STM_EVAL_LEDToggle(LED1); /* Inserted Delay */ for(Counter = 0; Counter < 0x5FF; Counter++); } #endif }