cancel
Showing results for 
Search instead for 
Did you mean: 

Dual Boot on the STM32G4 not quite working (boot from second bank fails)

Rafael Bachmann
Associate II

I checked out the example dual boot project from here:

https://github.com/STMicroelectronics/STM32CubeG4/tree/master/Projects/NUCLEO-G474RE/Examples/FLASH/FLASH_DualBoot

I am running this on my G474RE nucleo. What works:

* flashing bank 1 with the bank1 program, I can observe that the BFB2 bit is correctly toggled. But the bank2 program I compiled does not get executed.

* flashing bank 1 with the bank2 program, I can also observe that the BFB2 bit is correctly toggled (as it should), but bank2 is not executed correctly.

* flashing bank 1 with bank1 or bank2 programs and flashing bank 2 with the provided binary: https://github.com/STMicroelectronics/STM32CubeG4/blob/master/Projects/NUCLEO-G474RE/Examples/FLASH/FLASH_DualBoot/Binary/FLASH_DualBoot.bin also works!

So it seems my compilation of flash bank 2 program is somehow incorrect, since the provided binary for flash bank 2 works fine...? Or what is amiss here?

16 REPLIES 16
Imen.D
ST Employee

Please refer to the latest STM32CubeG4 firwmare package version 1.3.0 with fix on the DUAL BOOT example and the linker file.

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

Hi

I am kind of stuck with using BFB2 bit for switching banks in G474 MCU for OTA support.

I could see that the BFB2 bit option byte was switched successfully using my program, but the device still did not boot from the Bank 2.

I have verified that the current system bootloader version is 13.4.

BOOT0 pin was set to 0 in the hardware. 

For a hardware-specific reason, I had to disable the system bootloader configuring the option bytes to nSWBOOT0=0 and nBOOT0=1 using ST Link utility.

Later I realized that for BFB2 to work, I may have to enable the system BL. 

In order to check this manually, I flashed two binaries in Bank 1 and Bank 2.

Also configured nSWBOOT0=0 and nBOOT0=0 to enable the system BL and then BFB2=1 was set.

From now on, the device keeps giving me programming errors, for example,

"Programming error @ 0x08000BA4!"

Even reverting to the older option bytes configuration also gives the same error. This is the second device that is giving me the same issue.

Is there anything that I have to do to make the MCU programmable again? I do not know what is wrong with my configurations.

I'm not sure if this is related to your problem, but AFAIK the ST Link Utility does not fully support the option bytes of STM32G4 controllers, you should use CubeProgrammer instead. I think some of the bits are not accessible on ST-Link Utility and some have weird naming/polarity mismatches with the datasheet.

Maybe that messed something up in your option bytes configuration?

AScen.1
Associate II

Thanks for the reply. You may be right.

Is there any way to reset the option bytes to factory, say using the STM32CubeProgrammer or any other means?

João Baptista
Associate II

Dear.

I have this same problem, but with stm32l073RZ.

More explicitly, my code with a flashing led works on bank1, but it does not work on bank2. The strangest thing is that I also used the sample code for an intermittent led from stmcubel0 and it works, but with mine it only turns on the led but in low light.

I'm using stmcubeide, could this be the problem?

I used the stmcubeprogramer to change the banks.

Hello Imen,

Thank you for looking into this issue, but I would like some clarification please: My STM32G474 has bootloader version 13.0. If I keep the stack pointer below 0x20018000 (less than 96K) can I dual boot, even though I have such an early bootloader?

I appreciate any insight you can offer - thank you!

Regards,

Dave

Hello,

CORRECTION: Turns out I have bootloader 13.4 (I mistakenly thought the second byte was significant and mine is 0x00). The first byte is 0xD4, so I appear to have 13.4.

Dave