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

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

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

Jump to solution
2,081 Views
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.

Labels (1)
Tags (1)
0 Kudos
1 Solution
831 Views
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.

View solution in original post

0 Kudos
2 Replies
832 Views
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 Kudos
831 Views
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 Kudos