can i use execute function code in ram ?

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

can i use execute function code in ram ?

1,400 Views
byeongjinkim
Contributor II

I develop motor control software. 

i use PTU interrupt. (ADC end interrupt)

The code size becomes large, and it takes a long time.

Can this processor be copied to RAM and run?

The motor controller code has already been developed on the TI MCU (C28xx). (Verified code)

Changing MCU.

--------------------------

example)

#pragma CODE_SEG DEFAULT_RAM

void MY_Function(void)

{

  .....

}

#pragma CODE_SEG DEFAULT

"Events.c"

void AD2_OnEnd(void)

{

  MY_Function();

}

--------------------------

is it right? but compile error.

- CodeWarrior 10.7 (using PE)

- S12ZVMC128

0 Kudos
Reply
3 Replies

1,123 Views
RadekS
NXP Employee
NXP Employee

Hi Byeongjin,

Yes, you can use such construction. That is simplest method.

It works correctly on my side. I created new PE project with ADC and I placed MY_Function() code at start of Events.c file.

Could you please let mi know which compiler error you got?

 

 

Note: If this should be time critical task, there are two unwanted function calls (The AD1_Interrupt calls AD1_OnEnd() which calls MY_Function()) which will degrade execution time by stacking/unstacking.

I would like to recommend taking PE code just like inspiration and wrote ADC interrupt routine manually.

 

You may also inspire at our NXP official example codes:

3-Phase Hall Sensor BLDC S12ZVM Application – six step driving

http://www.nxp.com/docs/en/user-guide/MTRCKTSBNZVMHQSG.pdf

http://www.nxp.com/docs/en/application-note/AN4718.pdf

http://www.nxp.com/docs/en/application-note-software/AN4718SW.zip

3-Phase Sensorless BLDC S12ZVM Application – six step driving

http://www.nxp.com/docs/en/user-guide/MTRCKTSBNZVM128QSG.pdf

http://www.nxp.com/docs/en/application-note/AN4704.pdf

http://www.nxp.com/downloads/en/board-support-packages/MTRCKTSBNZVM128_SW.exe

3-phase Sensorless Dual-Shunt PMSM S12ZVM Application – FOC driving

http://www.nxp.com/docs/en/user-guide/MTRCKTSPNZVM128QSG.pdf

http://www.nxp.com/docs/en/application-note/AN5135.pdf

http://www.nxp.com/downloads/en/evaluation-development-boards-systems/MTRCKTSPNZVM128_SW.exe

3-phase Sensorless Single-Shunt PMSM S12ZVM Application – FOC driving

http://www.nxp.com/docs/en/application-note/AN5327.pdf

http://www.nxp.com/assets/documents/data/en/user-guides/AN5327-QSG.pdf

Note: please be aware that there is still typo error in this document (already reported) – the jumpers J57 and J60 should be in position 2-3.

http://www.nxp.com/docs/en/application-note-software/AN5327SW.zip

 

 

Note: We should avoid using float type since MCU do not have hardware support for that. The software emulation takes too long.

 

Note: The computation window may be extended by PMFFQCA_LDFQA[3:0] bit configuration. This field selects the PWM load frequency – Every 1..16 PWM opportunities.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

1,123 Views
byeongjinkim
Contributor II

change to PWM reload interrupt.

pastedImage_1.png

how to executing in ram? Do I need to copy all the memory?

 ToCopyToRam(0xFFEE00 ~ 0xFFFDFF) ㅡ> (0x002000 ~ 0x002FFF)

all copy?

0 Kudos
Reply

1,123 Views
RadekS
NXP Employee
NXP Employee

Hi Byeongjin,

 

When you will define some function directly on RAM like your original proposal, the function will be compiled for work in RAM and automatically copy from Flash to the RAM during Startup() – like variable initialization. For example:

#pragma CODE_SEG DEFAULT_RAM
void MY_Function(void)
{
  .....
}
#pragma CODE_SEG DEFAULT‍‍‍‍‍‍

 

Please be aware that the same #pragmas must be used also for function prototype.

 

 

The next option is compiling code for run in RAM and copy it there manually – as it is used in your next post (using RELOCATE_TO qualifier in prm linker file).

In that case, you should create a function which will copy ToCopyToRam section to the RAM (starting from 0x2000).

For example:

static void CopyCodeToRAM(void)
{ 
  UINT8 *Src;
  UINT8 *Dst;
  UINT16  SegSize;
  UINT16  x;
 
  //RAM code resides in Flash from 0xFFEE00 to 0xFFFDFF
  Src = (UINT8 *)__SEG_START_REF(ToCopyToRam);
  Dst = (UINT8 *) 0x2000;          //copied to RAM at 0x2000
  SegSize = (UINT16)__SEG_SIZE_REF(ToCopyToRam);
 
  for (x = 0; x < SegSize; x++)   //just copy a byte at a time
    *Dst++ = *Src++;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply