Hello,
I am trying to store several calibration values/tables into ROM at fixed addresses. I am using CodeWarrior on a 9S12P MCU. Right now, I am capable of defined addressing for individual constants as follows:
#pragma CONST_SEG PAGE_0C
volatile const UINT16 CalParameterA @ 0xC9000 = 1458;
#pragma CODE_SEG DEFAULT
This works just as I intend. However, with a bunch of constants, I want to add another definition where the location is sequentially located right behind the previous declaration. Some definition like:
#pragma CONST_SEG PAGE_0C
volatile const UINT16 CalParameterA @ 0xC9000 = 1458;
volatile const UINT16 CalParameterB = 6533;
volatile const UINT16 CalParameterC = 12;
#pragma CODE_SEG DEFAULT
Where the addressing would be:
CalParameterA 0xC9000
CalParameterB 0xC9002
CalParameterC 0xC9004
How can I best achieve this?
Hi Robert,
You tried to allocate three variables to 0xC9000-0xC9004 .
However with your code, I don’t think this can work.
There are two solutions:
Solution 1:
volatile const UINT16 CalParameterA @ 0xC9000 = 1458;
volatile const UINT16 CalParameterB @ 0xC9002 = 6533;
volatile const UINT16 CalParameterC @ 0xC9004 = 12;
You don’t need put above code under #pragma CONST_SEG PAGE_0C. Because you already use @ defining variables to specific address, there is no sense to put it under PAGE_0C segment.
Solution 2:
In prm, define a section from 0xC9000
PAGE_0C_9000 = READ_ONLY 0x0C9000 TO 0x0C93FF;
...
USER_CONST_C9000 INTO PAGE_ PAGE_0C_9000;
In C code,
#pragma CONST_SEG USER_CONST_C9000
volatile const UINT16 CalParameterA = 1458;
volatile const UINT16 CalParameterB = 6533;
volatile const UINT16 CalParameterC = 12;
#pragma CODE_SEG DEFAULT
Hope this helps.
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thank you. That was very helpful. As a follow up question: how do I keep space allocated in ROM if it is defined, but not used in an application? The order of each constant is critical.
Hi Robert.
To allocate unused global variable to memory, we need add the object in ENTRIES section in prm file
Example:
thus "global_val" will not being optimized out.
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------