Skip to main content
tst
Associate
May 8, 2019
Solved

STM32F446: Flash memory

  • May 8, 2019
  • 11 replies
  • 4146 views

I want write only some bytes but before that I have to erase a full sector.

If I don´t want to loss data from that sector I will need save them.

If sector size is 128Kb, how can I save all data? 

Thank you !

This topic has been closed for replies.
Best answer by Pavel A.

The first sector at 0x08000000 must be used by code (or bootloader) because the execution starts there.

All other sectors are up to you. A common approach is to allocate two sectors for data: one current and another backup.

Copy the data from one sector to another before erasing. Copying does not take much RAM, it can be done by 2 or 4 bytes.

-- pa

11 replies

John Craven
Senior
May 8, 2019

Have you looked at the EEPROM emulation packages that STM provides for most series?

tst
tstAuthor
Associate
May 10, 2019

I am trying to run the example but sometimes it works and others not...

Pavel A.
May 8, 2019

It's a problem. 446 has sectors of different size, and there's too little RAM to back up 128K. Try to find a smaller sector: 16 or 32K.

-- pa

tst
tstAuthor
Associate
May 9, 2019

The sector sizes of F446 are: 16K, 64K and 128K... I have also tried to save 16K data but I couldn't, just until 10K...

Couldn't I back up data from this flash memory?

Tesla DeLorean
Guru
May 9, 2019

You'll need to use smaller sectors for configuration data, by leaving holes in the code space. Or use a sector, or two, that you can commit to the data storage task, and ping-pong between them.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
tst
tstAuthor
Associate
May 10, 2019

But that MCU has these size sectors...so I will need manage data of these sizes...(16K,64K,128K...)...

turboscrew
Senior III
May 28, 2019

Sectors 0-3 are 16 kB. Leave sector 0 for boot code and use sectors 1 and 2 for storing data.

Note that you need to fix the linker script too, if you leave "data holes" in the middle of code.

You can define 4 flash-regions: boot, data1, data2 and code and allocate the code in boot and code.

Then you need to decide what goes into boot and what goes into code. Maybe initializations into boot and application itself into code.