STM32G0B1RE - How to switch to bank2 in dualbank mode?
I use this code to switch to bank2 after downloaded fw image in bank2. I have verified that the first address is (stack pointer) is pointing to the SRAM. But still it starts the code in bank1.
Is there any example that I can follow?
/* Unlock option bytes */
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
/* Read option bytes */
HAL_FLASHEx_OBGetConfig(&opb);
/* Modify */
if ((opb.USERConfig & OB_USER_DUALBANK_SWAP_DISABLE) == OB_USER_DUALBANK_SWAP_DISABLE) {
/* Switch to bank 2 */
LOG_INF("Switch to bank 2");
opb.USERConfig = OB_USER_DUALBANK_SWAP_ENABLE;
} else {
/* switch to bank 1 */
LOG_INF("Switch to bank 1");
opb.USERConfig = OB_USER_DUALBANK_SWAP_DISABLE;
}
opb.OptionType = OPTIONBYTE_USER;
opb.USERType = OB_USER_BANK_SWAP;
/* Program user option byte */
HAL_FLASHEx_OBProgram(&opb);
/* Load option bytes and reset */
HAL_FLASH_OB_Launch();
