STM32G0B1RE - How to switch to bank2 in dualbank mode?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-08 08:50 PM
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();
Solved! Go to Solution.
- Labels:
-
Flash
-
STM32G0 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-20 02:27 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-19 11:31 AM
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
Thanks
Imen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-20 02:27 AM
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.