1 Star 0 Fork 1

刘骢 / MiniFlashDB

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Mini Flash

嵌入式Flash数据库,无磨损平衡等功能,但是有极低的Flash占用(stm32 -Og编译仅占用1.7k)和对不支持逆序写入的Flash(STM32L4/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加入头文件列表

// 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

/* 初始化 */
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);
MIT License Copyright (c) 2022 刘骢 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

嵌入式Flash数据库,无磨损平衡等功能,但是有极低的Flash占用和对不支持逆序写入的Flash(STM32L4/G4)的支持。 展开 收起
C 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/jiu-xiao/MiniFlashDB.git
git@gitee.com:jiu-xiao/MiniFlashDB.git
jiu-xiao
MiniFlashDB
MiniFlashDB
main

搜索帮助