cancel
Showing results for 
Search instead for 
Did you mean: 

dual boot for stm32l151re not working

diegofontanabr
Associate II

i am not able to run any code on bank2 with STM32L151RE with 512kB FLASH.

program was loaded on both regions 0x0800 0000 and 0x8004 0000

0693W00000HniqRQAR.png0693W00000HniqvQAB.png0693W00000HnirFQAR.pngif nBFB2 is checked the code runs ok, if i just unched the code does not run....

what am i doing wrong?

7 REPLIES 7
moatjon
Associate III

Hey Dfont,

If nBFB2 is checked, the system boot mode is selected using the BOOT0 and BOOT1 pins on your device. What is the signal level on these pins?

Are you able to debug at all when nBFB2 is unchecked?

Kind regards,

moatjon

diegofontanabr
Associate II

BOOT0 is at GND, BOOT1 (PB2) is floating...

i am using a nucleo64 board MB1136, i replaced the original STM32L152RE with a STM32L151RE to ***** the dual boot, as i have verified the 152 does not have dual boot mode, is that right? or both of them work in dual boot mode?

but as i can see, if nBFB2 = 0 (unchecked), i.e. dual boot mode is active, the pins BOOT1 and BOOT0 does not matter, on booth cases the boot will be from "system memory", jumping to bank2 or bank1

0693W00000Hnqa2QAB.png 

diegofontanabr
Associate II

i am not able to debug when nBFB2 is unchecked

it seems to be locked in some region of the system memory

0693W00000HnrY8QAJ.png

diegofontanabr
Associate II

if i debug step-by-step (instruction by instruction) i can go very far away, but if i use the "step over" the process halt to that address

PKeiles
Associate

I have had similar issues using the STM32L4R5 on our custom board and working with the support team to get answers. Apparently there is some issue where this "PEMPTY" bit in the status register can become set while trying to switch banks and it can cause issues when trying to update the option bytes. However I can't seem to get the bit cleared via firmware for some reason and the processor ends up in a state with interrupts not working thus preventing the Systick timer usage and many routines in their HAL layer from working correctly.

If you as me, the usage of these option bytes to control the dual switching has some definite issues in how it works. Still waiting for more answers on this problem for the support guys.

diegofontanabr
Associate II

it is my first time using dual boot, i am new to STM32 mcu too.

i have seen that some MCU need to enable dual boot mode, in STM32L151RE it is naturaly enabled, it was born with dual bank?

in the aplication note AN2606 it says "If Value @0x08040000 is within int. SRAM address" > "Jump to user code in Bank2", the value 0x20014000 is a valid one?

when the system memory jumps to bank2, wich is in address 0x08040000, the flash address is automatic "remaped" to virtualy be in 0x8000 0000 wich is base address where originaly the code was compiled?

do i have to compile a specific binary for each bank?

for bank2 i have to adjust the base address of the flash? or the vector table?

i have found some information for dual boot using STM32G474RE, but i have not found info/examples for STM32L151 wich seems to be very different in this aspect....

when running a code in bank1, i will write my new firmware to bank2 at address 0x0804 0000?

how do i force to use this firmware in the next reset?

if the upload to bank2 got some error, how do i avoid to jump to bank2 in next reset?

now if i run in bank2, can i keep writing the new firmware to address 0x0804 0000? it is automatic remaped? or do i need to detect i am running in bank2 and write to address 0x0800 0000?

how to block a call to bank2 after a succeful update of the firmware to bank1?

in AN2606, page 307 Figure 73. Bootloader selection for STM32L1xxxE devices, where it says "BFB2 = 0", its the same as "nBFB2 = checked" (it has a "n" in front) in the option bytes of the STM32 ST-LINK Utility?

i will always let the nBFB2 unchecked or checked?

i will change the value of the nBFB2 to choose bank1 or bank2 ? or i need to let it at always the same state and invalidate the first word at bank1 (0x0800 0000) or bank2 (0x0804 0000) to select wich firmware to run?

i am the only one using dual boot in this MCU? i dont belive thats so hard.... i have years of experience with MCU and have never seen such hard thing to get to work....

PKeiles
Associate

Wow, lots of questions there. I have had many years of experience as well and this Dual boot design is not very good. From what I have found so far, you set the BFB2 bit to force the internal ST bootloader to use Bank2, but there has to be a valid vector at the first address, if there is not the PEMPTY bit gets set which is causing all sorts of issues for me. As for compilation, no the same exact image can run in both banks, the ST bootloader should branch to the correct bank based on the BFB2 bit.

Note you can only program memory in the opposite bank that you are executing code from, unless you want to execute the programming code from RAM. I have already go this part working, it's not too hard. An easy flag to check where you in in code is:

  if (READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_FB_MODE) == 0) ==> Currently executing code from Bank1.

This way you know where you are and can program the correct opposite bank. I am still waiting to hear back from support regarding the clearing of the PEMPTY bit and how to exit this strange state where it's running in the wrong bank and always resetting.