F2812程序从Flash搬到RAM中运行
【非本人原创】
第一步:
// Functions that will be run from RAM need to be assigned to
// a different section. This section will then be mapped using
// the linker cmd file.
#pragma CODE_SECTION(EPwm1_timer_isr, "ramfuncs");
#pragma CODE_SECTION(EPwm2_timer_isr, "ramfuncs");
MAIN()
{
// These are defined by the linker (see F2808.cmd)在CMD里面定义的变量
extern Uint16 RamfuncsLoadStart;
extern Uint16 RamfuncsLoadEnd;
extern Uint16 RamfuncsRunStart;
User specific code, enable interrupts:
// Copy time critical code and Flash setup code to RAM
// This includes the following ISR functions: EPwm1_timer_isr(), EPwm2_timer_isr()
// EPwm3_timer_isr and and InitFlash();
// The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
// symbols are created by the linker. Refer to the F2808.cmd file.
// Call Flash Initialization to setup flash waitstates
// This function must reside in RAM
}
第二步:将要从FLASH里面加载到RAM的函数定义到"ramfuncs"
// Functions that will be run from RAM need to be assigned to
// a different section. This section will then be mapped to a load and
// run address using the linker cmd file.
#pragma CODE_SECTION(InitFlash, "ramfuncs");
第三步:
CMD文件:
MEMORY
{
}
SECTIONS
{
}
总结:在MAP文件里:从FLASH加载到RAM运行的程序会有二个实际的存储空间,一个在FLASH里面,另一个在RAM里。ramfuncs : LOAD = FLASHA,//指定了要加载程序存储在FLASH里面的地址段。
MAP文件里的表现:
SECTION ALLOCATION MAP
ramfuncs 0 003f65d6 0000004d RUN ADDR = 00008000
.cinit 0 003f6623 00000019
GLOBAL SYMBOLS: SORTED ALPHABETICALLY BY Name
003f6623 _RamfuncsLoadEnd
003f65d6 _RamfuncsLoadStart
00008000 _RamfuncsRunStart
GLOBAL SYMBOLS: SORTED BY Symbol Address
00008000 _RamfuncsRunStart
0000801b _DSP28x_usDelay//三个从FLASH里加载RAM里运行的程序
0000801f _EPwm1_timer_isr
00008035 _EPwm2_timer_isr
003f65d6 _RamfuncsLoadStart
003f6623 cinit
003f6623 ___cinit__
003f6623 _RamfuncsLoadEnd//在FLASH的地址空间上面并没有具体的函数表现
程序运行上的表现:只要程序一运行到上面的三个函数,CCS程序PC指针就会指向相应RAM地址上运行。
本文详细介绍了如何将F2812 DSP的部分程序从Flash区域复制到RAM区域运行的过程。主要分为三步:首先使用编译器预处理指令将需要在RAM中运行的函数分配到特定的代码段;其次,在链接器命令文件中定义相应的内存区域和运行地址;最后,通过内存复制函数在程序启动时将这些代码段从Flash复制到RAM。
2859

被折叠的 条评论
为什么被折叠?



