方法一:
如果变量少, 可以定义在nvrecord_env_t结构体下申请自己的变量, 这个结构体会在关机前自动存如FLASH, 并在开机app_init()中自动从FLASH取出.
如果修改后也可以手动更新void nv_record_flash_flush(void)
方法二:
在npiflash_api.h文件中的枚举中添加自己的FLASH名字
enum NORFLASH_API_MODULE_ID_T
{
......
NORFLASH_API_MODULE_ID_UIFLASH,
}
在link_sym_armclang.h文件中,定义相关的宏 说明__uiflash_start和__uiflash_end的尾地址
#define __uiflash_start Image$$uiflash$$Base
#define __uiflash_end Image$$uiflash$$ZI$$Limit
在有用到初始化, 读写时声明如下变量,方便程序调用上面定义的地址
extern uint32_t __uiflash_start[];
extern uint32_t __uiflash_end[];
在LINK文件下. 打开tail_section_lds.s文件, 在尾部增加
.uiflash (NOLOAD):
{
__uiflash_start = .;
. = SECTION_SIZE(UIFLASH);
__uiflash_end = .;
} > FLASH_LOC(UIFLASH)
在这个变量中增加
__flash_tail_sec_start= ............
-SECTION_SIZE_LOC(0,UIFLASH)
-0;
__flash1_tail_sec_start= ............
-SECTION_SIZE_LOC(1,UIFLASH)
-0;
初始化
#define UIFLASH_SECTION_SIZE 0X1000 //4K
uint32_t npiflash_uiflash_open(void)
{
uint32_t block_size = 0;
uint32_t sector_size = 0;
uint32_t page_size = 0;
uint32_t res = 0;
hal_norflash_get_size(HAL_FLASH_ID_0, NULL, &block_size, §or_size, &page_size);
res = norflash_api_register(NORFLASH_API_MODULE_ID_UIFLASH,
HAL_FLASH_ID_0,
((uint32_t)__uiflash_start),
(uint32_t)__uiflash_end - (uint32_t)__uiflash_start,
block_size,
sector_size,
page_size,
UIFLASH_SECTION_SIZE,
NULL);
return res;
}
读flash bug_start[]为将FLASH读取到的缓存地址
uint8_t p_flash[P_FLASH_SIZE] = {0};
void npiflash_uiflash_read(void)
{
memcpy(p_flash, (uint8_t *)__uiflash_start, P_FLASH_SIZE);
}
写/更新flash, bug_start[]为需要写如的地址
uint32_t npiflash_uiflash_flush(void)
{
uint32_t lock = int_lock_global();
ret=norflash_api_erase ( NORFLASH_API_MODULE_ID_UIFLASH, ( uint32_t ) ( __uiflash_start ), UIFLASH_SECTION_SIZE,false);
ret=norflash_api_write ( NORFLASH_API_MODULE_ID_UIFLASH, ( uint32_t ) ( __uiflash_start ), ( uint8_t* ) bug_start, UIFLASH_SECTION_SIZE,false);
int_unlock_global ( lock );
return res;
}