準備事項:

1.跟Compiler告知需要複製的區塊:

#pragma CODE_SECTION(Func名稱, "目標位置"); // 放在有此Func的程式上方(檔案頂端)

2. 修改cmd檔(基本上以下是不需要修改的)

ramfuncs        : LOAD = FLASHD,  //程式存放位置(即等等需複製區塊的起始點)
                      RUN = RAML0,         //程式運作點
                      LOAD_START(_RamfuncsLoadStart), //通知Compiler欲複製程式起點
                      LOAD_END(_RamfuncsLoadEnd),      //通知Compiler程式終點
                      RUN_START(_RamfuncsRunStart),    //程式運作起點
                      PAGE = 0

3. 載入檔案DSPXXXx_MemCopy.c檔 (自動載入DSPXXXx_GlobalPrototypes.h)

初始化區塊放入此程式

MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);

 

程式執行後!

先看看記憶體配置

MEMORY
{
PAGE 0:    /* Program Memory */
           /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */

   RAML0       : origin = 0x008000, length = 0x001000     /* on-chip RAM block L0 */
   OTP         : origin = 0x3D7800, length = 0x000400     /* on-chip OTP */
   FLASHD      : origin = 0x3E8000, length = 0x004000     /* on-chip FLASH */
   FLASHC      : origin = 0x3EC000, length = 0x004000     /* on-chip FLASH */
   FLASHA      : origin = 0x3F4000, length = 0x003F80     /* on-chip FLASH */
   CSM_RSVD    : origin = 0x3F7F80, length = 0x000076     /* Part of FLASHA.  Program with all 0x0000 when CSM is in use. */
   BEGIN       : origin = 0x3F7FF6, length = 0x000002     /* Part of FLASHA.  Used for "boot to Flash" bootloader mode. */
   CSM_PWL     : origin = 0x3F7FF8, length = 0x000008     /* Part of FLASHA.  CSM password locations in FLASHA */
   ROM         : origin = 0x3FF000, length = 0x000FC0     /* Boot ROM */
   RESET       : origin = 0x3FFFC0, length = 0x000002     /* part of boot ROM  */
   VECTORS     : origin = 0x3FFFC2, length = 0x00003E     /* part of boot ROM  */

PAGE 1 :   /* Data Memory */
           /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE0 for program allocation */
           /* Registers remain on PAGE1                                                  */

   RAMM0       : origin = 0x000000, length = 0x000400     /* on-chip RAM block M0 */
   BOOT_RSVD   : origin = 0x000400, length = 0x000080     /* Part of M1, BOOT rom will use this for stack */
   RAMM1       : origin = 0x000480, length = 0x000380     /* on-chip RAM block M1 */
   RAML1       : origin = 0x009000, length = 0x001000     /* on-chip RAM block L1 */
   FLASHB      : origin = 0x3F0000, length = 0x004000     /* on-chip FLASH */
   RAMH0       : origin = 0x3FA000, length = 0x002000     /* on-chip RAM block H0 */
}

#pragma CODE_SECTION(ADC_interrupt, "ramfuncs");

觀察下面map檔配置可觀察到中斷副程式已經被配置在0x00008000的位置

而從變數RamfuncsLoadEnd與RamfuncsLoadStart分別放置ADC_interrupt程式長度並且記憶體配置在FlashD區塊內

00008000   _ADC_interrupt
003e8c3b   _RamfuncsLoadEnd
003e8bfe   _RamfuncsLoadStart
00008000   _RamfuncsRunStart

 

讓我們再來看看MemCopy的函數吧!

MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);

void MemCopy(Uint16 *SourceAddr, Uint16* SourceEndAddr, Uint16* DestAddr)
{
    while(SourceAddr < SourceEndAddr)
    {
       *DestAddr++ = *SourceAddr++;
    }
    return;
}

從指標看來就是將SourceAddr資料複製到DestAddr

也就是將RamfuncsLoadStart複製到RamfuncsRunStart

再從實際位址看的話也就是0x003e8bfe(FLASHD) => 0x00008000(RAML0)

最後用一張圖片來驗證吧!

image

 

ㄟ~~最後提到我為啥要發這篇文章?

第一就是一方面我可以做個紀念也可保存一下這篇知識,

另外一個重點是,芒果喜歡認真工作的男生(我很認真阿XD~~裝死)……

以上