打印
[STM32F1]

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

[复制链接]
752|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 海际天涯 于 2017-4-23 20:22 编辑

定义了一个全局常量如下
volatile static const u32 CPUIDEncrypt = 0xFFFFFFFF;
可是调试的时候发现这个常量并没有在flash中,还是在0x20000000的ram中,请教下怎么让他在flash中

1.jpg (32.22 KB )

1.jpg
沙发
pmp| | 2017-4-23 22:48 | 只看该作者
这个地址定义的在哪了?

使用特权

评论回复
板凳
pmp| | 2017-4-23 22:51 | 只看该作者
你的变量定义运行不都是ram吗?没有看懂啥意思。

使用特权

评论回复
地板
戈卫东| | 2017-4-23 23:05 | 只看该作者
可能是volatile 带来的问题。

使用特权

评论回复
5
戈卫东| | 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的帮助文档复制来的。

使用特权

评论回复
6
戈卫东| | 2017-4-23 23:24 | 只看该作者
好像不行。。。。。

使用特权

评论回复
7
海际天涯|  楼主 | 2017-4-24 11:38 | 只看该作者
戈卫东 发表于 2017-4-23 23:05
可能是volatile 带来的问题。

经实验,你说的正确,取掉就好了

使用特权

评论回复
8
戈卫东| | 2017-4-24 18:59 | 只看该作者
海际天涯 发表于 2017-4-24 11:38
经实验,你说的正确,取掉就好了

volatile const 跟 const还是不一样的。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

55

主题

105

帖子

1

粉丝