Skip to main content
Visitor II
February 11, 2025
Solved

Dual bank boot up from bank2 is not saved in STM32F427VG

  • February 11, 2025
  • 2 replies
  • 602 views

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

    This topic has been closed for replies.
    Best answer by melfice

    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();

    }

    2 replies

    ST Employee
    February 12, 2025

    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"

    melficeAuthorAnswer
    Visitor II
    February 20, 2025

    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();

    }