CONST in banked Memory.

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

CONST in banked Memory.

5,258 Views
hdan
Contributor III
hello,
I work on a s12DG256 with CW 3.1 and SofTec inDart.

I want to put my const in banked memory.

I do this :

#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"

int nCar=12;

#pragma CONST_SEG __PPAGE_SEG CONST_USER

const far int tada0=0x6655;
const far unsigned char Array[10] = {0xB9, 0xED};

#pragma CONST_SEG DEFAULT


void main(void) {

if (nCar > tada0) nCar = tada0 + Array[0];

for(;:smileywink: {} /* wait forever */
}


In map file (SofTec.map)I found :

*********************************************
SECTION-ALLOCATION SECTION
Section Name Size Type From To Segment
-------------------------------------------------
.init 69 R 0xC000 0xC044 ROM_C000
.startData 31 R 0xC045 0xC063 ROM_C000
NON_BANKED 14 R 0xC064 0xC071 ROM_C000
.copy 8 R 0xC072 0xC079 ROM_C000
.text 25 R 0x308000 0x308018 PAGE_30
CONST_USER 10 R 0x398000 0x398009 PAGE_39
.data 2 R/W 0x1000 0x1001 RAM


quite good my array is in the right place but ...

NOT USED VARIABLES
main.c.o:
tada0

tada0 is not in CONST_SEG !

I look to compiler option

-Cc -CpPPAGE=RUNTIME -D_HCS12 -D__NO_FLOAT__ -Lp=%n.pre -Mb -Onca -OnCstVa

-OnCstVar is check ( disable const variable by const replacement )


What can i do? where is my mistake? I turn in round on this question for a long time...

thanks,
Labels (1)
Tags (1)
0 Kudos
Reply
12 Replies

1,664 Views
hdan
Contributor III
hello,

I really need to put these data in specified Page.

my application is an industrial controler. There is two part of program:
- first part is the "core program" all the industrial controler have this program.
- second part is the "user program" specific to the machine.

the second part is recorded in EEPROM and can change with the evolution of the machine.

I have a lot of const, array and some code to put in 2 banked memories.

you say :
- make it volatile
- update the compiler, (not sure if this is an option)
- change the code so the compiler only sees an extern declaration of tada0, and not the definition.

- make it volatile : i can't store a volatile in banked memory (R/W needed)
- update the compiler (realy update or buy a new one ?)
- change the code... could you explain me I try to declare with extern but it do the same (i think i haven't understood)

thanks for all...
hdan
0 Kudos
Reply

1,664 Views
CompilerGuru
NXP Employee
NXP Employee
- make it volatile : i can't store a volatile in banked memory (R/W needed)
Why not?
Volatile means that accessing the variable has side effects, so the compiler has to perform every access and is not allowed to optimize them away. That is completely independent of const. const means it cannot be written. A variable can be const and volatile at once, for example a read only real time counter could be declared naturally as volatile const.

- update the compiler (realy update or buy a new one ?)
Well, could be buy one. But I don't know the details there.

- change the code... could you explain me I try to declare with extern but it do the same (i think i haven't understood)
If the compiler does not see the actual initialization value when it compiles the code, it wont do any constant folding.
e.g.
a.h:
#pragma CONST_SEG __PPAGE_SEG CONST_USER
extern const int tada0;
#pragma CONST_SEG DEFAULT

a.c:
#include "a.h"
#pragma CONST_SEG __PPAGE_SEG CONST_USER
const int tada0=0x12345;
#pragma CONST_SEG DEFAULT

b.c:
#include "a.h"
int useTada(void) {
    return tada0;
}

Actually it's sufficient if the compiler definition of the code using the constant is before the definition of the constant (but after a declaration of the constant, of course), it can be in the same file. I did just split the parts up into several files to be even more explicit.

Daniel
   

0 Kudos
Reply

1,664 Views
hdan
Contributor III
hello,

That's solve my problem.

I already use extern definition. I move the link order and be careful with all mu declaration and it 's good now.

Thanks.

( I never use volatile const before I still to think it's curious but why not :smileyhappy:
0 Kudos
Reply

1,664 Views
hdan
Contributor III
Hello,

I claim victory too early! 8-(

I have two problem:

the first :

The array of string are partially in low ROM :
in .h :
extern const char *__far MessageDef [];

in .c :
const char *__far MessageDef [lgMessageDef]=
{
"",
"password",
...................
"",
};

and in the .map i fund :
------- ROM-ADDRESS: 0xEA00 ---- RAM-ADDRESS: 0x1D2A ---- SIZE 300 ---
Name of initialized Object : MessageDef
38823F3882 4038824D38 8260388273
3882863882 8738828838 828938828A
38828B3882 8C38828D38 828E38828F.........

the string are allready in my banked rom but how to put that in the banked rom too ?

and my second problem look the same it's with arrays like :

in .h :
extern unsigned int* tSL[];

in .c :
unsigned int* tSL[32]=
{
&C1,
NULL,
....
}

------- ROM-ADDRESS: 0xE8C3 ---- RAM-ADDRESS: 0x1BB4 ---- SIZE 2 ---
Name of initialized Object : tSL
204E

the needing is the same... I need to have nothing of this part of my program in the ROM (only in the chosen two banked rom).

Someone have an idea or have done the same in the past?

hdan.
0 Kudos
Reply

1,664 Views
CompilerGuru
NXP Employee
NXP Employee
Note that with
>extern const char *__far MessageDef [];
MessageDef is not a constant. It's a variable which can be changed, it only happens to contain pointer pointing to non modifyable characters.
Use
extern const char * const __far MessageDef [];
instead.
(both declarations and definitions, of course)

Note too that the map file snippet you copied shows how the MessageDef  variable gets initialized.
Just checking the MessageDef  entry itself is probably simpler :smileyhappy:

about the tSL, well this is clearly a variable (and not a constant). You want to place it into banked flash? Is it constant?
If so, use "extern unsigned int* const tSL[];"

Daniel


0 Kudos
Reply

1,664 Views
hdan
Contributor III
Hello,

I find a solution for the const, i use struct like this:
struct sStrTab
{
const char *__far strDat;
};

extern const struct sStrTab MessageDef [];

it do the same and it's ok.

More difficult with variable, i understand why they appear in ROM, these variables are initialized. Their initializations are in ROM. How to put them in banked rom ?

hdan,
0 Kudos
Reply

1,664 Views
CompilerGuru
NXP Employee
NXP Employee
The problem with
const char *__far strDat;

is that strDat is NOT const.
code like
strDat= 0;
compiles just fine. This declaration states that strDat is a pointer to a constant string, so
strDat[2]= 'a';
for example does not compile, but the pointer itself can be changed to point to other strings instead.
If you want strDat to be in ROM/Flash, use
char *__far const strDat;
or
const char *__far const strDat;

About your variable question, sorry, I dont understand the question. Variables are changeable, so they don't apear in ROM (hopefully). Values used to initialize them initially may appear in ROM tough, that's what you saw in a previous post.


0 Kudos
Reply

1,664 Views
hdan
Contributor III
Hello,

For the variable, of course they are not in ROM, but their initialization yes.
if you write:

int a= 10;

10 is writed in ROM.

I found a "solution", i write:

const int tmp = 10;
int a = tmp;

with the const in the right page.

I suppose a better solution exist but that solve my problem.

Thanks,
0 Kudos
Reply

1,664 Views
CrasyCat
Specialist III
Hello
 
So you are looking for a way to put initialization values ( so called copy down information) in banked memory.
 
This is possible only for HCS12X or HCS12XE and with cw for hcs12 V4.6 (as far as I know).
 
You need to
  - edit the file start12.c
  - In that file you should see:
/*#define __BANKED_COPY_DOWN : allow to allocate .copy in flash area */
  - remove the comment in front of the line. Change it to
   #define __BANKED_COPY_DOWN /*: allow to allocate .copy in flash area */
  - rebuild the application.
 
This should be it.
But remember this is only working for HCS12X or HCS12XE.
It will not work for HCS12 or HC12.
 
CrasyCat
0 Kudos
Reply

1,664 Views
CompilerGuru
NXP Employee
NXP Employee
The subject looks a bit off topic as the problem is the constant replacement and has nothing to do with banked memory.
Anyway, the second time today that I write this is a known bug, this time its actually a bug fixed quite some time ago, since HC12 V4.0, below the snippet out of the release notes.

If you really must not have the constant folding taking place you could
- make it volatile
- update the compiler, (not sure if this is an option)
- change the code so the compiler only sees an extern declaration of tada0, and not the definition.

In the end, why is the constant folding actually a problem? This is obviously a simplified sample, but I wonder why the folding should not take place.

Daniel


List of fixed Bugs since HCS12X V4.0 rc
..  
- WB1-51395: constants were replaces although option -OnCstVar was specified


0 Kudos
Reply

1,664 Views
hdan
Contributor III
Hello,

thanks for your quick response.

How to upgrade my compiler ? I'm quite affraid to make a mistake. Is there a document who explain that?

hdan.
0 Kudos
Reply

1,664 Views
CrasyCat
Specialist III
Hello
 
If you want to link the constant tada0 to your application even though it is not used, you can
disable smart linking for that variable in the linker .prm file.
 
Just add following line to the .prm file:
ENTRIES
  tada0
END
 
CrasyCat
0 Kudos
Reply