020-CH32V307(WCH单片机)学习开发-关于warning: 'at' attribute directive ignored, 把数据存储在flash的固定位置
<p><iframe name="ifd" src="https://mnifdv.cn/resource/cnblogs/LearnCH32V307VCT6" frameborder="0" scrolling="auto" width="100%" height="1500"></iframe></p>
1,假设我想把一个变量或者字符串保存在flash的固定位置
经常玩keil的会这样写
char DeviceModel[50] __attribute__((at(0x08000000+1024*2))) = "111111111111111111111111111111111"; //把数据存在flash的0x08000800 位置
编译之后会提示说,at命令被忽略了,所以这条语句没有被执行
2,可以自定义个section
.flash_data :
{
. = ORIGIN(FLASH)+(2*1024);
KEEP(*(SORT_NONE(.flash_data_save_address)))
} >FLASH AT>FLASH
. = ORIGIN(FLASH)+(2*1024);//ORIGIN(FLASH)为 MEMORY定义的FLASH的起始地址(0x00000000),后面增加了2048字节(0x08000800)
KEEP(*(SORT_NONE(.flash_data_save_address))) //flash_data_save_address段使用keep命令来阻止链接器回收所在的 section
修改
char DeviceModel[50] __attribute__((section(".flash_data_save_address"))) = "1111111111111111111111111111111111111";
3,可以让软件生成bin文件看下
riscv-none-embed-objcopy -O binary "${ProjName}.elf" "${ProjName}.bin"
使用FlexHEX或者UltraEdit 打开bin文件