cancel
Showing results for 
Search instead for 
Did you mean: 

Custom size erase of Internal Flash or Override of existing data for STM32U585 series Internal flash

Nitin
Associate III

I am working with an STM32U585 microcontroller, and I need to perform read, write, and erase operations on the internal flash memory (Bank 1) with TrustZone security enabled. The page size is 8 KB, and I am encountering an issue when trying to write data.

Problem Overview:

  • When attempting to write data to flash without erasing, the write operation fails.
  • If I erase the entire 8 KB page and then write, the operation is successful.
  • However, my requirement is to write smaller amounts of data (e.g. 4 bytes) without erasing the remaining (8 KB - 4 bytes) bytes of the page. I only need to erase the specific location that will be written to, not the whole page, to avoid erasing other data within the same page.

Current Findings:

  • The flash memory only allows erasing entire pages, so when I need to erase a small portion, it results in the entire 8 KB page being erased, which is not ideal for my use case.

Questions:

  1. Is there any way to perform a partial erase in STM32U585 internal flash, specifically for small data sizes like 32 bytes or 4 bytes?
  2. Can I limit the erase operation to a smaller portion of the page, while preserving the other data within that same page?
  3. Are there specific functions or approaches that allow for targeted erasing of a section within a larger flash page without erasing the entire page?
  4. and last but not least, Is it possible to override those 4 bytes of data by new data so that we can achieve the requirement without erasing previously existing data.

I would appreciate any guidance, tips, or best practices that you can share to achieve partial page erasure in the STM32U575 microcontroller.

Thank you for your assistance!

@Jocelyn RICARD 

1 ACCEPTED SOLUTION

Accepted Solutions
olivierxpmetal
Associate II

Hi,

To the best of my knowledge, it's not possible to write only a few bytes to Flash memory without first erasing the entire page. This is a fundamental characteristic of Flash memory.

To modify a portion of the page, you must:

  1.  Read the entire page into a RAM buffer.
  2. Modify the desired bytes.
  3. Erase the entire page.
  4. Write the RAM buffer back to Flash.

For page rewriting, you are not required to write the entire page. The minimum write size is 4 32-bit words.

 

View solution in original post

3 REPLIES 3
olivierxpmetal
Associate II

Hi,

To the best of my knowledge, it's not possible to write only a few bytes to Flash memory without first erasing the entire page. This is a fundamental characteristic of Flash memory.

To modify a portion of the page, you must:

  1.  Read the entire page into a RAM buffer.
  2. Modify the desired bytes.
  3. Erase the entire page.
  4. Write the RAM buffer back to Flash.

For page rewriting, you are not required to write the entire page. The minimum write size is 4 32-bit words.

 

Jocelyn RICARD
ST Employee

Hi @Nitin ,

yes fully agree with @olivierxpmetal .

This is the principle of FLASH memory implementation.

If you need to read write without bothering with this sector constraint you have also following solutions 

1) Usage of external EEPROM. Such device don't have sector erase constraint.

2) Usage of EEPROM emulator: Principle is to use emulate the behavior of EEPROM using few flash sectors. You can have a look at X-CUBE-EEPROM - EEPROM emulation expansion software for STM32Cube - STMicroelectronics

Best regards

Jocelyn

Nitin
Associate III

Thanks for the confirmation Olivierxpmetal and Jocelyn.