cancel
Showing results for 
Search instead for 
Did you mean: 

Dual bank booting problem

KKlyn.1
Associate II

Hello!

I try to use dual bank option on the stm32l476 (256kB) for implementing a custom bootloader. I want just read new program (bin) by custom protocol and write it to another bank. After that I want to switch the banks, reset mcu and start the new program (from another bank).

Sounds easy!

My actions:

I built the program for bank1, load it to the address 0x08000000.

Then I loaded the same program to the bank 2 by address 0x08020000. (either with the st-link utility or just by writing to the flash directly from my program, tried both of variants).

After that I set option byte bfb2 from 0 to 1 (also either with st-link or just from program). But my mcu does not work at all.

I`ve compared the program in both banks and original .bin file with the help of the st-link utility and found that there is no difference between it (no corruption during program).

I`ve even tried to build program for bank 2 (with offset), but it also did not help.

I`ve noted that when I change the bfb2 bit, the value in the 0x4 address (entry point) also changes to strange address 0x1FFF6145 instead of 0x08005DE9 (my real entry point). I understand that mcu reads this address as an entry point and traps. But why does this address change to something strange one?

From the bank1 (bfb2=0) program works well.

Please, can anybody say what I do wrong?

Configurations: Boot0 connected to the ground. DaulBank=1, nBOOT1=1, FB_MODE=0

Best regards, Klynkin Kirill.

4 REPLIES 4
Pavel A.
Evangelist III

> strange address 0x1FFF6145

This looks like the internal ROM bootloader

KKlyn.1
Associate II

Yes, it seem to be true.

But it`s not obviously why? What I did wrong?

KKlyn.1
Associate II

UPD:

The problem was with the SCB->VTOR register.

It`s important to write the actual address of your interrupt table. (default value is 0)

If you don`t fill the SCB->VTOR with the corresponding value and leave it by default, you will receive the following troubles:

When you boot from the bank 1 (bfb2 bit is set to 0) the flash memory is mapped to the 0x0 address. And the vector table which is stored in your flash (0x08000000) is mapped to the 0x0. That`s why it works fine for booting form bank1

But when you boot from bank 2 (bfb 2 is set to 1), the system memory is mapped to the 0x0 address. And mcu can`t find the right reset vector table.

To avoid it, write the right offset for the vector table to SCB->VTOR register (not from 0x0 address where different memory might be mapped, but from the real FLASH)

For me it was just one code line SCB->VTOR = 0x08000000

I also encountered the same problem but assume we don't have any firmware loaded into bank1. then what address should we use for the VTOR reg? I want to run my firmware only from bank2 and i have nothing loaded in bank1 and when i set the VTOR to point to bank2 start (0x08018000 for STM32L073RZ) it doesn't work.