Deciphering LCF and storing CONSTs in flash

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Deciphering LCF and storing CONSTs in flash

Jump to solution
3,006 Views
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)

Labels (1)
0 Kudos
Reply
1 Solution
1,950 Views
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

View solution in original post

0 Kudos
Reply
3 Replies
1,951 Views
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 Kudos
Reply
1,950 Views
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 Kudos
Reply
1,950 Views
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 Kudos
Reply