cancel
Showing results for 
Search instead for 
Did you mean: 

Boot from Bank 1 does not work on STM32L476RGTx device with Keil MDK

GPavl.1
Associate II

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.

0693W00000GXf4dQAD.png 

3 REPLIES 3

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
GPavl.1
Associate II

Hey! I know that L0 devices doesn't switch banks but the L476 should. Attached are relevant sections of documentation.

From STM32L4 flash presentation.

0693W00000GXhhcQAD.png 

Dual bank flash organization for my device.

0693W00000GXhcSQAT.png 

Boot modes for my device.

0693W00000GXha2QAD.png 

How the bootloader works.

0693W00000GXhZ4QAL.png 

 What do you think?

GPavl.1
Associate II

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.