Initializing global data in S12X flash

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

Initializing global data in S12X flash

Jump to solution
2,868 Views
dp
Contributor III
CodeWarrior HCS12X 4.5
S12XDP512
Banked memory model
Minimal start-up

In the following example, TestStr and TestInt get initialized as expected. GlobalFlashTestStr and GlobalFlashTestInt do not get initialized but show allocated space in the map and debugger. What am I missing? How do I init data in the global flash space? Thanks.

Simplified code example://----------------------------------------------------------const char TestStr[] = "Test String";const int TestInt = 1234;#pragma DATA_SEG __GPAGE_SEG USRPGM_FLASHconst char GlobalFlashTestStr[] = "Global Flash Test String";const int GlobalFlashTestInt = 5678;#pragma DATA_SEG DEFAULTvoid main(void) {   for(;;) {}}//----------------------------------------------------------From PRM:SEGMENTS...FLASH_G1 = READ_WRITE 0x780000'G TO 0x78FFFF'G; // PAGE_E0 TO PAGE_E3...ENDPLACEMENT...USRPGM_FLASH INTO FLASH_G1;...ENDENTRIESGlobalFlashTestStrGlobalFlashTestIntTestStrTestIntEND//----------------------------------------------------------
Labels (1)
Tags (1)
0 Kudos
1 Solution
511 Views
dp
Contributor III
As you originally intuited, I meant to ask about intitializing data using global addressing in flash. Eventually, the array will exceed 16K. I can live with the access speed penalty. Your answers have provided additional insight regarding syntax and compiler behavior. Thank you all very much.

View solution in original post

0 Kudos
5 Replies
511 Views
CompilerGuru
NXP Employee
NXP Employee
The reason why it does not work for you is because you use READ_WRITE in your prm file. This instructs the linker to initialize this segment via copy down (which does not work as this is flash and you opted not to include the startup code), so use READ_ONLY instead. Also unless you have large objects >= 16k, I would keep on using logical addresses in the prm file, having two kinds of addresses which must not overlap just makes the prm harder to understand. Daniel
0 Kudos
511 Views
CompilerGuru
NXP Employee
NXP Employee
Just noted that the original post contains #pragma DATA_SEG,
that should be #pragma CONST_SEG instead as the objects to be placed
into the globally addressed flash are constants.

So it should look like this:

#pragma CONST_SEG __GPAGE_SEG USRPGM_FLASH
const char GlobalFlashTestStr[] = "Global Flash Test String";
const int GlobalFlashTestInt = 5678;
#pragma CONST_SEG DEFAULT

Daniel


0 Kudos
512 Views
dp
Contributor III
As you originally intuited, I meant to ask about intitializing data using global addressing in flash. Eventually, the array will exceed 16K. I can live with the access speed penalty. Your answers have provided additional insight regarding syntax and compiler behavior. Thank you all very much.
0 Kudos
511 Views
Alban
Senior Contributor II
Hello,

And in term of speed, Global Access cost one additional cycle for Read/Write instructions.
This cycle is on top of the time you spend having to change the Global page (GPAGE Register).

Still, you could declare it in a PAGED area you would declare as READ_ONLY.
And access it via the Global addressing.
You can force the Global addressing to the compiler by using "far".
In the latter, it will not try and use 16-bit.

Alban.
0 Kudos
511 Views
Alban
Senior Contributor II
Euh, re-reading the subject line, there could be a confusing between a variable scope and mode of addressing.

A Global data, as stated in the subject line, can be declared in any file and does not need to be used with a #PRAGMA or any other special way.
You just have to declare it outside a function, basically.

It is totally dissociated from Global addressing and Global space of the microcontroller.
A Global Data can be declared in any location of the memory (RAM, flash and/or EEPROM).

Initializing a Data via Global addressing in flash is different and is what was described previously by both Daniel and me.

Alban.
0 Kudos