HCS12 + Fixed address for two functions

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

HCS12 + Fixed address for two functions

444 Views
ssinfod
Contributor IV

Hello, I am using a HCS12DP512 MCU and I have a question regarding the Complier/Linker.

 

I`m trying to allocate two functions to the same specific address.

 

Ideally, it would like to do something like:

void t1(void) @0x9000

{

    putchar('1');

}

 

void t2(void) @0x9000

{

    putchar('2');

}

 

By default, one of the function would be included in my program. Then at run time, the user could send just the S-Record for one of this function with the bootloader in my MCU.

That would be useful when there is not enough room in the FLASH (code page). I could use this feature to have unit testing or debugging function in the field.

 

How can I achieve this with CodeWarrior IDE for HCS12 ?

I know I can create a user segment in the PRM file but It seems the LINKER will place both functions one after the other.

I really want to force these two fonctions at one specifc address.

 

Is that possible ?

 

Thanks in advance for your answer.

ssinfod

Labels (1)
Tags (2)
0 Kudos
1 Reply

251 Views
RadekS
NXP Employee
NXP Employee

I am afraid that I am not fully sure what you want to do with your code.

I suppose that you want call function at address 0x9000.

In default code you will use for example function “t1”.

I suppose that you additionally need compiled code of function “t2”.  This function t2 will be loaded via bootloader. Correct?

I would like to recommend Conditional Assembly Directives:

For example:

//#define CHANGE

void t1(void) @0x9000

{

#ifdef CHANGE

    putchar('2');

#else

    putchar('1');

#endif

}

In first run CHANGE is not defined and t1 contains command putchar('1');.

When you define CHANGE and compile project again, t1 will contains command putchar('2');.

Function t1 stay at the same address, and you can change content of flash by bootloader.

As you already mentioned, I would like to recommend create user segment for this function and size of this segment should be divisble by flash sector size. Code placement:

#pragma CODE_SEG MY_ROM

void t1(void) @0x9000

{

...

}

#pragma CODE_SEG DEFAULT

0 Kudos