Tiny storage(file) system on MCU internal flash memory for Nucleo F4xx. The purpose of SOFBlock class is to provide a way to write data on flash memory in the same way of file handling class in the file system.

Dependents:   storage_on_flash_demo mbed_controller_demo mbed-os-example-blinky-2

Embed: (wiki syntax)

« Back to documentation index

SOFBlock.h File Reference

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.

Author:
hillkim7@gmail.com The SOF in SOFBlock is abbreviation of "Storage On Flash". The purpose of SOFBlock class is to provide a way to write data on flash memory in the same way of file handling class in the file system. It manages a chunk of data on the Flash memory efficiently by minimizing flash erase operation as little as possible. Note: Currently it only supports STM32F4xx series platforms.
  • NUCLEO-F401RE, NUCLEO-F411RE, Seeed Arch Max The STM32 F4xx series from ST have plenty of internal Flash memory inside MCU core. For example STM32 401RE has 512Kbyts Flash. Typical size of firmware file is less than 256KB, so remaining area is free to use. The simplest way of flash utilization as data storage is to use a chunk of Flash area as an unit of storage. A block of flash is called sector in STM32F4xx domain. It requires to erase a sector before update bits in flash.

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.