running out of ram (L1102) on MC9S08JM16CGT

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

running out of ram (L1102) on MC9S08JM16CGT

跳至解决方案
1,041 次查看
russianspy1234
Contributor I

So I am having some trouble updating a fairly old program onto this microprocessor.  Basically, what I have is a big list of #defines for some strings and #define integers. then, I have about 80 arrays (const char) ranging in sizes from 1 to 11, that use those #defines integers as well as some other numbers  Then, i have 4 sets of arrays of arrays that hold the previous arrays arranged, and 4 sets of arrays that hold the #defined strings (const char *)  Yes I am aware that this is a very bad way to do it, but I was instructed to maintain the structure of the original code as closely as possible.  All of these declarations are done at the top of my code.  I also have two variables.  Within my code, based on certain conditions, i set one variable to one of the 4 in the first set, and the other to one of the 4 in the second set, and work with it.  Having all 4 conditionals (tried both switch and if) causes me to have an out of ram error, taking 1 of the conditionals (doesnt matter which one) out lets the program compile.

 

In short, i think i just need to know how to make sure my consts are stored in program memory and not ram but i included all info in cases I am missing something else.

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
763 次查看
CompilerGuru
NXP Employee
NXP Employee

Can you show the array definitions? I saw often the past that const is not properly used, especially for array of pointers.

 

E.g. "const char* array[10]=..." is an non constant array with pointers to constant strings. 

To make the array itself const the syntax is "const char* const array[10]=...".

 

Daniel

 

在原帖中查看解决方案

0 项奖励
回复
6 回复数
763 次查看
russianspy1234
Contributor I

The only things that are ending up in .data that shouldn't be are the arrays of arrays.  Everything else is in .rodata.  Whats throwing me off is that having the arrays define is ok, accessing only one works fine, but if I set up a conditional that accesses a specific one (by setting a pointer) I get an error.

0 项奖励
回复
764 次查看
CompilerGuru
NXP Employee
NXP Employee

Can you show the array definitions? I saw often the past that const is not properly used, especially for array of pointers.

 

E.g. "const char* array[10]=..." is an non constant array with pointers to constant strings. 

To make the array itself const the syntax is "const char* const array[10]=...".

 

Daniel

 

0 项奖励
回复
763 次查看
russianspy1234
Contributor I

Yeah that did it, I didn't have the second const in there.  I've never seen that before, I figured having it as an array of literals was enough...  Thank you.

0 项奖励
回复
763 次查看
bigmac
Specialist III

Hello,

 

You can check the project.map file generated by the linker, to see how the RAM is being allocated.  There is a section within the file that lists all RAM and flash memory usage in address sequence.

 

Note that page 0 RAM usually needs to be explicitly allocated using the appropriate #pragma, otherwise it will not be utilised.

 

Regards,

Mac

 

0 项奖励
回复
763 次查看
russianspy1234
Contributor I

looks like a bunch of the constants i expected to go into text are instead going into data or rodata/rodata1.  Gonna look into #pragma to change that, so far I've only ever used that for vectors.

0 项奖励
回复
763 次查看
bigmac
Specialist III

Hello,

 

I would have considered .rodata an appropriate flash memory location for your constant data.  Your problem would seem to concern the allocation of read_write memory (0x00B0 to 0x04AF).

 

Regards,

Mac

 

0 项奖励
回复