cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0B1RE - How to switch to bank2 in dualbank mode?

MNils.2
Associate

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

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @Imen DAHMEN​ , sorry it won't help. I checked the dual bank controls on the G0 more closely today and it's simplified compared to for example G4 so the X-CUBE-DBFU won't work on it.

But that's also good news for @MNils.2​ , because the dual bank is really very simple to manage. How do you determine on which bank is your code running? Because besides the difference in code itself, there is no indicator in G0. If you load two codes in banks 1 and 2, with only difference being that one displays "code A" and the other "code B", you should see the code from bank 2 running after reset when the OB bit nSWAP_BANK is modified.

Rgds,

Jarda

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.

View solution in original post

2 REPLIES 2
Imen.D
ST Employee

Hello @MNils.2​ and welcome to the Community 🙂

The DBFU example should work on the dual bank STM32G0 and will help you on your request: X-CUBE-DBFU - On-the-fly firmware update for dual bank STM32 microcontrollers (AN4767)

You can refer to this AN4767 to perform safely the switch to bank2.

Imen

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

Hello @Imen DAHMEN​ , sorry it won't help. I checked the dual bank controls on the G0 more closely today and it's simplified compared to for example G4 so the X-CUBE-DBFU won't work on it.

But that's also good news for @MNils.2​ , because the dual bank is really very simple to manage. How do you determine on which bank is your code running? Because besides the difference in code itself, there is no indicator in G0. If you load two codes in banks 1 and 2, with only difference being that one displays "code A" and the other "code B", you should see the code from bank 2 running after reset when the OB bit nSWAP_BANK is modified.

Rgds,

Jarda

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.