Tip : After EasyFlash V4.1, the FlashDB open source project newly designed and developed based on EasyFlash has been officially launched. It has newly integrated functions such as timing database, multi-partition management, and multiple database instances, which has also improved the overall performance to a certain extent. Welcome to follow: https://github.com/armink/FlashDB. At the same time, the existing EasyFlash will continue to be maintained.
EasyFlash is an open source lightweight embedded Flash memory library, which makes it easier for developers to implement common application development based on Flash memory. It is very suitable for smart home, wearable, industrial control, medical care, Internet of Things and other products that require power-off storage functions. It has extremely low resource usage and supports various MCU on-chip memory. This library mainly includes three practical functions :
EasyFlash can not only realize the power-down storage function of information such as setting parameters or running logs of products, but also encapsulate simple methods of adding, deleting, modifying and querying , reducing the difficulty of developers in processing product parameters and ensuring better scalability of the product in later upgrades. Make Flash a small key-value storage database that turns Flash into a NoSQL (non-relational database) model.
This library encapsulates the commonly used interface of IAP (In-Application Programming) function, supports CRC32 verification, and supports Bootloader and Application upgrades.
It is ideal for small products without file systems, making it easier for developers to quickly locate and find the causes of system crashes or crashes. At the same time, it is used with EasyLogger (my open source ultra-lightweight, high-performance C log library, which provides a seamless interface with EasyFlash), and easily implements the Flash storage function of C logs.
Currently, there are two main modes of ENV function, one is the NG mode brought to V4.0, and the other is the legacy mode that continues V3.0
The corresponding source code file is:
ef_env.c
Since the Spring Festival in 2019, EasyFlash has finally released V4.0 version after more than 4 years of iteration and combined with the needs and suggestions of many developers. The ENV function in this version is named NG (Next Generation) mode. This is a completely refactored new version with the following new features:
V4.0 design and internal principles, V4.0 migration guide and more, please continue to read the following documentation section
Note : Some Flashes cannot be written in reverse order, such as STM32L4 on-chip Flash, so NG mode cannot be used. In this case, it is recommended to use the legacy mode of V3.0.
The corresponding source code files are:
ef_env_legacy.candef_env_legacy_wl.c
legacy mode also has wear balance and power-down protection functions. Compared with V 4.0 NG mode, using legacy mode requires additional RAM space to temporarily cache each ENV, and finally call the save interface, erase the sectors uniformly and then store them on Flash.
| V4.0 NG mode | V3.0 legacy mode | |
|---|---|---|
| RAM resource usage | Low | high |
| Support Flash Comprehensive | Some Flash is restricted: For example, STM32L4 in-chip | More comprehensive |
| Is GC garbage collection required? | GC is required, which causes the write speed to slow down when GC is triggered | unnecessary |
| value type limit | Unlimited | It supports better string types |
| Power down protection | support | support |
| Wear balance | support | support |
| Incremental upgrade | support | support |
最低要求: ROM: 6K bytes RAM: 0.1K bytes
Currently, the hardware platforms have been transplanted include stm32f10x and stm32f4xx series on-chip Flash, and off-chip SPI Flash (based on SFUD), which are also the platforms used by the author's products. The porting of other platforms is not difficult. At the beginning of the project design, adaptability issues for all platforms were considered (except 64-bit), so all porting interfaces were reserved. To port, you only need to modify a file easyflashportef_port.c to realize the functions of erasing, writing, reading and printing.
Welcome to fork and pull request (Github|OSChina|Coding). If you think this open source project is great, you can click Star in the upper right corner of the project homepage and recommend it to more friends in need.
The following figure is a common interface for calling environment variables through the console (terminal). It demonstrates the following process, which all support direct calls by the application layer.
temp and assign a value of 123 ;456 and save and restart;
The following figure demonstrates the process of upgrading IAP software through the console. It uses the IAP function interface that comes with the library, and the demonstration uses the serial port + Ymodem protocol. You can also realize remote network updates through CAN, 485, Ethernet and other buses.

The process below is to output the log through the console and store the output log in Flash. Restart and read the last saved log, and finally clear the Flash log.

docszhapi.mddocszhport.mddocszhv4_migrate.mddocszhdesign.mdBe sure to use it after reading the document .

If EasyFlash solves your problem, you might as well scan the QR code above to invite me to have a cup of coffee ~
Use the MIT open source protocol. Please read the contents of the LICENSE file in the project for details.
EasyFlash is an open source lightweight embedded flash memory library. It provides convenient application interface for MCU (Micro Control Unit). The developers can achieve more efficient and common application development based on Flash memory. The library currently provides three useful features :
EasyFlash can store setting parameters or running logs and other information which you want to keep after power down. It contains add, delete, modify and query methods. It helps developer to process the product parameters, and make sure the product has better scalability after upgrade. Turns the Flash into a small NoSQL (non-relational databases) model and Key-Value stores database.
The library encapsulates the IAP (In-Application Programming) feature common interface. Support CRC32 checksum. While supporting the bootloader and application upgrade.
It's very suitable for small without a file system products. The developer can easily to locate and query problem when system crashes or freezes. You can use EasyLogger( A super-lightweight, high-performance C log library which open source by me. It provides a seamless interface with EasyFlash) at the same time. So, it's so easy to store the logs to flash.
Minimum : ROM: 6K bytes RAM: 0.2K bytes
Hardware platform has been ported SPI Flash, stm32f10x and stm32f4xx series of on-chip Flash. These are my product platforms. Remaining platform porting difficulty is little. To port it just modify easyflashportef_port.c file. Implement erase, write, read, print feature.
Welcome everyone to fork and pull request (Github|OSChina|Coding). If you think this open source project is awesome. You can press the Star on the top right corner of project home page, and recommend it to more friends.
The figure below shows an ENV's common interface be called by the console (terminal). These interfaces are supported by the application layer called.
temp and value is 123 ;456 and save, reboot;
The figure below shows the process of upgrading software through the console by IAP. It uses this library comes with IAP function interface. It uses a serial port + Ymodem protocol mode. You can also be achieved through CAN, 485, Ethernet bus to online upgrade.

The following figure is the output of the log process through the console. The logs are saved to flash at real time. Then the board is rebooted and the logs back are read back from flash. At last logs will be erased.

All documents are in the docsen folder. Please read the documents before porting it and using it.
Using MIT open source license, please read the project LICENSE file.