AnsweredAssumed Answered

STM32F401RE SPI-Bootloader Erase - does not work

Question asked by heil.janis on Jul 28, 2016
Latest reply on Aug 9, 2016 by Clive One

I have a problem with the erase command for the SPI-bootloader.

1) The documentation says 0x44 in the text and 0x43 in the figures (AN4286 DocID024458 Rev 2)

2) The documentation is inconsistent with the use of the terms "page" and "sector". This has huge impact on my question below. For details also see:

3) The discription in chapter 2.8 does not fit the Figures 18 and 19: Is a checksum required after transmitting the "number of pages"? Text says no, figure 18 and 19 say yes.

Now to my actual question:
I am currently trying to implement the SPI-bootloader command "erase" on a STM32F401RE MCU with 512kb flash memory. It works when I perform a mass-erase (length = 0xFFFF), but not when I try to erase single sectors. Write protection is off.
The bootloader sends only ACKs and seems to work - but the sectors are not erased (as I said: mass erase works, but I need single sector erase).

Some more background why the documentation needs correction:
The confusing part is that - according to AN4286 -  the erase-comand takes 16bit page-numbers. Pages are not mentioned anywhere else on the STM32F401 documentation. So I figure that sectors are actually meant. Is that correct?
If so: Why does the bootloader take 16bit wide sector-IDs when there are only 8 different sectors? (Larger MCUs have only marginally more sectors, so that cannot be the reason.)

Is my pseudo-code correct for erasing sector 0 (at flash address 0x08000000):
SpiSend(0xA5,0x44,0xBB);  // documentation says 0x43,0xBC in Figure 18??
SpiSend(0x00, 0x00); // N = 1 sectors shall be erased, bootloader wants N-1 = 0
SpiSend(0x00); // checksum, required?? Figure 18+19 say yes, text says no
SpiSend(0x00,0x00); // sector 0
SpiSend(0x00); // checksum

--> I get an ACK, but the sectors are not erased.
NOTE: I controle the byte at 0x08000000 because even if pages were meant instead of sectors, then I would erase page 0 which would most also start at 0x08000000.

Have a nice evening and thanks for the help :)
Janis Heil