Deciphering LCF and storing CONSTs in flash

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Deciphering LCF and storing CONSTs in flash

ソリューションへジャンプ
2,997件の閲覧回数
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,941件の閲覧回数
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,942件の閲覧回数
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,941件の閲覧回数
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,941件の閲覧回数
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 件の賞賛
返信