[STM32F1] 请教IAR7.801下定义flash中常量失败的原因

[复制链接]
1220|7
 楼主| 海际天涯 发表于 2017-4-23 19:29 | 显示全部楼层 |阅读模式
本帖最后由 海际天涯 于 2017-4-23 20:22 编辑

定义了一个全局常量如下
volatile static const u32 CPUIDEncrypt = 0xFFFFFFFF;
可是调试的时候发现这个常量并没有在flash中,还是在0x20000000的ram中,请教下怎么让他在flash中
1.jpg
pmp 发表于 2017-4-23 22:48 | 显示全部楼层
这个地址定义的在哪了?
pmp 发表于 2017-4-23 22:51 | 显示全部楼层
你的变量定义运行不都是ram吗?没有看懂啥意思。
戈卫东 发表于 2017-4-23 23:05 | 显示全部楼层
可能是volatile 带来的问题。
戈卫东 发表于 2017-4-23 23:09 | 显示全部楼层
Declaring objects volatile and const
If you declare a volatile object const, it will be write-protected but it will still be stored in RAM memory as the C standard specifies.
To store the object in read-only memory instead, but still make it possible to access it as a const volatile object, define the variable like this:
const volatile int x @ "FLASH";The compiler will generate the read/write section FLASH. That section should be placed in ROM and is used for manually initializing the variables when the application starts up.
Thereafter, the initializers can be reflashed with other values at any time.
以上是从IAR的帮助文档复制来的。
戈卫东 发表于 2017-4-23 23:24 | 显示全部楼层
好像不行。。。。。
 楼主| 海际天涯 发表于 2017-4-24 11:38 | 显示全部楼层
戈卫东 发表于 2017-4-23 23:05
可能是volatile 带来的问题。

经实验,你说的正确,取掉就好了
戈卫东 发表于 2017-4-24 18:59 | 显示全部楼层
海际天涯 发表于 2017-4-24 11:38
经实验,你说的正确,取掉就好了

volatile const 跟 const还是不一样的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

55

主题

106

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部