请问如何将程序拷贝到RAM中运行?

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

请问如何将程序拷贝到RAM中运行?

1,374 Views
mikijt
Contributor I

最近在写bootloadr ,程序能够通过上位机将APP下发到mcu中,但是在APP执行命令擦除FLASH时出现了死机;

单独调试APP程序的时候,执行擦除命令,PC跳转到0x00001 ;

我就在考虑是不是我的flash相关的程序有没有拷贝到RAM 中,之前的做法是就是在对应的函数前面加上:#pragma CODE_SEG DEFAULT_RAM

1.copydown sction是否实现了从flash到ram的拷贝?是否是在doCopyDown就已经实现了这个拷贝过程?

尝试过将函数前面加上#pragma CODE_SEG DEFAULT_RAM,能够发现法该函数的地址是在RAM中。带上我不太确定!

2.是否需要手动memcpy才能实现代码的拷贝?

参考某BootLoader例程中的关于代码拷贝的代码:

/*************************************************************************************/

#define __SEG_START_REF(a) __SEG_START_ ## a
#define __SEG_END_REF(a) __SEG_END_ ## a
#define __SEG_SIZE_REF(a) __SEG_SIZE_ ## a
#define __SEG_START_DEF(a) extern char __SEG_START_REF(a) []
#define __SEG_END_DEF(a) extern char __SEG_END_REF( a) []
#define __SEG_SIZE_DEF(a) extern char __SEG_SIZE_REF( a) []

__SEG_START_DEF(SHADOW_ROM);
__SEG_END_DEF(SHADOW_ROM);
__SEG_SIZE_DEF(SHADOW_ROM);

/*************************************************************************************/

static void CopyCodeToRAM(void)
{
/* Variable Declarations */
uchar *Src;
uchar *Dst;
uint SegSize;
uint x;
/* Begin Function CopyCodeToRAM() */
Src = (uchar *)__SEG_START_REF(SHADOW_ROM); /* RAM code resides in Flash from 0xf000 - 0xf1ff */
Dst = (uchar *)0x001000; /* copied to the upper 512 bytes of RAM */
SegSize = (uint)__SEG_SIZE_REF(SHADOW_ROM);
for (x = 0; x < SegSize; x++) /* just copy a byte at a time */
*Dst++ = *Src++;
}

但是在执行的时候发现,执行该局之后,对应的RAM并没有与源flash地址的内容相同,就是说拷贝过程失败。

请问那种方法是对的?或者别的方法?

3、如何确定程序已经被拷贝到RAM中?

0 Kudos
3 Replies

886 Views
dianabatrlova
NXP TechSupport
NXP TechSupport

Hello, 

For better understanding, please, write your question in English. 

The flash commands should be executed from RAM because we cannot execute code in flash block during erase/program flash command. 

#pragma CODE_SEG DEFAULT_RAM

//Your function should be placed between the pragmas for placing the function in to RAM

#pragma CODE_SEG DEFAULT

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

The function will be automatically copied from Flash to the RAM during Startup() 

I would like to recommend you to look at an attached example code where you can see how to erase and program flash.

I assume this is the easiest way for executing the function from RAM. 

I hope it helps.

Thank you.

Best Regards,

Diana

0 Kudos

886 Views
mikijt
Contributor I

thank you very much!

As the function(pflash_send_command) is in the RAM section (0x10000 )in the map file, that means the func wound be  copyed into ram in startup ()!

测试点.jpg

0 Kudos

886 Views
dianabatrlova
NXP TechSupport
NXP TechSupport

Hello,

If you look into the code the PFLASH_Send_Command function is called in the PFLASH_Erase_Verify_Section function. It is not needed to place the whole PFLASH_Erase_Verify_Section function into RAM, Only a critical section (launch command) is placed into RAM when CCIF = 0. 

I hope it helps.

Best Regards,

Diana

0 Kudos