FR8018HA怎么进行flash读写
-
使用FR8018芯片,有需要断电保存的变量值需要用到flash读写功能,用了图上的代码,读出来数组里面全部是0,是地址有问题吗?
!
-
#include "os_timer.h"
os_timer_t timer_update_id;
uint8_t flag =0;
uint8_t read_data[128]={0};
uint8_t read_data_W[128]={0};
void timer_update_task(void* vag)
{
co_printf("%s, mem (0x%x)\r\n", func, os_get_free_heap_size());
// ool_write( , );if(flag==0) { flash_read(0x3F000,128,&read_data[0]); co_printf("\r\n Read flash\r\n"); show_reg(read_data,128,1); flag=1; } else if(flag ==1) { flash_erase(0x3F000,0x1000); for(uint8_t i =0;i<128;i++) { read_data[i]=i; } show_reg(read_data,128,1); flag=2; } else if(flag ==2) { flash_write(0x3F000,128,&read_data[0]); flag=3; } else if(flag ==3) { flash_read(0x3F000,128,&read_data_W[0]); co_printf("\r\n read_data_W\r\n"); show_reg(read_data_W,128,1); os_timer_stop(&timer_update_id); }
}
void timer_task_send(uint8_t on_off, uint32_t ms, bool num)
{
#if 1
static uint8_t flag = 1;
if(flag)
{
os_timer_init(&timer_update_id,timer_update_task,NULL);
}
if(on_off)
{
os_timer_start(&timer_update_id,ms,num);
}
else
{
os_timer_stop(&timer_update_id);
}
flag=0;
#endif
}参考一下,写的地址不能写在代码区,A、B区之外,计算A、B区就是image_size*2之后就是用户可以操作的flash