Declare constant in ROM

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

Declare constant in ROM

721 Views
brunolalb
Contributor I

Hi,
I'm working in a project with a MC56F8006 and an OLED Display, so I have to allocate about 1 KB of "screens" for my display. I'm trying to allocate this 1 KB in internal flash memory, because they won't be changed ever (they are constants). I'm currently declaring it as "static const UWord8 screenN[] = { lots of bytes};", but it seems to be occupying the RAM segment, since I ran out of RAM, even though I have only about 500 bytes of variables.


I found some people saying to declare the screens as "__pmem static UWord8 screenN[] = { lots of bytes };" and use level 4 optimizations. It made my code compile, but got several warnings regarding the linker command file, for example: "F_Pbss_start_addr defined in the Linker Command File is not word-aligned, address in bytes is 7609."

 

I don't know what else to do. I searched everything and still haven't got a straight answer. How do I declare a array of bytes in flash memory so it doesn't occupy my RAM memory?

 

Regards,
Bruno

Labels (1)
Tags (1)
0 Kudos
2 Replies

324 Views
willihoffmann
Contributor I

It's quite an old post, so I think the problem should have been solved now, but for anyone else having this error and not knowing where the problem is: if you are using byte-arrays, make sure to have an even amount of bytes, so you don't break word alignment.

0 Kudos

324 Views
giacomopetrini
Contributor IV

Hi,

 

In a project I just declared this:

__pmem const UInt8 CRC8_table[256] = {//lot of bytes};

 

and work correctly. (the const is not mandatory I think). 

 

Try to compile with "Level 2 optimization" or less. I've found out that sometimes compiling with Level 3 or above gives some strange result when using variables in program memory.

 

By the way you should check the "Targeting 56800E" pdf, it gives some insight on how to use the __pmem command and what are the limitation on putting data in program memory.

 

You can also try the "Pool Strings" and "Reuse Strings" checkbox in Language Settings (In theTarget Settings Panel), they can maybe shrink the memory footprint of the strings...

 

Hope this helps

 

Bye Giacomo

0 Kudos