Skip to main content
Visitor II
June 5, 2024
Question

Bootloader stm32l072kzt 192kb

  • June 5, 2024
  • 2 replies
  • 3923 views

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?

    This topic has been closed for replies.

    2 replies

    Technical Moderator
    June 11, 2024

    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).

     

    WaveAuthor
    Visitor II
    June 11, 2024

    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

    Graduate II
    June 11, 2024

    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.

    WaveAuthor
    Visitor II
    June 11, 2024

    >>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

    Graduate II
    June 11, 2024

    I mean establish how slow exactly, and which clock sources it's using. This can be done by reviewing and unpacking the RCC registers. Once you know what state the system is in you can then hypothesis as to how and why.

    Check also the wait state settings for the FLASH, these too may slow down code execution.

    Out of the second bank it will have run the system boot loader first.

    WaveAuthor
    Visitor II
    June 12, 2024

    In fact, what I'm doing is just a test, so that I can understand better, and for me to see the jump, that's why I used the stm32 CubeProgrammer tool.

    I need to perform the bootloader on my sstm32l072 microcontroller automatically, without any manual intervention, and without USB, and also without using any tools.

    Does my microcontroller only have a dual bank format to carry out the bootloader?

    Is there any way I can perform the bootloader, through the firmware itself?

    Imagine a routine, so after a while of operation, a function arrives that tells the microcontroller whether or not it needs to bootloader. If necessary, I won't have a USB or any tool, nor any human around to make the bootloader, I'll just have the firmware itself. That's why it needs to be automatic. It is possible? What ways can I try this?