2008-06-15 09:15 PM
Flash Memory Page Erase
2011-05-17 03:37 AM
All:
There is an error in the Flash Programming Manual PM0042. If this has been pointed out before on this forum, I could not find it. The Page Erase procedure, p. 15 and the accompanying chart (Figure 2 on p.16) clearly state that to erase a page in the flash memory one sets the FAR, then sets the FLASH_CR_PER bit to 1, then sets FLASH_CR_STRT bit to 1. When I did this, Flash Page 0 got erased regardless of what value I wrote into FAR. Since in my case page 0 contained the program itself, this resulted in a crash. It was very difficult to troubleshoot. I noticed that the example program in ST's firwmare library performed the operations in a different order: First set FLASH_CR_PER, then set FAR, then FLASH_CR_STRT. This works as intended. The STM32 acts as if setting the FLASH_CR_PER bit clears the FAR, but this behavior is not documented either in the procedure I mentioned above, the docs for the FLASH_CR_PER bit, or the docs for the FAR. Since the FAR is read-only, its contents can never be checked, so it's hard to know exactly what is going on here. But it's clear that the manual and the example program are different and the program works. So the manual is wrong and should be corrected. Paul Cornelius2011-05-17 03:37 AM
Dear Paul,
In the Flash Manual version 3( May 2008) it is stated in page 14/30 : Page Erase A page of the Flash memory can be erased using the Page Erase feature of the FPEC. To erase a page, the procedure below should be followed: â—� Check that no Flash memory operation is ongoing by checking the BSY bit in the FLASH_CR register â—� Set the PER bit in the FLASH_CR register â—� Program the FLASH_AR register to select a page to erase â—� Set the STRT bit in the FLASH_CR register â—� Wait for the BSY bit to be reset â—� Read the erased page and verify Please refer to : Cheers, STOne-32.