AnsweredAssumed Answered

CW for S12(X). Function in RAM is easy!

Question asked by kef on Sep 12, 2010
Latest reply on Jul 23, 2017 by Byeongjin Kim

I guess not everyone knows how easy it is to move function to RAM using CW for S12(X). I don't know where it is mentioned in the documentation and from which CW version this feature is available, but I was wondering why it is so easy to select where to put XGATE functions, to flash or to RAM. For XGATE, switching to RAM or to ROM is done this way:

 

#pragma push
#pragma CODE_SEG XGATE_CODE_RAM

function_in_RAM()

{

}
#pragma pop

 

#pragma push
#pragma CODE_SEG XGATE_CODE_FLASH

function_in_FLASH()

{

}
#pragma pop

 

I used to think this is possible only for XGATE. But it seems that when linker finds any code allocated in READ_WRITE segments, it puts copy of code in flash and lets standard startup.c copy the code from flash to RAM, like it is done for all initialized variables. So in case we need some S12 flash programming routine in RAM, we can do it this way:

 

#pragma push

#pragma CODE_SEG ramsegment // ramsegment - any segment, but

                                                                 // not predefined one like DEFAULT_RAM, and of course not

                                                                 // a part of paged RAM.

                                                                 // Just add to prm placement section

                                                                 //       ramsegment INTO RAM

foo_in_RAM()

{

}
#pragma pop

 

That's really nice and easy. Far better than RELOCATE_TO and unknown size of function.

 

 

Unfortunately this is not working in CW 6.3 for HC08/S08, linker complains when code is found in R/W segment. Don't know if this is the same in CW 10 for MCUs.

Outcomes