cancel
Showing results for 
Search instead for 
Did you mean: 

Bootloader stm32l072kzt 192kb

Wave
Associate II

I want to perform the bootloader on my stm32l072kzt 192kb microcontroller without the need to use serial interfaces, my idea is to download a new firmware from the cloud and then update the computer with this new firmware. However, it seems to me that he doesn't jump from bank 1 to bank 2, can you confirm and explain this to me? Furthermore, what are the ways to bootloader the stm32l072kzt 192kb microcontroller?

21 REPLIES 21
Imen.D
ST Employee

Hello @Wave,

STM32L072 has dual bank boot mechanism, and it is not possible to jump to Bootloader on any device having dual bank boot mechanism or flash empty check mechanism. Because the Bootloader will consider this attempt as hw request to execute dual boot or empty check and will simply jump to user flash.

If you want to bypass this mechanism, there are two options:
- Use option Bytes / Boot pins to configure boot from Bootloader then reset
- Jump to Bootloader but ensure that the first word in the user flash (@0x0800 0000) is erased (ie. write zeros to it).

 

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

My mciro stm32l072KZ,

I have a firmware running in the flash, on the bank being 0x0800000, If I put BOOT0 = 0, NBOOT1 = 1, BFB2= 1 and restart the computer and put the same firmware on bank2 it doesn't initialize and gets stuck. What must have no bank2 code to initialize correctly? I changed the linker script to:

/* Definition of memories */
MEMORY
{
RAM (xrw): SOURCE = 0x20000000, LENGTH = 20K
FLASH (rx): SOURCE = 0x8018000, LENGTH = 192K
}


And it still stuck. I tried to do it through CubeProgrammer with these steps.

1 - I erased all the memory and programmed a firmware for bank1 at 0x080000 with bfb2=0, nboot1=1 and boot0=0.

2 - I left it running for a while, and it worked perfectly.

3 - I took exactly the same firwmare and changed its memory in the linker script, and then recompiled it.

4 - I erased all the flash again, marked bfb2 = 1, nboot1 = 1, bfb2 = 1, programmed the new firmware, and restarted the computer and nothing happened.

In fact, it came out like this:

14:35:52 : UR connection mode is defined with the HWrst reset mode 14:35:52 : ST-LINK SN : 35FF6D06304E4B3043242443
14:35:52 : ST-LINK FW : V2J37S7
14:35:52 : Board : -- 14:35:52 : Voltage : 3.30V
14:35:52: SWD freq: 4000 KHz
14:35:52 : Connect mode: Normal
14:35:52 : Reset mode : Software reset
14:35:52 : Device ID : 0x447
14:35:52 : Revision ID : Rev Z
14:35:52 : Debug in Low Power mode is not supported for this device. 14:35:53 : UPLOADING OPTION BYTES DATA ...
14:35:53 : Bank : 0x00
14:35:53 : Address : 0x4002201c
14:35:53 : Size : 104 Bytes
14:35:53 : Bank : 0x01
14:35:53 : Address : 0x1ff80000
14:35:53 : Size : 20 Bytes
14:35:53: UPLOADING...
14:35:53 : Size : 1024 Bytes
14:35:53 : Address : 0x8018000
14:35:53 : Read progress:
14:35:53 : Data read successfully
14:35:53 : Time elapsed during the read operation is: 00:00:00.017 14:36:03 : MASS ERASE ...
14:36:09 : Mass erase successfully achieved
14:36:10: UPLOADING...
14:36:10 : Size : 1024 Bytes
14:36:10 : Address : 0x8018000
14:36:10 : Read progress:
14:36:10 : Data read successfully
14:36:10 : Time elapsed during the read operation is: 00:00:00.042 14:36:19 : Memory Programming ...
14:36:19 : Opening and parsing file: smart_light_teste.bin
14:36:19 : File: smart_light_teste.bin
14:36:19 : Size : 59.38 KB
14:36:19 : Address : 0x08018000
14:36:19 : Erasing memory corresponding to segment 0:
14:36:19 : Erasing internal memory sectors [768 1243]
14:36:20 : Download in Progress:
14:36:25 : File download complete
14:36:25 : Time elapsed during download operation: 00:00:06.118 14:36:25 : Verifying ...
14:36:25 : Read progress:
14:36:25 : Download verified successfully
14:36:26 : RUNNING Program...
14:36:26 : Address: : 0x08018000 1
4:36:26 : Warning: failed to run application!
14:36:26 : Warning: The core is kept under Reset!
14:36:26 : Error: Start operation failed

Doesn't it flip the banks? Physically you need to write to one address, but the code will expect to be at the base address when it runs, and that won't help if your vector table is full of absolute addresses in the wrong memory space.

What you might want to consider is a smaller loader that fork()s to the bank you want.

Or honestly that you manage your own floor-plan within the device, and your own FOTA methods.

The ROM loader almost certainly isn't going to have all the flexibility you might want/need.

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

My vector table is just a base address, nothing special. This same bank1 firmware was running with everything at the base address, without any changes to the linker script or the vector table. However, if I do this process that I mentioned with the firmware modified in the table and in the linker script, or with the firmware with everything on the base without modifications, it's the same, and it doesn't change the firmware (so it doesn't change the banks). What do you think it could be?

Unless I'm mistaken, you'd have to erase the firmware in the first bank for it to look in the second bank, at which point it would flip/remap the banks so the second one appears at 0x08000000 and executes that with the expectation that the vectors and firmware are built to exists at 0x08000000, not 0x08018000

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

I did this process, erased all flash memory, both banks, recorded firmware at address 0x08018000, with the firmware addresses and vectors pointed to base 0x0800000, marked bfb2=1, nboot1=1, boot0=0. I restarted the microcontroller and it even started up, but it ran very slowly. Why would it work slower?

I did it using STM32 CUBEPROGRAMMER

>>Why would it work slower?

Runs off the 4 MHz MSI when it starts, and doesn't transition to the 32 MHz via the PLL, for whatever reason?

Would suggest printing out the MCU and BUS speed, so it's apparent what's happening.

If it's not dumping into Error_Handler() already, perhaps instrument and check the startup process, and the robustness of SystemClock_Config() to starting with unexpected clock settings out of reset.

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

>>Runs off the 4 MHz MSI when it starts, and doesn't transition to the 32 MHz via the PLL, for whatever reason?

I don't understand, after the process I reset, removing power and activating again, but with the initialization in bank2 of course, and then it works without falling into error_handler() but it is very slow, sorry, but I didn't understand what you meant

Could it be because my bootloader is on LPUART? I noticed that it says "Debug in Lower Power Mode", after I mark boot0=0, bfb2=1, nboot1=1 I reset the computer by removing the power and returning again, and when I return I save the firmware at 0x0801800 and execute it. Then make the jump and start the code, but very slowly.