Deciphering LCF and storing CONSTs in flash

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Deciphering LCF and storing CONSTs in flash

跳至解决方案
3,002 次查看
FridgeFreezer
Senior Contributor I

I've been trying to read up about linker command files but there seems to be a lot of stuff out there that contradicts itself or confuses things somewhat by wanting to do more complex things. The targeting manual is less than crystal clear on the subject.

 

Basically I'm looking to store a load of initialised variables, which are constants (an array of strings for example) in flash rather than RAM. I don't need to store them in a specific place, as long as I can reference the array and use the data, eg reference the structure:

messages.[language].[message_hello_world] returns the const string "Hello world"

 

This post seems to suggest that you need to declare a CONST area of flash to make it work, other posts suggest that if you declare something CONST then the compiler will just handle it.

https://community.freescale.com/message/54826#54826

 

Can anyone tell me in simple terms if I can do as some posts seem to suggest and just declare a variable CONST and the compiler will handle it?

 

(Edited to add: This is in CW7.2 for ColdFire MCF52259)

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,946 次查看
Kopone
Contributor IV

I am not sure about CW7.2, but I've done that alot with the CV1 derivates and the compiler/linker would always put my consts in the flash, no need to worry about anything. In fact, it put ALL strings in the flash even were I was not even expecting it. Imagine reserving a string for output where (just for lazyness and saving from sprintf) you wanted to overwrite a byte later, like this:

 

char *result="The result is:x units";

...

result[14] = '0' + resultDigit;

 

Took me a while to figure why my mcu would reset ifself :smileytongue:

This is where the debugger comes in REAL handy, so I'd suggest you just have a look where your pointers are pointing to when you use such a constant. In my case, they were pointing directly into the Flash (the adresses of the regions are in the MCUs Reference Manual).

 

Regards,

 Sven

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,947 次查看
Kopone
Contributor IV

I am not sure about CW7.2, but I've done that alot with the CV1 derivates and the compiler/linker would always put my consts in the flash, no need to worry about anything. In fact, it put ALL strings in the flash even were I was not even expecting it. Imagine reserving a string for output where (just for lazyness and saving from sprintf) you wanted to overwrite a byte later, like this:

 

char *result="The result is:x units";

...

result[14] = '0' + resultDigit;

 

Took me a while to figure why my mcu would reset ifself :smileytongue:

This is where the debugger comes in REAL handy, so I'd suggest you just have a look where your pointers are pointing to when you use such a constant. In my case, they were pointing directly into the Flash (the adresses of the regions are in the MCUs Reference Manual).

 

Regards,

 Sven

0 项奖励
回复
1,946 次查看
FridgeFreezer
Senior Contributor I

Thanks guys, I thought that would be the case but it's very difficult to find anywhere it's explicitly stated.

0 项奖励
回复
1,946 次查看
vier_kuifjes
Senior Contributor I

As far as I know, const data is stored in the rodata section. The location of this section (ROM/RAM) is defined in the LCF file.

0 项奖励
回复