2021-11-15 01:02 PM
Hey!
I'm trying to get the dual boot to work on STM32L476RGTx. I'm using Keil MDK with compiler version 5. I wrote a simple blinky code that toggles LED on GPIO pin every 500 ms. Initialisation code and project were generated with CubeMX. After build I generate bin file from elf according to Keil documentation.
When I flash the bin file to 0x0800 0000 with stlink utility the code works as expected (it does the same when I flash it with Keil).
When I flash the same bin file to 0x0808 0000 also, the code still works as it still runs from bank 0. Then I set the BFB2 bit in option bytes with stlink utility. The codes breaks with LED blinking extremely fast. It seems that the mcu is in reboot loop. Confirmed that with debugger, code would run through init and pin toogle and then reset somewhere in the HAL_Delay function while waiting for next pin toggle.
If I erase the whole flash and then only flash the example to 0x0808 0000 and set the BFB2 bit in option bytes the code does not work at all.
nBOOT0 = 0 (pin tied to GND)
nBOOT1 = 1
What am I doing wrong here? Attached is the Keil project.
2021-11-15 02:45 PM
As I recall it doesn't switch the banks, you'd need a different binary, built for a different address, or some common boot code in each to be smart enough to physically swap the banks within the memory space.
Try building a binary for the upper address space, making sure you initialize SCB->VTOR properly
2021-11-16 01:07 AM
Hey! I know that L0 devices doesn't switch banks but the L476 should. Attached are relevant sections of documentation.
From STM32L4 flash presentation.
Dual bank flash organization for my device.
Boot modes for my device.
How the bootloader works.
What do you think?
2021-11-22 10:47 AM
Figured out what's wrong.
In file "system_stm32l4xx.c" I had to uncomment "#define USER_VECT_TAB_ADDRESS". After the bootloader started my code the vector table didn't get remaped. At systick interrupt the cpu jumped back to bootloader and code restarted.
Hope this will help someone else having the same problem.