diff --git a/docs/zh/api.md b/docs/zh/api.md index 1edd4ea..3903f65 100644 --- a/docs/zh/api.md +++ b/docs/zh/api.md @@ -329,17 +329,12 @@ void flash_print(const char *format, ...) - 默认状态:开启 - 操作方法:开启、关闭`FLASH_USING_LOG`宏即可 -### 3.4 ENV的CRC32校验 - -- 默认状态:开启 -- 操作方法:开启、关闭`FLASH_ENV_USING_CRC_CHECK`宏即可 - -### 3.5 环境变量的容量 +### 3.4 环境变量的容量 - 默认容量:2K Bytes - 操作方法:修改`FLASH_USER_SETTING_ENV_SIZE`宏定义即可 -### 3.6 磨损平衡/常规 模式 +### 3.5 磨损平衡/常规 模式 - 默认状态:常规模式 - 磨损平衡模式:打开`FLASH_ENV_USING_WEAR_LEVELING_MODE`,关闭`FLASH_ENV_USING_NORMAL_MODE` @@ -354,4 +349,4 @@ void flash_print(const char *format, ...) - 写数据前务必记得先擦除 - 环境变量设置完后,只有调用 `flash_save_env`才会保存在Flash中,否则开机会丢失修改的内容 - 不要在应用程序及Bootloader中执行擦除及拷贝自身的动作 -- Flash读取和写入方法的最小单位为4个字节,擦除的最小单位则需根据用户的平台来确定 +- ENV及Log功能对Flash擦除和写入要求4个字节对齐,擦除的最小单位则需根据用户的平台来确定 diff --git a/easyflash/inc/flash.h b/easyflash/inc/flash.h index 8881b4e..2eb0ff9 100644 --- a/easyflash/inc/flash.h +++ b/easyflash/inc/flash.h @@ -43,9 +43,7 @@ extern "C" { /* using IAP function */ #define FLASH_USING_IAP /* using save log function */ -/* #define FLASH_USING_LOG */ -/* using CRC32 check when load environment variable from Flash */ -#define FLASH_ENV_USING_CRC_CHECK +#define FLASH_USING_LOG /* the user setting size of ENV, must be word alignment */ #define FLASH_USER_SETTING_ENV_SIZE (2 * 1024) /* default 2K */ /* using wear leveling mode or normal mode */ @@ -64,7 +62,7 @@ if (!(EXPR)) \ while (1); \ } /* EasyFlash software version number */ -#define FLASH_SW_VERSION "1.06.10" +#define FLASH_SW_VERSION "1.07.02" typedef struct _flash_env{ char *key; diff --git a/easyflash/src/flash_env.c b/easyflash/src/flash_env.c index 1e525fa..c032902 100644 --- a/easyflash/src/flash_env.c +++ b/easyflash/src/flash_env.c @@ -49,12 +49,8 @@ enum { /* data section ENV end address index in system section */ ENV_PARAM_INDEX_END_ADDR = 0, - -#ifdef FLASH_ENV_USING_CRC_CHECK /* data section CRC32 code index in system section */ ENV_PARAM_INDEX_DATA_CRC, -#endif - /* flash ENV parameters word size */ ENV_PARAM_WORD_SIZE, /* flash ENV parameters byte size */ @@ -79,11 +75,8 @@ static uint32_t *find_env(const char *key); static FlashErrCode del_env(const char *key); static size_t get_env_data_size(void); static FlashErrCode create_env(const char *key, const char *value); - -#ifdef FLASH_ENV_USING_CRC_CHECK static uint32_t calc_env_crc(void); static bool env_crc_is_ok(void); -#endif /** * Flash ENV initialize. @@ -498,8 +491,6 @@ void flash_load_env(void) { env_cache_bak = env_cache + ENV_PARAM_WORD_SIZE; /* read all ENV from flash */ flash_read(get_env_data_addr(), env_cache_bak, get_env_data_size()); - -#ifdef FLASH_ENV_USING_CRC_CHECK /* read ENV CRC code from flash */ flash_read(get_env_system_addr() + ENV_PARAM_INDEX_DATA_CRC * 4, &env_cache[ENV_PARAM_INDEX_DATA_CRC] , 4); @@ -508,8 +499,6 @@ void flash_load_env(void) { FLASH_INFO("Warning: ENV CRC check failed. Set it to default.\n"); flash_env_set_default(); } -#endif - } } @@ -519,11 +508,8 @@ void flash_load_env(void) { FlashErrCode flash_save_env(void) { FlashErrCode result = FLASH_NO_ERR; -#ifdef FLASH_ENV_USING_CRC_CHECK /* calculate and cache CRC32 code */ env_cache[ENV_PARAM_INDEX_DATA_CRC] = calc_env_crc(); -#endif - /* erase ENV */ result = flash_erase(get_env_system_addr(), flash_get_env_write_bytes()); switch (result) { @@ -554,7 +540,6 @@ FlashErrCode flash_save_env(void) { return result; } -#ifdef FLASH_ENV_USING_CRC_CHECK /** * Calculate the cached ENV CRC32 value. * @@ -571,9 +556,7 @@ static uint32_t calc_env_crc(void) { return crc32; } -#endif -#ifdef FLASH_ENV_USING_CRC_CHECK /** * Check the ENV CRC32 * @@ -587,7 +570,6 @@ static bool env_crc_is_ok(void) { return false; } } -#endif #endif /* FLASH_ENV_USING_NORMAL_MODE */ diff --git a/easyflash/src/flash_env_wl.c b/easyflash/src/flash_env_wl.c index af8d933..6272911 100644 --- a/easyflash/src/flash_env_wl.c +++ b/easyflash/src/flash_env_wl.c @@ -56,12 +56,8 @@ enum { /* data section ENV detail part end address index */ ENV_PARAM_PART_INDEX_END_ADDR = 0, - -#ifdef FLASH_ENV_USING_CRC_CHECK /* data section CRC32 code index */ ENV_PARAM_PART_INDEX_DATA_CRC, -#endif - /* ENV parameters part word size */ ENV_PARAM_PART_WORD_SIZE, /* ENV parameters part byte size */ @@ -96,11 +92,8 @@ static size_t get_env_user_used_size(void); static FlashErrCode create_env(const char *key, const char *value); static FlashErrCode del_env(const char *key); static FlashErrCode save_cur_using_data_addr(uint32_t cur_data_addr); - -#ifdef FLASH_ENV_USING_CRC_CHECK static uint32_t calc_env_crc(void); static bool env_crc_is_ok(void); -#endif /** * Flash ENV initialize. @@ -569,8 +562,6 @@ void flash_load_env(void) { env_cache_bak = env_cache + ENV_PARAM_PART_WORD_SIZE; /* read all ENV from flash */ flash_read(get_env_detail_addr(), env_cache_bak, get_env_detail_size()); - -#ifdef FLASH_ENV_USING_CRC_CHECK /* read ENV CRC code from flash */ flash_read(get_cur_using_data_addr() + ENV_PARAM_PART_INDEX_DATA_CRC * 4, &env_cache[ENV_PARAM_PART_INDEX_DATA_CRC], 4); @@ -579,8 +570,6 @@ void flash_load_env(void) { FLASH_INFO("Warning: ENV CRC check failed. Set it to default.\n"); flash_env_set_default(); } -#endif - } } @@ -597,11 +586,8 @@ FlashErrCode flash_save_env(void) { /* wear leveling process, automatic move ENV to next available position */ while (get_cur_using_data_addr() + env_detail_size < get_env_start_addr() + flash_get_env_total_size()) { - -#ifdef FLASH_ENV_USING_CRC_CHECK - /* calculate and cache CRC32 code */ - env_cache[ENV_PARAM_PART_INDEX_DATA_CRC] = calc_env_crc(); -#endif + /* calculate and cache CRC32 code */ + env_cache[ENV_PARAM_PART_INDEX_DATA_CRC] = calc_env_crc(); /* erase ENV */ result = flash_erase(get_cur_using_data_addr(), ENV_PARAM_PART_BYTE_SIZE + env_detail_size); switch (result) { @@ -667,7 +653,6 @@ FlashErrCode flash_save_env(void) { return result; } -#ifdef FLASH_ENV_USING_CRC_CHECK /** * Calculate the cached ENV CRC32 value. * @@ -684,9 +669,7 @@ static uint32_t calc_env_crc(void) { return crc32; } -#endif -#ifdef FLASH_ENV_USING_CRC_CHECK /** * Check the ENV CRC32 * @@ -700,7 +683,6 @@ static bool env_crc_is_ok(void) { return false; } } -#endif /** * Save current using data section address to flash.