cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G473 BFB2 Not Working

kip18
Associate II

BFB2 Set, but never enter Bank2 program.

Boot0 = 0
Boot1 = 1

I can run the 2 programs from cubeide in there respective locations and ISR work when BFB2 is set for the BANK I am debugging in. However I never enter BANK2 program on resetting/powercycling when BFB2 is set.

Bootloader Version is 0xD5

Does setting this bit somehow need to be utilized at some point or is it just an indicator of what bank we are in

uint32_t mapped = READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_FB_MODE);

I never see this high, which may be because I never enter bank2

Stack pointer is set to 

_estack = ORIGIN(RAM) + LENGTH(RAM) ; /* end of "SRAM" type memory */

 

BFB2 Dual Bank Boot does not work as expected. My understanding is this is a valid stack pointer, I have also tried additional stackpointer locations with no luck

3 REPLIES 3
Imen.D
ST Employee

Hello @kip18 ,

Which Bootloader version used?

If you look at the RM0440 / Rev8 / Page 91, there is this statement:
To select boot from flash memory bank 2, set the BFB2 bit in the user option bytes. When this bit is set and the boot pins are in the boot from main flash memory configuration, the device boots from system memory, and the bootloader jumps to execute the user application programmed in flash memory bank 2. For further details, refer to AN2606. See Table 13: Access status versus protection level and execution modes for bootloader function for different RDP levels.

If bootloader version is lower than V13.4 (0xD4) then the project might not work as expected due to known limitation on Bootloader. 

In that case, it is possible to make the project work by changing the option bytes values as below:
BFB2=1, nBOOT0=1 and nBOOT1=0,
The Bootloader version can be found in the address 0x1FFF6FFE and should be 0xD4 or higher.
For more details, please refer to "AN2606 STM32 microcontroller system memory boot mode" Application note.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Bootloader version is 0xD5, which says no limitations. I have also tried moving the stack pointer per the 0xD4 limitation, still did not work.

My boot pins are set to boot from flash as specified. boot0 is from external pin pulled low, have tried overriding it with the boot options to ensure boot0 = 0 and boot1 =1 and still does not enter bank2 with BFB2

Regardless of BFB2 Being set I am always running from BANK1

kip18_0-1708710763419.png

RDP is always level 0 : 0xAA

 

I could give you a sample program but it is just an LED be toggled in BANK1 and then identical program but different LED is toggled in BANK2. Regardless of BFB2 bit being set the internal bootloader only goes to bank 1. I can see it in system memory on restart, but proceeds to bank1

 

 

READ_BIT(SYSCFG->MEMRMP, 0x1 << 8);

 

 

Lots of people say this is cleared on reset, my understanding is the internal boot loader would set this. this never happens don't know if that's an issue or if thats because internal bootloader never chooses bank2 to jump too.

 

I have attached an example for STM32G474 modified for STM32G473, that will write a program to bank2 and then set the option bits and launch. Never does it show bank2 active, maybe an issue with that bit or bootloader throws out the program. I want to reiterate I have also done two identical programs with different LED toggling and used STMCubeProgrammer to flash and activate the OptionByte for BFB2 with no success.

 

LL_SYSCFG_SetFlashBankMode(LL_SYSCFG_BANKMODE_BANK2);

 

if I manually set this bit at the start of program execution if BFB2 is set then I get the desired behaviour.

is this the expected implementation? seems wrong. I'll have to insert a BFB2 check at the start of program execution and then remap manually myself.

 

my workaround is calling this prior to anything happening, need to set vector table to 0x08000000 as well

    FLASH_OBProgramInitTypeDef OBInit;
    HAL_FLASH_Unlock();
    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
    HAL_FLASH_OB_Unlock();
    HAL_FLASHEx_OBGetConfig(&OBInit);

    if (((OBInit.USERConfig) & (OB_BFB2_ENABLE)) == OB_BFB2_ENABLE) {
        LL_SYSCFG_SetFlashBankMode(LL_SYSCFG_BANKMODE_BANK2);
    } else {
        LL_SYSCFG_SetFlashBankMode(LL_SYSCFG_BANKMODE_BANK1);
    }

    HAL_FLASH_OB_Lock();
    HAL_FLASH_Lock();

 

Seems like a hack and the documentation doesn't explain this and possibly is an errata cause the 474 example doesn't account for this.