Skip to main content
Visitor II
May 7, 2024
Question

Cannot read correct data from STM32 internal FLASH

  • May 7, 2024
  • 2 replies
  • 1133 views

Hi,

I am using STM32u585 MCU.

It has 2 FLASH banks of 1MB each one.

In initially I read correct data (64 bytes) from page 0 of FLASH bank 2, at address 0x0810.0000

After that I erase the FLASH page.

In CubeIDE Memory Browser window I can see that the page is erased.

When I try to read the same address from FLASH I do not read 0xFF bytes (as expected) but I read the previous bytes before page erase.

When I read the contents of another FLASH page (bank 2 page 1 - the next page) it reads correct data and if after that I read the contents of page 0 I read the correct page contents (0xFF) bytes.

The same happens if I read bytes into the page 0, when I try to read the page I receive the previous bytes.

This happens to every FLASH page.

The MCU behaves like there is a FLASH "cache" memory that holds the last page contents and if I want to read the new data bytes I have to reset the "cache" by reading another page.

Is there an explanation for this? How can I read the page I have just programmed without another FLASH read?

    This topic has been closed for replies.

    2 replies

    Technical Moderator
    May 7, 2024

    Hello,

    Did you try reading the Flash after erasing the page without using the debugger? 

    Stelios67Author
    Visitor II
    May 8, 2024

    Hi, 

    yes, we have tried that. We have tried to print the bytes we read.

    The problem is solved if we disable the ICACH_CR_EN bit before we read the flash bytes and re-enable it after the read.
    Or if we disable it before the flash erase or programming and re-enable it after.