Stores data on the flash memory of stm32f4xx
Dependents: DISCO-F429ZI_LCDTS_demo_richard
Fork of storage_on_flash by
SOFBlock.h File Reference
Simple storage implementation on internal MCU flash memory. More...
Go to the source code of this file.
Detailed Description
Simple storage implementation on internal MCU flash memory.
Conceptually it is quite simple. Here is typical write operation: 1) Erase sector n 2) Write data to sector n Read operation: 1) Just read physical memory address of sector n The base physical address of STM32 flash is 0x08000000.
There may be inefficiency in this flash usage scenario when size of data is too small compared with sector size. The size of sectors from #5 to #7 of STM32-F4xx Flash is 128KB. For example, if I only need to maintain 1KB data, whenever I need to update data I need to erase whole 128KB of sector. This produces two problems. One is time consumption of the erase operation. The operation of ERASE128KB takes 1~4 seconds long. The other is related to lifetime of Flash memory. More you erase and write and lifetime of flash is shorter.
To overcome such problems, here simple flash management algorithm is used for. By tracking data offset and size it can hold multiple data in a sector. Bear in mind that is impossible rewriting data on Flash. Keeping tracking data along with data itself without frequent erase operation is crucial. To do this, data itself is growing from low address. On the other hand tracking data is growing down from high address. Let's assume the size of data is 1KB and store it in sector #6 which address range is from 0x08040000 to 0x0805ffff. +-------------+----------------------------------------------------------------------+-----+ <data> <tracking data>=""> +-------------+----------------------------------------------------------------------+-----+ data grows -> <- tracking data grows Writing data will be placed at the end of data always and reading data will pick the last data. It is like simple file system that only keep a file only.
Unlike file manipulation operation, there is caution you need to check if write operation fails or need to check free size before you start to write data. It is required to format flash sector when there is no more free space.
Definition in file SOFBlock.h.
Generated on Wed Jul 13 2022 22:53:56 by 1.7.2