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.
已解决! 转到解答。
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.
Update.
Indeed the same easy-code-in-RAM approach works also for S08 and CW for MCUs v6.3. You only need to go to linker options and check the "Never check section qualifier compatibility" on "Output" page. Or add -NoSectCompat to linker command line.
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.
Update.
Indeed the same easy-code-in-RAM approach works also for S08 and CW for MCUs v6.3. You only need to go to linker options and check the "Never check section qualifier compatibility" on "Output" page. Or add -NoSectCompat to linker command line.
Is the following method correct?
example)
ProcessorExpert.prm
- file1.h
#pragma push
#pragma CODE_SEG ToCopyToRAM
void Test1(void);
#pragma CODE_SEG DEFAULT
#pragma pop
- file1.c
#pragma push
#pragma CODE_SEG ToCopyToRAM
void Test1(void)
{
//-----------test code------------------//
}
#pragma CODE_SEG DEFAULT
#pragma pop
- file2.h
#pragma push
#pragma CODE_SEG ToCopyToRAM
void Test2(void);
#pragma CODE_SEG DEFAULT
#pragma pop
- file2.c
#pragma push
#pragma CODE_SEG ToCopyToRAM
void Test2(void)
{
//-----------test code------------------//
}
#pragma CODE_SEG DEFAULT
#pragma pop
- main.c
void main(void)
{
// initialization
while(1)
{
Test1();
Test2();
}
}
it it right?