Topic : Compile error using code const

Forum : ARM

Original Post
Post Information Post
July 6, 2011 - 7:31am
Guest

I have a large array (it's actually an image for displaying onto an LCD). Because it is so large I am trying to make sure it stays in flash (at just under 100K, it's almost 1/5 of my flash, so won't fit in RAM anyway). I've defined the array as

code const uint16_t logo40_pixels[LOGO40_WIDTH][LOGO40_HEIGHT] = {{65535, 65535, 65535, 65535, 65535, 65535, 65535,...

I've tried several permutations of this, but it just won't compile and gives me
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'const'
or just hangs and does nothing

I'm sorry if I've done something blatantly wrong, but for the life of me I can't see it.

Replies
Post Information Post
+1
0
-1
July 6, 2011 - 10:05am
Raisonance Support Team

Hi Craig,

This is a classic requirement, although the answer is "this is *not* C". So the reply is compiler-dependent.

First, just having your array as const should be enough for GCC to place it in flash => If this is your case, you are done with this problem.

If you need further control, the "code" qualifier works on some compilers (STM8, 8051 etc), however if you are using RKit-ARM, it is based on the GCC toolchain. In such a case the compiler won't help much: You have to place the array in a specific section (using the __attribute__ keyword) , then fiddle with your .ld linker file to place the section at the proper location (in flash).

Please refer to http://forum.raisonance.com/viewtopic.php?id=3216 for details.

Best Regards,