2025-08-01 9:22 AM
Hi,
I encountered a behavior contrary to Reference Manual while erasing FLASH page on STM32G473xB (128 KiB of FLASH memory).
The scenario is that I use several pages at the end of FLASH for classic eeprom emulation, so there are flips between two halves for wear leveling and we need to erase some page(s) before we re-use them.
I made sure DBANK=1 and all the protections are disabled (all areas start>end). Anyway if DBANK was 0, the page numbering would be the same, we only wouldn't use BKER bit in FLASH_CR and only the page size would be different.
Here is related table from RM:
What I observed... No problem with writes to uninitialized FLASH pages. I tried to erase the very last four pages (so in the 2nd bank) using BKER=1 and page numbers 28..31, this is described in RM as a proper way to do it, but it never worked. When I was stepping the code (the code is pretty simple and straight-forward) in the debugger, there was absolutely no problem indicated in FLASH_SR, the operation completed successfully, but the expected pages weren't in fact erased, and consequent writes failed as one would expect.
When I tried BKER=0 and page numbers 60..63, it started to work as a charm. The only change I made was in BKER and PNB bits values in FLASH_CR, nothing more. Successfully made a practical test that this way I'm really able to erase a single 2KiB page in the 2nd bank (eg. erasing only page 60 = Page 28 in Bank 2) preserving data in neighbor pages.
What do you think, should this be reported as a RM documentation issue, or I overlooked something somewhere?