Maker Pro
Maker Pro

codewarrior HC12,how to impose absolute address in C?

B

blisca

Jan 1, 1970
0
Hi to all
Does anyone know how ,in C language,to impose that a costant be assigned to
a prefixed flash location overriding the linker?

i mean someting analog to the ORG directive in assembler

thank you and Happy new year
Diego
 
J

Jan Panteltje

Jan 1, 1970
0
Hi to all
Does anyone know how ,in C language,to impose that a costant be assigned to
a prefixed flash location overriding the linker?

i mean someting analog to the ORG directive in assembler

thank you and Happy new year
Diego

Has been too long since I used HC1X micros.
But in C you can normally use a pointer:

void poke(char *address, char data)
{
unsigned char *my_pointer;

my_pointer = address;

*my_pointer = data;

return;
}

You have to make sure you got bit width right, if your compiler supports it,
(gcc), for example:

uint16_t *my_pointer; // if 16 bit address
unit8_t data; // if 8 bits data



Or something like that.
 
J

John Devereux

Jan 1, 1970
0
Jan Panteltje said:
Has been too long since I used HC1X micros.
But in C you can normally use a pointer:

void poke(char *address, char data)
{
unsigned char *my_pointer;

my_pointer = address;

*my_pointer = data;

return;
}

You have to make sure you got bit width right, if your compiler supports it,
(gcc), for example:

uint16_t *my_pointer; // if 16 bit address
unit8_t data; // if 8 bits data



Or something like that.

Or just

void poke(unsigned char * address, unsigned char data)
{
*address = data;
}

or

*((unsigned char*)0xf000) = 123;

(Although I am not sure that is quite what the OP was asking for).
 
J

Jan Panteltje

Jan 1, 1970
0
Or just

void poke(unsigned char * address, unsigned char data)
{
*address = data;
}

or

*((unsigned char*)0xf000) = 123;

Yes that is better, mine was wrong anyways (should have been int address in the function call).
(Although I am not sure that is quite what the OP was asking for).

We will have to wait and see ...
 
B

blisca

Jan 1, 1970
0
Hi to all
Does anyone know how ,in C language,to impose that a costant be assigned to
a prefixed flash location overriding the linker?

i mean someting analog to the ORG directive in assembler
thank you and Happy new year
Diego
Has been too long since I used HC1X micros.
But in C you can normally use a pointer:
void poke(char *address, char data)
{
unsigned char *my_pointer;
my_pointer = address;

*my_pointer = data;
return;
}
You have to make sure you got bit width right, if your compiler supports it,
(gcc), for example:

uint16_t *my_pointer; // if 16 bit address
unit8_t data; // if 8 bits data
Or something like that.[/QUOTE]
Or just

void poke(unsigned char * address, unsigned char data)
{
*address = data;
}
or
*((unsigned char*)0xf000) = 123;

(Although I am not sure that is quite what the OP was asking for).[/QUOTE]
John Devereux

Thanks but the problem is that i'm compiling for a microprocessor of hc12
family,the 9s12e64,and is not so easy to change te value of the location in
the flash at run time,
as you know you have to erase and re-write a whole flash block,and during
this time the program has to be copied somewhere in RAM,because the MCU
can't read instructions from the flash
during flash manipulation.
Talking about a constant it is easier to declare it in the flash at compile
time,but the linker decides where to put it.
I would be able to set the constant in an absolute location,i.e. 0x4500
Thank you again
 
blisca said:
Hi to all
Does anyone know how ,in C language,to impose that a costant be assigned to
a prefixed flash location overriding the linker?

i mean someting analog to the ORG directive in assembler

For the HCS12/codewarrior,

Use @address after the declaration, like this:

const volatile short mychunkofdata[] @0xF800 = { 0x1EFC, 0x2202 , etc }

You could also define a data segment with the .prm file

and of course check the .map file to see that you got what you actually
wanted
 
O

OBones

Jan 1, 1970
0
blisca said:
Hi to all
Does anyone know how ,in C language,to impose that a costant be assigned to
a prefixed flash location overriding the linker?

i mean someting analog to the ORG directive in assembler


For the HCS12/codewarrior,

Use @address after the declaration, like this:

const volatile short mychunkofdata[] @0xF800 = { 0x1EFC, 0x2202 , etc }

Out of curiosity, why volatile if it's const?
 
A

Arlet

Jan 1, 1970
0
OBones said:
blisca said:
Hi to all
Does anyone know how ,in C language,to impose that a costant be assigned to
a prefixed flash location overriding the linker?

i mean someting analog to the ORG directive in assembler


For the HCS12/codewarrior,

Use @address after the declaration, like this:

const volatile short mychunkofdata[] @0xF800 = { 0x1EFC, 0x2202 , etc }

Out of curiosity, why volatile if it's const?

const only means that the code may not modify the value, not that it
never changes. A read-only hardware register could be declared 'const
volatile'

http://publications.gbdirect.co.uk/c_book/chapter8/const_and_volatile.html
 
J

John Devereux

Jan 1, 1970
0
blisca said:
Thanks but the problem is that i'm compiling for a microprocessor of hc12
family,the 9s12e64,and is not so easy to change te value of the location in
the flash at run time,
as you know you have to erase and re-write a whole flash block,and during
this time the program has to be copied somewhere in RAM,because the MCU
can't read instructions from the flash
during flash manipulation.
Talking about a constant it is easier to declare it in the flash at compile
time,but the linker decides where to put it.
I would be able to set the constant in an absolute location,i.e. 0x4500
Thank you again


So you want to have location 0x4500 contain a particular constant
value? I think you will have to do this outside of the C program,
unless your dialect of C has special extensions to do this.

As you say, the linker decides where to put it. So the general
approach would be to have an assembly language file that defines the
constant, in its own section. Then you need to modify the linker
script to place this section at the address you want. The details will
depend on the tools you use.

Why do you want to do this? It does not make much sense to me.
 
B

blisca

Jan 1, 1970
0
John Devereux said:
So you want to have location 0x4500 contain a particular constant
value? I think you will have to do this outside of the C program,
unless your dialect of C has special extensions to do this.

As you say, the linker decides where to put it. So the general
approach would be to have an assembly language file that defines the
constant, in its own section. Then you need to modify the linker
script to place this section at the address you want. The details will
depend on the tools you use.

Why do you want to do this? It does not make much sense to me.

The reason is :
i'm experimenting about storing costants,that can be updated run-time in the
flash,because there is no EEPROM in this MCU
i would like to be shure that i dont'affect other data,of course when the
firmware will be at good point i will assure to save and re-write al the
data in the same block
By now i feel better having the code in area very far from this flash
constants,i:e the code starting from 0xC000 and variables say in 0x4000
i'm not absolutely shure that i'm doing the smartest thing,so thanks for any
hint

Following the example in the answer of cs_posting:
Use @address after the declaration, like this:
const volatile short mychunkofdata[] @0xF800 = { 0x1EFC, 0x2202 , etc }

it appears working


I'm learning to work with the 9s12e64 MCU with a self built
"scrapedfromthtrash educational board",have fun watching it at
http://img165.imageshack.us/my.php?image=image003xs4.jpg
as you can see it is cutted with an heavy scissor butcher_style

thanks again
 
So you want to have location 0x4500 contain a particular constant
value? I think you will have to do this outside of the C program,
unless your dialect of C has special extensions to do this.

It (codewarrior for HCS12) does. Use @address after the declaration
 
J

John Devereux

Jan 1, 1970
0
blisca said:
John Devereux said:
Why do you want to do this? It does not make much sense to me.

The reason is :
i'm experimenting about storing costants,that can be updated run-time in the
flash,because there is no EEPROM in this MCU
i would like to be shure that i dont'affect other data,of course when the
firmware will be at good point i will assure to save and re-write al the
data in the same block
By now i feel better having the code in area very far from this flash
constants,i:e the code starting from 0xC000 and variables say in 0x4000
i'm not absolutely shure that i'm doing the smartest thing,so thanks for any
hint

Following the example in the answer of cs_posting:
Use @address after the declaration, like this:
const volatile short mychunkofdata[] @0xF800 = { 0x1EFC, 0x2202 , etc }

it appears working


OK, I see now.

It looks like you have solved your problem, but you could try
something like this too (untested):


struct set
{
long test_number;
unsigned test_time;
long CycleCount;
long hwRevision;
long hwOptions;
int repeat_period;
/* etc... */
};


struct set* s = (struct set*)0xf800;

/* ... */

unsigned test_time = s->test_time;
 
blisca said:
The reason is :
i'm experimenting about storing costants,that can be updated run-time in the
flash,because there is no EEPROM in this MCU
i would like to be shure that i dont'affect other data,of course when the
firmware will be at good point i will assure to save and re-write al the
data in the same block
By now i feel better having the code in area very far from this flash
constants,i:e the code starting from 0xC000 and variables say in 0x4000
i'm not absolutely shure that i'm doing the smartest thing,so thanks for any
hint

Sounds good to me.

I assume you got the app note and the code for programming the flash -
the "do on stack" thing or wrote your own.

As long as you keep the flash sector size - 0x200 bytes if I recall -
in mind you should be fine.

Just set up your .prm file to put you code in a safe place.

I actually keep two entirely seperate projects/programs in the flash -
one is a small tool that allows me to upload and reflash the other,
which is the main application. The .prm files keep them out of
conlict, and the upload-accepter will refuse to erase the flash areas
where it resides.
 
B

blisca

Jan 1, 1970
0
Sounds good to me.
well,it encourages me to go on trying
I assume you got the app note and the code for programming the flash -
the "do on stack" thing or wrote your own.

yes i have both,the flash.h-DoOnStack.asm stuff looks smarter than my
assembly code that works fine except...
As long as you keep the flash sector size - 0x200 bytes if I recall -
in mind you should be fine.

except for the fact that it looks erasing 1024 bytes at time,but i guess
that is how the 9s12e64 flash works

Just set up your .prm file to put you code in a safe place.

I actually keep two entirely seperate projects/programs in the flash -
one is a small tool that allows me to upload and reflash the other,
which is the main application. The .prm files keep them out of
conlict, and the upload-accepter will refuse to erase the flash areas
where it resides.


it looks as a good way to do the things,thank you for this last suggestion
and explanations
 
blisca said:
except for the fact that it looks erasing 1024 bytes at time,but i guess
that is how the 9s12e64 flash works

I could have the size wrong - it's from memory and could be different
on different members of the HCS12 family. I believe the flash is often
16 bit word oriented on these too - so you erase the big blocks, and
write words. Though i suppose you can write bytes if you really want
to, putting ff in the byte you don't want to touch.

Oh, and do have care to program the security word immediately if you
erase the block containing the interrupt vectors. If you don't, you
won't be able to access the chip with the BDM pod via the codewarrior
tools, and will instead have to download something like P&E unsecure to
unbrick it.

Lastly, if you go running around modifying memory, hiwave may or may
not show your changes. I think it is more likely to reflect changed
data in its memory dump - change the code and you will confuse it
severely! I really try to load the code with the BDM pod if I will be
debugging it.
 
J

jasen

Jan 1, 1970
0
Out of curiosity, why volatile if it's const?

const means you can't change it, volatile means someone else can.

Bye.
Jasen
 
B

blisca

Jan 1, 1970
0
my fault,block size is 512 bytes
I could have the size wrong - it's from memory and could be different
on different members of the HCS12 family. I believe the flash is often
16 bit word oriented on these too - so you erase the big blocks, and
write words. Though i suppose you can write bytes if you really want
to, putting ff in the byte you don't want to touch.

Oh, and do have care to program the security word immediately if you
erase the block containing the interrupt vectors. If you don't, you
won't be able to access the chip with the BDM pod via the codewarrior
tools, and will instead have to download something like P&E unsecure to
unbrick it.
!!!!!!!!!better i check my code 3 times more to avoid this,you talk as you
tried it on yourself
Lastly, if you go running around modifying memory, hiwave may or may
not show your changes. I think it is more likely to reflect changed
data in its memory dump - change the code and you will confuse it
severely! I really try to load the code with the BDM pod if I will be
debugging it.

ok,many thanks

PS do you know if is possiblo to use the area between 0x8000 and 0xC000 as
a linear space using the small model?
 

Similar threads

Top