cancel
Showing results for 
Search instead for 
Did you mean: 

How can I detect the active flash bank on stm32g4? BFB2 bit is not conclusive

Rafael Bachmann
Associate II

Hi,

I am developing an application with stm32g4 using the dual bank feature for firmware upgrades. To check if an upgrade was successful, I need to check the currently active bank.

I can read the option bytes and get the BFB2 bit. But: if the firmware on bank X was not correct and was rejected by the system bootloader, the system bootloader does not boot bank X, instead it boots bank Y. But it does not toggle the BFB2 bit, leading to a state where BFB2 indicates bank X but actually bank Y runs.

Is there a way to query the actually active bank?

3 REPLIES 3

https://www.st.com/resource/en/reference_manual/dm00355726-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf

Check SYSCFG_MEMRMP / MEM_MODE

Mark the images when you write them into different banks

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Imen.D
ST Employee

Please follow this discussion

https://community.st.com/s/question/0D50X0000CEqc1SSQR/dual-boot-on-the-stm32g4-not-quite-working-boot-from-second-bank-fails?t=1591957302322

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

Did you managed to query the active bank? I followed the related discussion, and it solves issues related to the bank switching on boot, which is very useful, but nothing about how to check in wich bank are you running after boot. My code is going to erase a bank and flash a new firmware, then switchover, but I need to know what bank to erase in the first place. Isn't is this the expected behaviour for dual bank?