RMUL2025/lib/MiniFlashDB/README.md

71 lines
1.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Mini Flash
嵌入式Flash数据库无磨损平衡等功能但是有极低的Flash占用stm32 -Og编译仅占用1.7k和对不支持逆序写入的FlashSTM32L4/G4的支持。
## 使用方法
### CMakelists.txt
```
add_subdirectory(${MiniFlashDB_PATH} mf.out)
target_include_directories(
MiniFlash
PUBLIC ${MiniFlashDB_CONFIG_FILE_PATH}
)
```
### mf_config.h
示例配置文件在 ` ./config`文件夹下。请将 `mf_config.h `放在`${MiniFlashDB_CONFIG_FILE_PATH}`目录下由cmake加入头文件列表
```c
// mf_config.h
/* 一块FLASH空间的大小 */
#define MF_FLASH_BLOCK_SIZE (2048)
/* 主FLASH地址 */
#define MF_FLASH_MAIN_ADDR (flash_1)
/* 备份FLASH地址 */
#define MF_FLASH_BACKUP_ADDR (flash_2)
/* Flash读写函数 */
#define MF_ERASE mf_erase
#define MF_WRITE mf_write
static void mf_erase(void *addr) {
/* 从addr开始擦除长度为MF_FLASH_BLOCK_SIZE的flash */
...
}
static void mf_write(void *addr, void *buf) {
/* 从addr开始把buf写入长度为MF_FLASH_BLOCK_SIZE的flash */
...
}
```
## API
```c
/* 初始化 */
void mf_init();
/* 添加键值 */
mf_status_t mf_add_key(const char *name, void *data, size_t size);
/* 设置键值数据 */
mf_status_t mf_set_key(const char *name, const void *data, size_t size);
/* 查找键值 */
mf_key_info_t *mf_search_key(const char *name);
/* 获取键值数据 */
uint8_t *mf_get_key_data(mf_key_info_t *key);
/* 获取键值名称 */
const char *mf_get_key_name(mf_key_info_t *key);
```