cancel
Showing results for 
Search instead for 
Did you mean: 

Dual bank boot up from bank2 is not saved in STM32F427VG

melfice
Associate

Hello,

 

I am working on a product with dual banks enabled. In each banks, there are one bootloader and application. In bank1's bootloader, if new application arrived, it will update bank2's application and then reset and boot from bank2. 

I meet a problem that the boot from bank 2 is not saved after power off. The code always boot from bank 1, after it lost power. In design, it should boot from the same bank as previous, while there is no firmware update. 

Attached my code for setting OB_BFB2_ENABLE after firmware upgrade.

Thank you for assistances.

 

Melfice

1 ACCEPTED SOLUTION

Accepted Solutions
melfice
Associate

For records, I have managed to implement the dual bank code. 

 

{

FLASH_OBProgramInitTypeDef OBInit;

FLASH_AdvOBProgramInitTypeDef AdvOBInit;

 

HAL_FLASH_Unlock();

__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPERR);

HAL_FLASH_OB_Unlock();

HAL_FLASHEx_OBGetConfig(&OBInit);

 

OBInit.OptionType = OPTIONBYTE_USER;

 

HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit);

AdvOBInit.OptionType = OPTIONBYTE_BOOTCONFIG;

 

if ((AdvOBInit.BootConfig &OB_DUAL_BOOT_ENABLE)==OB_DUAL_BOOT_ENABLE) {

AdvOBInit.BootConfig &= (~OB_DUAL_BOOT_ENABLE);

} else {

AdvOBInit.BootConfig |= OB_DUAL_BOOT_ENABLE;

}

 

if (HAL_FLASHEx_AdvOBProgram(&AdvOBInit) != HAL_OK)

{

Error_Handler();

}

 

if (HAL_FLASHEx_OBProgram(&OBInit) != HAL_OK) {

Error_Handler();

}

if (HAL_FLASH_OB_Launch() != HAL_OK) {

Error_Handler();

}

HAL_FLASH_OB_Lock();

HAL_FLASH_Lock();

}

View solution in original post

2 REPLIES 2
Sarra.S
ST Employee

Hello @melfice

Make sure that the system memory is remapped correctly by setting the SYSCFG->MEMRMP register, 

As noted in AN2606On devices with dual bank boot, to jump to system memory from user code the user must
first remap the system memory bootloader at address 0x00000000 using SYSCFG register
(except for STM32F7 series), then jump to bootloader"

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

melfice
Associate

For records, I have managed to implement the dual bank code. 

 

{

FLASH_OBProgramInitTypeDef OBInit;

FLASH_AdvOBProgramInitTypeDef AdvOBInit;

 

HAL_FLASH_Unlock();

__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPERR);

HAL_FLASH_OB_Unlock();

HAL_FLASHEx_OBGetConfig(&OBInit);

 

OBInit.OptionType = OPTIONBYTE_USER;

 

HAL_FLASHEx_AdvOBGetConfig(&AdvOBInit);

AdvOBInit.OptionType = OPTIONBYTE_BOOTCONFIG;

 

if ((AdvOBInit.BootConfig &OB_DUAL_BOOT_ENABLE)==OB_DUAL_BOOT_ENABLE) {

AdvOBInit.BootConfig &= (~OB_DUAL_BOOT_ENABLE);

} else {

AdvOBInit.BootConfig |= OB_DUAL_BOOT_ENABLE;

}

 

if (HAL_FLASHEx_AdvOBProgram(&AdvOBInit) != HAL_OK)

{

Error_Handler();

}

 

if (HAL_FLASHEx_OBProgram(&OBInit) != HAL_OK) {

Error_Handler();

}

if (HAL_FLASH_OB_Launch() != HAL_OK) {

Error_Handler();

}

HAL_FLASH_OB_Lock();

HAL_FLASH_Lock();

}