Skip to main content
November 20, 2023
Solved

STM32G474RET6: Always boot from bank1 and to jump bank2

  • November 20, 2023
  • 3 replies
  • 1802 views

Hello

In STM32G474RET6 I want to have 2 banks. Bank 1 for golden (boot image) and Bank 2 for an application image.

As I want to have a robust solution I always want to boot from Bank 1 (address: 0x8000000), to check if valid firmware exist in Bank 2 (address 0x8040000) and if ok to jump to Bank 2 and to run firmware stored there.

My code based on FLASH_DualBoot example of STM32Cube_FW_G4_V1.5.0 is working ok, but it is not good enough for me as it toggle the boot between Bank 1 and Bank 2. 

Where I can't find simple example code that will simply jump to Bank 2 from Bank 1 (and still remain boot from Bank 1 after next power up)?

 

Thank you.

 

Alex

This topic has been closed for replies.
Best answer by FBL

Hello @Legacy member 

It is not possible that example code jump to Bank 2 from Bank 1 (and still remain boot from Bank 1 after next power up). This is because when BFB2 bit is set, the system memory remains aliased at @0x0000 0000 as detailed in the reference manual.

 

3 replies

Visitor II
November 20, 2023

To implement a solution where you can jump from Bank 1 to Bank 2 and persistently boot from Bank 1 on subsequent power-ups, you need to carefully manage the boot configuration and set a flag or identifier that indicates the selected bank. You can try with the  STM32 HAL library.

November 20, 2023

Why I need flag indicating selected bank? Firmware programmed in each bank are different.

If currently running firmware in Bank 1 there will be an option to jump only to Bank 2 (and back from Bank 2 to Bank 1).

What specifically to look in STM32 HAL library?

Is there any code example for a jump between banks (without toggling BFB2 bit)? 

I am not a software developer (but a hardware developer) - but still need to implement this jump in firmware.

So please elaborate any suggestions with examples.

Thank you.

Alex

FBLBest answer
Technical Moderator
November 20, 2023

Hello @Legacy member 

It is not possible that example code jump to Bank 2 from Bank 1 (and still remain boot from Bank 1 after next power up). This is because when BFB2 bit is set, the system memory remains aliased at @0x0000 0000 as detailed in the reference manual.

 

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
Tesla DeLorean
Guru
November 20, 2023

>>Is there any code example for a jump between banks (without toggling BFB2 bit)? 

It's surely just a control transfer, code and vector builds at the address you have for the second bank. Be that 0x08100000 or 0x08008000 ..

Make the linker fixup the __Vectors  or _gfnVector you write into SCB->VTOR, and use a c function pointer. None of this is magically different from any other IAP that would be viable for a single bank (or non swapping) solution.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
November 20, 2023

The other alternative if you must have things built for the same address basis and perhaps swap at some point. Say one image which has a version / sequence number and you always want to run the newest valid / signed version.

Implement something like fork(), have the exact same code in the front of both banks, a loader, determine which image is the desired one, and then just change the mapping as you're executing, flow will then take you into the image you want.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..