【完善】readme。

Signed-off-by: armink <armink.ztl@gmail.com>
v5.x-beta
armink 6 years ago
parent 5ad9396de0
commit 9121fd3e15

@ -1,157 +1,105 @@
# EasyFlash
# EasyFlash:超轻量级嵌入式数据库
[![GitHub release](https://img.shields.io/github/release/armink/EasyFlash.svg)](https://github.com/armink/EasyFlash/releases/latest) [![GitHub commits](https://img.shields.io/github/commits-since/armink/EasyFlash/4.1.0.svg)](https://github.com/armink/EasyFlash/compare/4.1.0...master) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/armink/EasyFlash/master/LICENSE)
## 1、介绍[English](#1-introduction)
## 简介
[EasyFlash](https://github.com/armink/EasyFlash)是一款开源的轻量级嵌入式Flash存储器库方便开发者更加轻松的实现基于Flash存储器的常见应用开发。非常适合智能家居、可穿戴、工控、医疗、物联网等需要断电存储功能的产品资源占用极低支持各种 MCU 片上存储器。该库主要包括 **三大实用功能**
EasyFlash 是一款超轻量级的嵌入式数据库开源项目,专注于提供嵌入式产品的数据存储方案。其拥有较强的可靠性及性能,并在保证极低的资源占用前提下,尽可能延长 Flash 使用寿命。
- **ENV** 快速保存产品参数,支持 **写平衡(磨损平衡)** 及 **掉电保护** 功能
EasyFlash 提供两种数据库模式:
EasyFlash不仅能够实现对产品的 **设定参数** 或 **运行日志** 等信息的掉电保存功能,还封装了简洁的 **增加、删除、修改及查询** 方法, 降低了开发者对产品参数的处理难度也保证了产品在后期升级时拥有更好的扩展性。让Flash变为NoSQL非关系型数据库模型的小型键值Key-Value存储数据库。
- **键值数据库** 是一种非关系数据库它将数据存储为键值Key-Value对集合其中键作为唯一标识符。KVDB 操作简洁,可扩展性强。
- **时序数据库** :时间序列数据库 Time Series Database , 简称 TSDB它将数据按照 **时间顺序存储** 。TSDB 数据具有时间戳,数据存储量大,插入及查询性能高。
- **IAP** 在线升级再也不是难事儿
## 使用场景
该库封装了IAP(In-Application Programming)功能常用的接口支持CRC32校验同时支持Bootloader及Application的升级。
如今物联网产品种类越来越多运行时产生的数据种类及总量及也在不断变大。EasyFlash 提供了多样化的数据存储方案,不仅资源占用小,并且存储容量大,非常适合用于物联网产品。下面是主要应用场景:
- **Log** 无需文件系统日志可直接存储在Flash上
- **键值数据库**
- 产品参数存储
- 用户配置信息存储
- 小文件管理
- **时序数据库**
- 存储动态产生的结构化数据:如 温湿度传感器采集的环境监测信息,智能手环实时记录的人体健康信息等
- 记录运行日志:存储产品历史的运行日志,异常告警的记录等
非常适合应用在小型的不带文件系统的产品中,方便开发人员快速定位、查找系统发生崩溃或死机的原因。同时配合[EasyLogger](https://github.com/armink/EasyLogger)(我开源的超轻量级、高性能C日志库它提供与EasyFlash的无缝接口)一起使用轻松实现C日志的Flash存储功能。
## 主要特性
### 1.1、V4.0 NG 模式
- 资源占用极低,内存占用几乎为 **0** ;
- 支持 多分区,**多实例** 。数据量大时,可细化分区,降低检索时间;
- 支持 **磨损平衡** ,延长 Flash 寿命;
- 支持 **掉电保护** 功能,可靠性高;
- 支持 字符串及 blob 两种 KV 类型,方便用户操作;
- 支持 KV **增量升级** ,产品固件升级后, KVDB 内容也支持自动升级;
- 支持 修改每条 TSDB 记录的状态,方便用户进行管理;
自 2019 年春节后EasyFlash 经过 4 年多的迭代,结合众多开发者的需求及建议,终于发布了 V4.0 版本,该版本中的 ENV 功能被命名为 **NG** (Next Generation) 模式,这是一个完全重构的新版本,具有以下新特性:
## 性能及资源占用
- 更小的资源占用,内存占用 **几乎为 0** V4.0 以前版本会使用额外的 RAM 空间进行缓存)
- ENV 的值类型支持 **任意类型** 、任意长度,相当于直接 memcpy 变量至 flash V4.0 之前只支持存储字符串)
- ENV 操作效率比以前的模式高,充分利用剩余空闲区域,擦除次数及操作时间显著降低;
- **原生支持** 磨损平衡、掉电保护功能 V4.0 之前需要占用额外的 Flash 扇区);
- ENV 支持 **增量升级** ,固件升级后 ENV 也支持升级;
- 支持大数据存储模式,**长度无限制**,数据可在多个 Flash 扇区上顺序存储。像脚本程序、音频等占用 Flash 超过 1 个扇区的资源也都可以存入 ENV即将在 V4.2 支持);
- 支持 **数据加密** ,提升存储的安全性,物联网时代的必备功能(即将在 V4.3 支持);
- 支持 **数据压缩** ,减低 Flash 占用(即将在 V4.4 支持);
### TSDB 性能测试1 nor flash W25Q64
V4.0 设计及内部原理V4.0 迁移指南等更多内容请继续阅读下面的 [文档章节](#3文档)
### 1.2、资源占用
```
最低要求: ROM: 6K bytes RAM: 0.1K bytes
```shell
msh />tsl bench
Append 1250 TSL in 5 seconds, average: 250.00 tsl/S, 4.00 ms/per
Query total spent 2248 (ms) for 1251 TSL, min 1, max 2, average: 1.80 ms/per
```
### 1.3、支持平台
目前已移植硬件平台有 `stm32f10x``stm32f4xx` 系列的片内Flash片外的 SPI Flash基于 [SFUD](https://github.com/armink/SFUD)这些也是笔者产品使用的平台。其余平台的移植难度不大在项目的设计之初就有考虑针对所有平台的适配性问题64位除外所以对所有移植接口都有做预留。移植只需修改 [`\easyflash\port\ef_port.c`](https://github.com/armink/EasyFlash/blob/master/easyflash/port/ef_port.c) 一个文件,实现里面的擦、写、读及打印功能即可。
欢迎大家 **fork and pull request**([Github](https://github.com/armink/EasyFlash)|[OSChina](http://git.oschina.net/armink/EasyFlash)|[Coding](https://coding.net/u/armink/p/EasyFlash/git)) 。如果觉得这个开源项目很赞,可以点击[项目主页](https://github.com/armink/EasyFlash) 右上角的 **Star**,同时把它推荐给更多有需要的朋友。
## 2、流程
### 2.1、ENV环境变量KV数据库
下图为通过控制台(终端)来调用环境变量的常用接口,演示了以下过程,这些接口都支持被应用层直接调用。
- 1、创建“温度”的环境变量名为 `temp`,并且赋值为 `123`
- 2、保存“温度”到Flash中并重启V4.0 版本的每个操作完自动保存,无需额外保存);
- 3、检查“温度”是否被成功保存
- 4、修改“温度”值为 `456` 并保存、重启;
- 5、检查“温度”是否被成功修改
- 6、删除“温度”的环境变量。
![easy_flash_env](/docs/zh/images/EnvDemo.gif)
### 2.2、IAP在线升级
下图演示了通过控制台来进行IAP升级软件的过程使用的是库中自带的IAP功能接口演示采用的是串口+Ymodem协议的方式。你还也可以实现通过CAN、485、以太网等总线来实现远程网络更新。
![easy_flash_iap](/docs/zh/images/IapDemo.gif)
### 2.3、Log日志存储
下图过程为通过控制台输出日志并将输出的日志存储到Flash中。重启再读取上次保存的日志最后清空Flash日志。
![easy_flash_log](/docs/zh/images/LogDemo.gif)
## 3、文档
- API 文档:[`\docs\zh\api.md`](docs/zh/api.md)
- 移植文档:[`\docs\zh\port.md`](docs/zh/port.md)
- V4.0 迁移指南:[`\docs\zh\v4_migrate.md`](docs/zh/v4_migrate.md)
- V4.0 ENV 功能设计与实现:[`\docs\zh\design.md`](docs/zh/design.md)
务必保证在 **阅读文档** 后再移植使用。
插入平均4 ms查询平均1.8 ms
## 4、支持
### TSDB 性能测试2 stm32f2 onchip flash
![support](/docs/zh/images/wechat_support.png)
如果 EasyFlash 解决了你的问题,不妨扫描上面二维码请我 **喝杯咖啡**~
## 5、许可
采用 MIT 开源协议,细节请阅读项目中的 LICENSE 文件内容。
---
## 1 Introduction
[EasyFlash](https://github.com/armink/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**
- **Env(environment variables)** Fast Saves product parameters. Support **write balance mode(wear leveling)** and **power fail safeguard**.
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 makes sure the product has better scalability after upgrade. Turns the Flash into a small NoSQL (non-relational databases) model and Key-Value stores database.
- **IAP** : online upgrade is no longer a difficult thing.
The library encapsulates the IAP (In-Application Programming) feature common interface. Support CRC32 checksum. While supporting the bootloader and application upgrade.
- **Log** : The logs can store to product's flash which has no file-system.
It's very suitable for small without a file system products. The developer can easy to locate and query problem when system crashes or freezes. You can use [EasyLogger](https://github.com/armink/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.
### 1.1 Resource consumption
```
Minimum : ROM: 6K bytes RAM: 0.2K bytes
```shell
msh />tsl bench
Append 13527 TSL in 5 seconds, average: 2705.40 tsl/S, 0.37 ms/per
Query total spent 1621 (ms) for 13528 TSL, min 0, max 1, average: 0.12 ms/per
```
### 1.2 Supported platforms
插入平均0.37 ms查询平均0.12 ms
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 [`\easyflash\port\ef_port.c`](https://github.com/armink/EasyFlash/blob/master/easyflash/port/ef_port.c) file. Implement erase, write, read, print feature.
### 资源占用 (stm32f4 IAR8.20)
Welcome everyone to **fork and pull request**([Github](https://github.com/armink/EasyFlash)|[OSChina](http://git.oschina.net/armink/EasyFlash)|[Coding](https://coding.net/u/armink/p/EasyFlash/git)). If you think this open source project is awesome. You can press the **Star** on the top right corner of [project home page](https://github.com/armink/EasyFlash), and recommend it to more friends.
```shell
Module ro code ro data rw data
------ ------- ------- -------
...
easyflash.o 276 232 1
ef_kv.o 4 584 356 1
ef_ts_log.o 1 160 236
ef_utils.o 418 1 024
...
```
## 2 Flow
上面是 IAR 的 map 文件信息,可见 EasyFlash 的资源占用非常低
### 2.1 Env(KV database)
## 如何使用
The figure below shows an ENV's common interface be called by the console (terminal). These interfaces are supported by the application layer called.
从 EasyFlash V5.0 开始,由于软件架构完全重构,导致代码改动巨大,为此牺牲了之前 API 的兼容性。后续 EasyFlash 的 V4.X 版本将会继续维护(见 stable-v4.x 分支),希望大家谅解。
- 1.Create temperature environment variable. It's name is `temp` and value is `123`;
- 2.Save temperature to flash and reboot;
- 3.Check the temperature has saved successfully;
- 4.Change the temperature value to `456` and save, reboot;
- 5.Check the temperature has changed successfully;
- 6.Delete temperature environment variable.
### 移植
![easy_flash_env](/docs/en/images/EnvDemo.gif)
EasyFlash 底层依赖于 RT-Thread 的 FAL (Flash Abstraction Layer) Flash 抽象层开源软件包 ,该开源库也支持运行在裸机平台 [(点击查看介绍)](http://packages.rt-thread.org/detail.html?package=fal)。所以只需要将所用到的 Flash 对接到 FAL ,即可完成整个移植工作。
### 2.2 IAP
FAL 移植主要流程:
The figure below shows the process of upgrading software through the console by IAP. It use 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.
- 定义 flash 设备,详见([GitHub](https://github.com/RT-Thread-packages/fal#21%E5%AE%9A%E4%B9%89-flash-%E8%AE%BE%E5%A4%87)|[Gitee](https://gitee.com/RT-Thread-Mirror/fal#21%E5%AE%9A%E4%B9%89-flash-%E8%AE%BE%E5%A4%87)
- 定义 flash 设备表,详见([GitHub](https://github.com/RT-Thread-packages/fal#22%E5%AE%9A%E4%B9%89-flash-%E8%AE%BE%E5%A4%87%E8%A1%A8)|[Gitee](https://gitee.com/RT-Thread-Mirror/fal#22%E5%AE%9A%E4%B9%89-flash-%E8%AE%BE%E5%A4%87%E8%A1%A8)
- 定义 flash 分区表,详见([GitHub](https://github.com/RT-Thread-packages/fal#23%E5%AE%9A%E4%B9%89-flash-%E5%88%86%E5%8C%BA%E8%A1%A8)|[Gitee](https://gitee.com/RT-Thread-Mirror/fal#23%E5%AE%9A%E4%B9%89-flash-%E5%88%86%E5%8C%BA%E8%A1%A8)
![easy_flash_iap](/docs/en/images/IapDemo.gif)
### 示例
### 2.3 Log
EasyFlash 提供了主要功能的示例,直接加入工程即可运行,并具有一定的参考性
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.
| 文件路径 | 介绍 | 备注 |
| ------------------------------------------------------------ | --------------------------------------- | ---- |
| [`samples/kvdb_type_string_sample.c`](samples/kvdb_type_string_sample.c) | KVDB 使用字符型键值的示例 | |
| [`samples/kvdb_type_blob_sample.c`](samples/kvdb_type_blob_sample.c) | KVDB 使用 blob 型(任意类型)键值的示例 | |
| [`samples/tsdb_sample.c`](samples/tsdb_sample.c) | TSDB 示例 | |
![easy_flash_log](/docs/en/images/LogDemo.gif)
## 支持
## 3 Documents
![support](E:/Program/STM32/EasyFlash/docs/zh/images/wechat_support.png)
All documents are in the [`\docs\en\`](https://github.com/armink/EasyFlash/tree/master/docs/en) folder. Please **read the documents** before porting it and using it.
如果 EasyFlash 解决了你的问题,不妨扫描上面二维码请我 **喝杯咖啡**~
## 4 License
## 许可
Using MIT open source license, please read the project LICENSE file.
采用 MIT 开源协议,细节请阅读项目中的 LICENSE 文件内容。

Binary file not shown.

Before

Width:  |  Height:  |  Size: 268 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 277 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 277 KiB

@ -1,278 +0,0 @@
# EasyFlash 移植说明
---
## 1、下载源码
[点击此链接](https://github.com/armink/EasyFlash/archive/master.zip)即可直接下载位于Github上的最新源码。
> 建议:点击项目主页 https://github.com/armink/EasyFlash 右上角 **Watch & Star**,这样项目有更新时,会及时以邮件形式通知你。
如果Github下载太慢也可以点击项目位于的国内仓库下载的链接([OSChina](https://git.oschina.net/Armink/EasyFlash/repository/archive?ref=master)|[Coding](https://coding.net/u/armink/p/EasyFlash/git/archive/master))。
## 2、导入项目
在导入到项目前,先打开[`\demo\`](https://github.com/armink/EasyFlash/tree/master/demo)文件夹检查下有没有与项目Flash规格一致的Demo。如果有则先直接跳过2、3、4章节按照第5章的要求设置参数并运行、验证Demo。验证通过再按照下面的导入项目要求将Demo中的移植文件直接导入到项目中即可。
- 1、先解压下载好的源码包文件的目录结构大致如下
|源文件 |描述 |
|:------------------------------ |:----- |
|\easyflash\src\ef_env.c |Env常规模式相关操作接口及实现源码|
|\easyflash\src\ef_iap.c |IAP 相关操作接口及实现源码|
|\easyflash\src\ef_log.c |Log 相关操作接口及实现源码|
|\easyflash\src\ef_utils.c |EasyFlash常用小工具例如CRC32|
|\easyflash\src\easyflash.c |目前只包含EasyFlash初始化方法|
|\easyflash\port\ef_port.c |不同平台下的EasyFlash移植接口|
|\demo\env\stm32f10x\non_os |stm32f10x裸机片内Flash的Env demo|
|\demo\env\stm32f10x\non_os_spi_flash |stm32f10x裸机SPI Flash的Env demo|
|\demo\env\stm32f10x\rtt |stm32f10x基于[RT-Thread](http://www.rt-thread.org/)的片内Flash Env demo|
|\demo\env\stm32f4xx |stm32f4xx基于[RT-Thread](http://www.rt-thread.org/)的片内Flash Env demo|
|\demo\iap\ymodem+rtt.c |使用[RT-Thread](http://www.rt-thread.org/)+[Ymodem](https://github.com/RT-Thread/rt-thread/tree/master/components/utilities/ymodem)的IAP Demo|
|\demo\log\easylogger.c |基于[EasyLogger](https://github.com/armink/EasyLogger)的Log Demo|
- 2、将`\easyflash\`(里面包含`inc`、`src`及`port`的那个)文件夹拷贝到项目中;
- 3、添加`\easyflash\src\easyflash.c`、`\easyflash\src\ef_utils.c`及`\easyflash\port\ef_port.c`这些文件到项目的编译路径中;
- 4、根据项目需求选择性添加`\easyflash\src\`中的其他源码文件到项目的编译路径中;
- 5、添加`\easyflash\inc\`文件夹到编译的头文件目录列表中;
## 3、Flash规格
在移植时务必先要了解项目的Flash规格这里需要了解是规格是 **擦除粒度(擦除最小单元)** 、**写入粒度**及 **内部存储结构** 各个厂家的Flash规格都有差异同一厂家不同系列的规格也有差异。以下是一些常见 Flash 的规格
| Flash 类型 | 写入粒度 | 擦除粒度 | 内部存储结构 |
| ---------------------- | -------- | ------------ | ------------------------- |
| STM32F1 片内 Flash | 4bytes | 1K/2K | 均匀分布 |
| STM32F2/F4 片内 Flash | 1byte | 16K/64K/128K | 最大的有128K最小的有16K |
| Nor FlashSPI-Flash | 1bit | 4K | 均匀分布 |
> **注意**
> - 1、务必保证熟悉Flash规格后再继续下章节
> - 2、V4.0 新模式暂时无法使用在 STM32L4 片内 Flash 上L4 只能使用 V3.0 版本或者 V4.0 的 EF_ENV_USING_LEGACY_MODE 模式
## 4、移植接口
### 4.1 移植初始化
EasyFlash移植初始化。可以传递默认环境变量初始化EasyFlash移植所需的资源等等。
```C
EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size)
```
|参数 |描述|
|:----- |:----|
|default_env |默认的环境变量|
|default_env_size |默认环境变量的数量|
### 4.2 读取Flash
最小单位为4个字节。
```C
EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size)
```
|参数 |描述|
|:----- |:----|
|addr |读取起始地址4字节对齐|
|buf |存放读取数据的缓冲区|
|size |读取数据的大小(字节)|
### 4.3 擦除Flash
```C
EfErrCode ef_port_erase(uint32_t addr, size_t size)
```
|参数 |描述|
|:----- |:----|
|addr |擦除起始地址|
|size |擦除数据的大小(字节)|
### 4.4 写入Flash
最小单位为4个字节。
```C
EfErrCode ef_port_write(uint32_t addr, const uint32_t *buf, size_t size)
```
|参数 |描述|
|:----- |:----|
|addr |写入的起始地址4字节对齐|
|buf |源数据的缓冲区|
|size |写入数据的大小(字节)|
### 4.5 对环境变量缓冲区加锁
为了保证RAM缓冲区在并发执行的安全性所以需要对其进行加锁如果项目的使用场景不存在并发情况则可以忽略。有操作系统时可以使用获取信号量来加锁裸机时可以通过关闭全局中断来加锁。
```C
void ef_port_env_lock(void)
```
### 4.6 对环境变量缓冲区解锁
有操作系统是可以使用释放信号量来解锁,裸机时可以通过开启全局中断来解锁。
```C
void ef_port_env_unlock(void)
```
### 4.7 打印调试日志信息
在定义`PRINT_DEBUG`宏后,打印调试日志信息。
```C
void ef_log_debug(const char *file, const long line, const char *format, ...)
```
|参数 |描述|
|:----- |:----|
|file |调用该方法的文件|
|line |调用该方法的行号|
|format |打印格式|
|... |不定参|
### 4.8 打印普通日志信息
```C
void ef_log_info(const char *format, ...)
```
|参数 |描述|
|:----- |:----|
|format |打印格式|
|... |不定参|
### 4.9 无格式打印信息
该方法输出无固定格式的打印信息,为`ef_print_env`方法所用(如果不使用`ef_print_env`则可以忽略)。而`ef_log_debug`及`ef_log_info`可以输出带指定前缀及格式的打印日志信息。
```C
void ef_print(const char *format, ...)
```
|参数 |描述|
|:----- |:----|
|format |打印格式|
|... |不定参|
### 4.10 默认环境变量集合
在 ef_port.c 文件顶部定义有 `static const ef_env default_env_set[]` ,我们可以将产品上需要的默认环境变量集中定义在这里。当 flash 第一次初始化时会将默认的环境变量写入。
默认环境变量内部采用 void * 类型,所以支持任意类型,可参考如下示例:
```C
static uint32_t boot_count = 0;
static time_t boot_time[10] = {0, 1, 2, 3};
static const ef_env default_env_set[] = {
// { key , value, value_len }
{"username", "armink", 0}, //类型为字符串的环境变量可以设定值的长度为 0 ,此时会在初始化时会自动检测其长度
{"password", "123456", 0},
{"boot_count", &boot_count, sizeof(boot_count)}, //整形
{"boot_time", &boot_time, sizeof(boot_time)}, //数组类型,其他类型使用方式类似
};
```
## 5、设置参数
配置时需要修改项目中的`ef_cfg.h`文件,开启、关闭、修改对应的宏即可。
### 5.1 环境变量功能
- 默认状态:开启
- 操作方法:开启、关闭`EF_USING_ENV`宏即可
#### 5.1.1 自动更新(增量更新)
可以对 ENV 设置版本号(参照 5.1.2)。当 ENV 初始化时,如果检测到产品存储的版本号与设定版本号不一致,会自动追加默认环境变量集合中新增的环境变量。
该功能非常适用于经常升级的产品中,当产品功能变更时,有可能会新增环境变量,此时只需要增大当前设定的 ENV 版本号,下次固件升级后,新增的环境变量将会自动追加上去。
- 默认状态:关闭
- 操作方法:开启、关闭`EF_ENV_AUTO_UPDATE`宏即可
#### 5.1.2 环境变量版本号
该配置依赖于 5.1.1 配置。设置的环境变量版本号为整形数值,可以从 0 开始。如果在默认环境变量表中增加了环境变量,此时需要对该配置进行修改(通常加 1 )。
- 操作方法:修改`EF_ENV_VER_NUM`宏对应值即可
### 5.2 在线升级功能
- 默认状态:开启
- 操作方法:开启、关闭`EF_USING_IAP`宏即可
### 5.3 日志功能
- 默认状态:开启
- 操作方法:开启、关闭`EF_USING_LOG`宏即可
### 5.4 Flash 擦除粒度(最小擦除单位)
- 操作方法:修改`EF_ERASE_MIN_SIZE`宏对应值即可单位byte
### 5.5 Flash 写入粒度
- 操作方法:修改`EF_WRITE_GRAN`宏对应值即可单位bit仅支持1/8/32
### 5.5 备份区
备份区共计包含3个区域依次为环境变量区、日志区及在线升级区。分区方式如下图所示
![backup_area_partiton](images/BackupAreaPartition.jpg)
在配置时需要注意以下几点:
- 1、所有的区域必须按照`EF_ERASE_MIN_SIZE`对齐;
- 2、环境变量分区大少至少为两倍以上 `EF_ERASE_MIN_SIZE`
- 3、从 V4.0 开始 ENV 的模式命名为 NG 模式V4.0 之前的称之为 LEGACY 遗留模式;
- 遗留模式已经被废弃,不再建议继续使用;
- 如果需要继续使用遗留模式,请 EasyFlash 的 V3.X 版本。
#### 5.5.1 备份区起始地址
- 操作方法:修改`EF_START_ADDR`宏对应值即可
#### 5.5.2 环境变量区总容量
- 操作方法:修改`ENV_AREA_SIZE`宏对应值即可
> 注意:不使用环境变量功能时,可以不定义此宏。
#### 5.5.3 日志区总容量
- 操作方法:修改`LOG_AREA_SIZE`宏对应值即可
> 注意:不使用日志功能时,可以不定义此宏。
### 5.6 调试日志
开启后,将会库运行时自动输出调试日志
- 默认状态:开启
- 操作方法:开启、关闭`PRINT_DEBUG`宏即可
## 6、测试验证
如果`\demo\`文件夹下有与项目Flash规格一致的Demo则直接编译运行观察测试结果即可。无需关注下面的步骤。
每次使用前,务必先执行`easyflash_init()`方法对EasyFlash库及所使用的Flash进行初始化保证初始化没问题后再使用各功能的API方法。如果出现错误或断言需根据提示信息检查移植配置及接口。
### 6.1 环境变量
查看[`\demo\env\`](https://github.com/armink/EasyFlash/tree/master/demo/env)子文件夹中例子的`README.md`说明文档。测试时可以将`\demo\env\stm32f10x\non_os\app\src\app.c`中的`static void test_env(void)`方法体复制到项目中,然后运行测试。
### 6.2 在线升级
查看[`\demo\iap\README.md`](https://github.com/armink/EasyFlash/tree/master/demo/iap)说明文档。
### 6.3 日志
查看[`\demo\log\README.md`](https://github.com/armink/EasyFlash/tree/master/demo/log)说明文档。
> 注意:`easylogger.c`是使用[EasyLogger](https://github.com/armink/EasyLogger)与EasyFlash的无缝接口的例子EasyLogger提供针对日志的很多常用功能封装详细功能可以查看其介绍。使用这个例子时务必记得将EasyLogger一并导入到项目中。
Loading…
Cancel
Save