codewarrior HC12,how to impose absolute address in C?

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

Reply to
blisca
Loading thread data ...

On a sunny day (Fri, 29 Dec 2006 13:51:29 +0100) it happened "blisca" wrote in :

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.

Reply to
Jan Panteltje

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).

--

John Devereux
Reply to
John Devereux

On a sunny day (Fri, 29 Dec 2006 13:27:19 +0000) it happened John Devereux wrote in :

Yes that is better, mine was wrong anyways (should have been int address in the function call).

We will have to wait and see ...

Reply to
Jan Panteltje

to

it,

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

Reply to
blisca

This may be helpful:

formatting link

Reply to
Arlet

to

thanks,going to read it immediately

Reply to
blisca

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

Reply to
cs_posting

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

Reply to
OBones

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'

formatting link

Reply to
Arlet

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.

--

John Devereux
Reply to
John Devereux

hc12

in

during

compile

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:

it appears working

I'm learning to work with the 9s12e64 MCU with a self built "scrapedfromthtrash educational board",have fun watching it at

formatting link
as you can see it is cutted with an heavy scissor butcher_style

thanks again

Reply to
blisca

i wrote

instead of >i:e the code starting from 0xC000 and constants say in 0x4000

Reply to
blisca

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

Reply to
cs_posting

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;

--

John Devereux
Reply to
John Devereux

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.

Reply to
cs_posting

the

the

any

well,it encourages me to go on trying

yes i have both,the flash.h-DoOnStack.asm stuff looks smarter than my assembly code that works fine except...

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

it looks as a good way to do the things,thank you for this last suggestion and explanations

Reply to
blisca

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.

Reply to
cs_posting

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

Bye. Jasen

Reply to
jasen

my fault,block size is 512 bytes

!!!!!!!!!better i check my code 3 times more to avoid this,you talk as you tried it on yourself

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?

Reply to
blisca

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.