Lightweight Embedded Database FlashDB

Lightweight Embedded Database FlashDB

Currently, I am using FlashDB in mass-produced medical products. It is stable, reliable, and convenient, so I recommend it. I will continue to share the technologies I use in embedded systems and artificial intelligence, so follow me for more references to accelerate your development process.Love Programming, Love Life

FlashDB: A Lightweight Embedded Database Providing Efficient Solutions for Storage in Embedded Devices

In scenarios such as embedded medical devices, industrial control equipment, and edge gateways, the storage of log data, parameter configurations, and other information is a core requirement — it must adapt to the characteristics of Flash memory while ensuring convenience, security, and efficiency.

Lightweight Embedded Database FlashDB

1. Core Positioning and Modes of FlashDB

FlashDB focuses on Flash storage solutions for embedded products, supporting both traditional file system-based modes and deeply integrating Flash characteristics, balancing performance and reliability with extremely low resource usage while extending the lifespan of Flash.

It offers two core database modes:

1. Key-Value Database (KVDB)
  • Essence: A non-relational database that stores data in “key-value pairs,” with keys as unique identifiers.
  • Features: Simple operations, strong scalability, supports two KV types: string and blob, accommodating diverse data formats.
2. Time Series Database (TSDB)
  • Essence: A time series database that stores data in chronological order, with each record carrying a timestamp.
  • Features: Suitable for storing large volumes of dynamic data, with excellent insertion and query performance, supports modifying the status of individual records for easier management.

2. Core Application Scenarios

The two modes of FlashDB cater to different embedded scenarios, covering core needs such as parameter storage and dynamic data recording:

Database Mode Typical Application Scenarios
Key-Value Database (KVDB) – Product parameter storage (e.g., device calibration parameters, operating thresholds)– User configuration information (e.g., device name, network settings)– Small file management (e.g., firmware upgrade package fragments, certificate files)
Time Series Database (TSDB) – Dynamic structured data (e.g., temperature and humidity sensor data, heart rate/step count records from smart bands)– Operation logs and alarms (e.g., device anomaly records, historical operation status logs)

3. Core Features: Lightweight, Reliable, Efficient

The competitiveness of FlashDB stems from its deep optimization for embedded scenarios, with core features including:

  • Extremely Lightweight: Memory usage is nearly 0, with very low resource consumption, suitable for low-performance MCUs.
  • Multi-Partition and Multi-Instance: When data volume is large, partitions can be refined to reduce retrieval time and improve efficiency.
  • Wear Leveling: Algorithms balance Flash erase cycles, extending hardware lifespan (the lifespan of Flash in embedded devices directly affects product lifecycle).
  • Power Failure Protection: Ensures data is not lost during sudden power outages, meeting reliability requirements for medical, industrial, and other stability-demanding scenarios.
  • KV Incremental Upgrade: After firmware upgrades, KVDB content can be automatically synchronized to avoid parameter loss or incompatibility.

4. Performance and Resource Usage: Data Validation Efficiency

The performance of FlashDB has been validated in actual hardware environments, while resource usage is extremely low, accommodating the hardware limitations of embedded devices:

1. Performance Testing of Time Series Database (TSDB)
  • On NOR Flash (W25Q64): Insertion speed: average 4ms/record (1250 records in just 5 seconds, about 250 records/second); Query speed: average 1.77ms/record (1251 records total time 2218ms).

  • On STM32F2 On-Chip Flash: Insertion speed: average 0.37ms/record (13421 records in just 5 seconds, about 2684 records/second); Query speed: average 0.11ms/record (13422 records total time 1475ms).

2. Resource Usage (Based on STM32F4 + IAR8.20)
Module ro code ro data rw data
fdb.o 276 bytes 232 bytes 1 byte
fdb_kvdb.o 4584 bytes 356 bytes 1 byte
fdb_tsdb.o 1160 bytes 236 bytes
fdb_utils.o 418 bytes 1024 bytes

It can be seen that FlashDB has minimal total resource usage, fully accommodating resource-constrained embedded devices.

5. Usage and Licensing

  • Documentation Support: Provides complete quick start, porting, configuration, and API documentation, available at:FlashDB Documentation

  • Open Source License: Licensed under Apache-2.0, allowing commercial use, source code hosted on Gitee:https://gitee.com/armink/FlashDB

Conclusion

FlashDB’s core advantages of “lightweight, reliable, and efficient” perfectly adapt to the storage needs of embedded medical devices, industrial control, edge gateways, etc. — addressing both the wear and power failure reliability issues of Flash storage while covering the storage needs of parameters and dynamic data through two database modes.

For developers needing to quickly implement a stable storage solution, FlashDB is undoubtedly a choice worth trying.

In the next article, we will introduce the porting methods of FlashDB on platforms like STM32, so follow me to not miss the practical part!

https://www.bookstack.cn/read/flashdb-2.1-zh/_coverpage.md

Leave a Comment