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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
2,359 次查看
kef
Specialist I

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.

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,109 次查看
kef
Specialist I

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.

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,110 次查看
kef
Specialist I

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.

0 项奖励
回复
1,109 次查看
byeongjinkim
Contributor II

Is the following method correct?

example)

ProcessorExpert.prm

pastedImage_1.png

- 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?

0 项奖励
回复