Question
STM32G473QET6 Dual Bank/Boot Mode Question
I am having some issues implementing dual bank/boot.
I have set up a dummy project starting at base address 0x08000000 for 256k bytes that will turn on a red LED
I have another dummy project starting at base address 0x08040000 for 256k bytes that will turn on a green LED
Based on the example from 474 Dual Boot Mode, it seems you set the system in DBANK mode by setting the bit in FLASH_OPTR as well as setting the BF2B bit.
Now I am confused if the BF2B forces booting from bank 2 or it just means it is allowed, cause I also see the function
HAL_SYSCFG_EnableMemorySwappingBank(); // stm32g4xx_hal.c line 591
Does calling this function and setting the SYSCFG_MEMRMP_FB_MODE bit cause the swap? or is this bit used to show where you booted from?
right now I call this, and it crashes at HAL_FLASH_OB_Launch(), I do see dbank bit is set but never the BF2B bit or the SYSCFG_MEMRMP_FB_MODE bit, even after calling the above function.
FLASH_OBProgramInitTypeDef OBInit;
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
HAL_FLASH_OB_Unlock();
HAL_FLASHEx_OBGetConfig(&OBInit);
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;
}
if (HAL_FLASHEx_OBProgram(&OBInit) != HAL_OK) {
// uint32_t errorCode = HAL_FLASH_GetError();
while (1) {
HAL_Delay(1000);
//HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}
}
if (HAL_FLASH_OB_Launch() != HAL_OK) {
//uint32_t errorCode = HAL_FLASH_GetError();
while (1) {
HAL_Delay(100);
//HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}
}
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
Any help would be appreciated.
HAL_FLASH_OB_Launch seems to reset MCU and I never get to HAL_FLASH_OB_Lock(); this seems unexpected behaviour
