cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G473QET6 Dual Bank/Boot Mode Question

kip18
Associate II

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
1 REPLY 1
kip18
Associate II

this never reads as set unless I set it, READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_FB_MODE);

I have created two programs that are identical other than the light they flash, the program residing in bank2 is never run, I have modified the stack pointer based on a previous workaround stated for a bootloader at D3 or less. I am at D5 when reading the address.

STM32G474 example workaround 

Do I need to set SYSCFG_MEMRMP_FB_MODE or is it set by the internal bootloader that if BF2B bit is set it will check for a valid program in bank2 and then run it.

The documentation is unclear, I have tried connecting with StmCubeProgrammer and flashed both binarys to 0x08000000 and 0x08040000 and toggled the BF2B bit but I have not been able to run from Bank2