Skip to main content
Explorer II
December 21, 2023
Solved

STM32L1 system bootloader erase

  • December 21, 2023
  • 2 replies
  • 3215 views

Hi everyone,

I am using an STM32h7 to program an STM32L151 using the system bootloader through usart.

When I ask for the supported commands, I get that the erase command is between them but, surprisingly, when I try to use it I get a nack.
Then I read that some MCUs do not support the erase command and so my first question is: does the STM32L151 support the erase (or extended erase) command?

Then I tried to erase the flash enabling and then disabling the RDP level 1, that is working but, after this operation, I find also the option bytes changed respect to the default (I read {0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000} instead of {0xFF5500AA, 0xff0700F8, 0xffff0000, 0xffff0000, 0xffff0000} at address 0x1FF80000).

So at the moment my firmware update process is working but, instead of sending a single erase command I have to:
- set RDP level 1

- restart the uP

- set RDP level 0

- restart the uP

- re-write default option bytes

- restart the uP

My second question is: am I doing something wrong or is expected to follow these steps the perform a flash erase?

Thank you,

regards

Arianna

    This topic has been closed for replies.
    Best answer by AGhez

    I have the reply I was looking for:

    the extended erase command is supported, but only for the single page erase, i.e. it is not possible to perform the 'special erase' described in the application note AN3155:

    AGhez_1-1704811984315.png

    Here there are the byte sequences:

    1.  handshake and get info:
      tx: 7f
      rx: 79
      tx: 00 ff
      rx: 79 0b 31 00 01 02 11 21 31 44 63 73 82 92 79
    2. global mass erase
      tx: 44 bb
      rx: 79
      tx: ff ff 00
      rx: 1f
    3. bank 1 mass erase
      tx: 44 bb
      rx: 79
      tx: ff fe 01
      rx: 1f
    4. single page erase
      tx: 44 bb
      rx: 79
      tx: 00 00 00 00 00
      rx: 79

    2 replies

    Super User
    December 21, 2023

    > is expected to follow these steps the perform a flash erase?

    No, there's no reason to set RDP=1 then to 0 to do a flash erase.

     

    The bootloader versions are given in AN2606 for your chip. "STM32L151" is not specific enough to tell.

    The GET command can be used to determine supported commands.

    Note that ERASE and EXTENDED ERASE are mutually exclusive. Your bootloader will support one of them. Probably EXTENDED ERASE is the only one supported.

     

    AGhezAuthor
    Explorer II
    December 21, 2023

    Hi, thank you for your reply.
    I am using an STM32L151RET6.

    With the GET command I get that the erase command is supported, but when I try to use it a get immediately a nack.

    I tried the RDP workaround following this thread: Bootloader UART: NACK to mass erase in extended er... - STMicroelectronics Community

    If you have any other hint, it would be appreciated.

    Regards

    Super User
    December 21, 2023

    The link you have is pretty conclusive, it just isn't supported here, bizarrely. Bummer.

    > I checked and this device (as well as for example STM32L1 series) do not implement the mass erase in the bootloader. The BL code space was simply too small on this device to fit the mass erase. Sorry.

     

    Should be able to do page-by-page erase though.

    Graduate II
    December 21, 2023

    >>With the GET command I get that the erase command is supported, but when I try to use it a get immediately a nack.

    Ok, but what would help everyone here would be the exact byte sequences, and responses you observe when interacting with the system boot loader.

    The boot loader is fussy about syntax, and has a smaller subset of commands when RDP is enabled.

    Erase will be further complicated by write protection settings, explicit, and inferred.

    My approach in these situations would be to debug and disassemble the loader to understand it's specific objection, and how well that relates to the AN3155 docs for the protocol.

    AGhezAuthorAnswer
    Explorer II
    January 9, 2024

    I have the reply I was looking for:

    the extended erase command is supported, but only for the single page erase, i.e. it is not possible to perform the 'special erase' described in the application note AN3155:

    AGhez_1-1704811984315.png

    Here there are the byte sequences:

    1.  handshake and get info:
      tx: 7f
      rx: 79
      tx: 00 ff
      rx: 79 0b 31 00 01 02 11 21 31 44 63 73 82 92 79
    2. global mass erase
      tx: 44 bb
      rx: 79
      tx: ff ff 00
      rx: 1f
    3. bank 1 mass erase
      tx: 44 bb
      rx: 79
      tx: ff fe 01
      rx: 1f
    4. single page erase
      tx: 44 bb
      rx: 79
      tx: 00 00 00 00 00
      rx: 79