2019-01-29 05:37 AM
FLASH_OBProgramInitTypeDef OBInit;
/* Set BFB2 bit to enable boot from Flash Bank2 */
/* Allow Access to Flash control registers and user Flash */
HAL_FLASH_Unlock();
/* Clear OPTVERR bit set on virgin samples */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
/* Allow Access to option bytes sector */
HAL_FLASH_OB_Unlock();
/* Get the Dual boot configuration status */
HAL_FLASHEx_OBGetConfig(&OBInit);
/* Enable/Disable dual boot feature */
OBInit.OptionType = OPTIONBYTE_USER;
OBInit.USERType = OB_USER_BFB2;
if (((OBInit.USERConfig) & (OB_BFB2_ENABLE)) == OB_BFB2_ENABLE) {
OBInit.USERConfig = OB_BFB2_DISABLE;
} else {
OBInit.USERConfig = OB_BFB2_ENABLE;
}
HAL_FLASHEx_OBProgram(&OBInit)
HAL_FLASH_OB_Launch();
HAL_NVIC_SystemReset();