Problem with MC9S08QG8 RAM

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

Problem with MC9S08QG8 RAM

Jump to solution
4,416 Views
neocronos
Contributor III
Hello,

I have a couple of global structures into the MC9S08QG8 RAM (512 bytes). At some function I use atoi() and then itoa() but one of the structures is being somehow rewritten inside of the atoi(). How can I avoid this?

By the way, if anyone knows how could I get some help in this thread I'd appreciate it:

http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&message.id=11140#M11140

Thanks
Labels (1)
0 Kudos
1 Solution
1,708 Views
bigmac
Specialist III
Hello,
 
I suspect that your stack usage is over-writing the global structure in question.  With only 512 bytes of RAM available it may not be possible for you to increase the size of the stack allocation, depending on the size of your structures.
 
Examine the map file for the project, and make sure that the top-of-stack is at the highest RAM address, and that the global variables commence at the lowest RAM address (within zero page).  This will allow the widest separation between the global variables and the stack.  You might need to modify the PRM file to achieve this.
 
Regards,
Mac
 

View solution in original post

0 Kudos
18 Replies
1,708 Views
neocronos
Contributor III
Hi again, one more question :smileyhappy:

Each time I close the project and open it again (with saved and compiled btw), it changes the .prm for the original one. I've tried modifying it, replacing it, deleting it and adding it ... but nothing seems to work. How can I use the modified one permanently?

Thanks
0 Kudos
1,708 Views
CrasyCat
Specialist III
Hello
 
Did you activate ProcessorExpert in your project?
 
CrasyCat
0 Kudos
1,708 Views
neocronos
Contributor III
Yes, I'm using Processor Expert.
0 Kudos
1,708 Views
CrasyCat
Specialist III
Hello
 
Look at that thread.
You need to set  "Generate prm file" to NO in the CPU Bean Build Options.
 
CrasyCat
0 Kudos
1,708 Views
neocronos
Contributor III
Thanks :smileyhappy:
0 Kudos
1,708 Views
neocronos
Contributor III
Awesome, thanks a lot for the help. :smileyhappy: I'll check it out a bit later.

Hey any thought of who could help me with this?:

http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&message.id=11140#M11140
0 Kudos
1,708 Views
allawtterb
Contributor IV
If you are still tight on memory space after the suggestions by bigmac and Eckhard, you might consider writing your own functions to do atoi and itoa.  You might be able to make something that better fits your application for memory efficency.  
0 Kudos
1,708 Views
JimDon
Senior Contributor III
Please explain how re-writing atoi and itoa is going to save RAM space.

0 Kudos
1,708 Views
bigmac
Specialist III
Hello,
 
The attached PRM file for the QG8 should produce a more suitable RAM allocation than the default PRM file created by the project wizard.  The global variables will first be allocated to Z_RAM, and then to RAM.  The stack is allocated to its own segment at the top of RAM.
 
Regards,
Mac
 
0 Kudos
1,708 Views
neocronos
Contributor III
Thanks a lot. It worked just fine. I have a couple of doubts if anyone could answer them please:

At the PRM that Big attached there was this line:

VECTOR 0        _Startup

But the compiler said "L1119 Vector allocated at absolute address 0xFFFE overlaps with sections placed in segment .absSeg78" (by the way, how can I copy errors to the clipboard?)". So I used the one it had before:

INIT        _EntryPoint

And it worked. What does it mean?

I have to say here that I'm still a student and I have plenty of knowledge to learn, for example, I have had this doubt of what is the difference btw using // and /* */ for one single code line?. // Seems faster but I've seen people rather /* */

And also, does someone know who is UK_CF_FAE? He was the only who answered here:

http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&message.id=11140#M11140

Does anyone know who could help me with ZigBee issues? like the one that is at that link?

Thanks again and sorry for bringing newbie questions :smileyhappy:
0 Kudos
1,708 Views
JimDon
Senior Contributor III
/**/ vs //

One issue is that MIRSA, a set of "C" coding standards for the automotive industry, forbids the use of //.
So, if you have ever had to write code that conforms to MIRSA, you get in habit of not using //.

I am not saying there is anything wrong with using // and in other programming contexts I prefer them.


0 Kudos
1,708 Views
fabio
Contributor IV
Hi,

Some more tips you could use:

Looking at the project's map file you'll be able to grab some useful information. At the "OBJECT-ALLOCATION SECTION" you will find the absolute address, size and number of references to all symbols used by your application.

Locate the variable with the highest address: this one is the most likely to be written by undesired stack overflow conditions. You can start a debug section and monitor the state of this variable. Any unexpected change may be a symptom of a stack overflow.

You can instruct the linker to use the direct page with a small adjustment in the project's PRM file:

In the PLACEMENT section, just add the the Z-RAM segment into the placement of the DEFAULT_RAM. Something like this: DEFAULT_RAM  INTO RAM, Z_RAM;

You can also manually place variables with high number of references into the direct page by using:

Code:
#pragma DATA_SEG __SHORT_SEG MY_ZEROPAGEunsigned near char my_direct_char_variable;
unsigned near int my_direct_int_variable;
#pragma DATA_SEG DEFAULT

 Note that placing variables into direct page like this has a major advantage (considering you are using the small memory model): the code size is reduced because direct page variables consume less FLASH as the instructions using direct addressing mode are 1 byte shorter then those using extended addressing mode.

#MARKETING ON
You could also take a look at this book: HCS08 Unleashed . It has many examples and could be useful :smileywink:
#MARKETING OFF

Best regards,

0 Kudos
1,708 Views
allawtterb
Contributor IV


neocronos wrote:
And also, does someone know who is UK_CF_FAE? He was the only who answered here:

http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&message.id=11140#M11140

Does anyone know who could help me with ZigBee issues? like the one that is at that link?

Thanks again and sorry for bringing newbie questions :smileyhappy:


I don't know who UK_CF_FAE but I would guess he might be a Fields Application Engineer for the Coldfire and is located in the United Kingdom :smileywink:  Your best bet to getting help with anything Zigbee related would be to get a hold of Mads, perhaps send him a private message with a link to your post.
0 Kudos
1,708 Views
bigmac
Specialist III
Hello,


neocronos wrote:

I have had this doubt of what is the difference btw using // and /* */ for one single code line?. // Seems faster but I've seen people rather /* */


The second method of making a comment was the one originally defined for C, whereas the first method was introduced for C++, in addition to the other metnod.  Code Warrior supports either method.  Some programmers habitually use the original method because it will work for any compiler.
 
Another difference is that the original method can be applied to multiple line blocks, whereas the C++ method is applicable only to the current line.
Regards,
Mac
 
0 Kudos
1,708 Views
JimDon
Senior Contributor III
There are many ways to define the entry point of the program.
It just means the you defined it twice. Mac did not know that it was also defined elsewhere. Both ways work.
L1119 basically means that you have tried to put something in memory twice.

As for your ZigBee question, I am personally not experienced with ZigBee, but perhaps the question is not clear to those who are and that is why you have not got an answer.


Also, when you put a URL into a post, if you use the icon with the globe an the chain link on it to make a a link, other can just click the link and are more likely to follow it. The way you did it, you have to copy and paste into a new browser window.

0 Kudos
1,708 Views
allawtterb
Contributor IV


JimDon wrote:
Please explain how re-writing atoi and itoa is going to save RAM space.




I have not taken a look at the atoi or itoa functions but it is possible it could reduce the stack requirements of the functions.  I don't know how tight of rope the neocronos is walking with his RAM useage but it be enough to be worth his while.  
0 Kudos
1,709 Views
bigmac
Specialist III
Hello,
 
I suspect that your stack usage is over-writing the global structure in question.  With only 512 bytes of RAM available it may not be possible for you to increase the size of the stack allocation, depending on the size of your structures.
 
Examine the map file for the project, and make sure that the top-of-stack is at the highest RAM address, and that the global variables commence at the lowest RAM address (within zero page).  This will allow the widest separation between the global variables and the stack.  You might need to modify the PRM file to achieve this.
 
Regards,
Mac
 
0 Kudos
1,707 Views
eckhard
Contributor V
Hello,

by default codewarrior sets the Stackpointer not on the top of RAM stack is just above the global Variables ind is as Big as definded with STACKSIZE in the .prm linker file. You can increase the Stacksize ore use the Stacktop option. By default the Zeropage is not used, maybe you should put your structures there to have more RAM for the Stack.

Putting variables into the zeropage works like this :

#pragma DATA_SEG __SHORT_SEG MY_ZEROPAGE
/*Page 0 data declarations go here*/
#pragma DATA_SEG DEFAULT


Eckhard
0 Kudos