在之前的博客【链接脚本(Linker Script)应用实例(一)使用copy table将函数载入到RAM中运行】中,我们第一步使用#pragma section命令将PFlashProgram函数存储至程序段.flash_driver,具体程序如下:
#pragma section ".flash_driver" ax void PFlashProgram( uint32 flash, uint32 addr, uint32 word_l, uint32 word_u ) { uint32 load_cnt; uint16 endinitSfty_pw = IfxScuWdt_getSafetyWatchdogPasswordInline(); IfxFlash_enterPageMode(addr); /* wait until unbusy */ IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_P0); /* write 32 bytes (8 doublewords) into assembly buffer */ for (load_cnt = 0; load_cnt < 4; load_cnt++) { IfxFlash_loadPage2X32(addr, word_l, word_u); } /* write page */ IfxScuWdt_clearSafetyEndinitInline(endinitSfty_pw); IfxFlash_writePage(addr); IfxScuWdt_setSafetyEndinitInline(endinitSfty_pw); /* wait until unbusy */ IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_P0); } #pragma section
编译之后的map文件如下,可以看到PFlashProgram函数生成的程序段大小为280字节。下面对函数的内容进行调整后重新编译,以验证将PFlashProgram函数存储到.flash_driver程序段时是否同时也将IfxFlash_enterPageMode、IfxFlash_waitUnbusy及IfxFlash_loadPage2X32等子函数同时存储到该段。这个问题之所以值得关注,是因为若不将其子函数也存储到该段,子函数将默认存储在ROM(Flash)中,那么PFlashProgram函数执行到其子函数时将从Flash而不是RAM中取指令。由于TC297不支持Flash操作函数对其所在的Flash进行擦写(Flash大多都具有这种特性)(Flash操作函数必须在RAM中或另一个Flash Bank中运行从而执行擦写操作),PFlashProgram函数无法成功执行对PFlash的写入操作。另外,了解#pragma section命令的这个特性也有助于程序员对代码存储与执行情况的掌握。
Linker version: GNU ld version (GNU Binutils) 2.20 (TriCore) using BFD version (GNU Binutils) 2.20 (v2.3), Tool Version v2.7 Name of linker executable: c:/hightec/toolchains/tricore/v4.9.1.0-infineon-2.0/bin/../lib/gcc/tricore/4.9.4/../../../../tricore/bin/ld.exe Date of link run: Thu Sep 05 10:42:28 2019 Name of linker map file: Flash_test.map >>> Symbols (global (S = g) and static (S = l); sorted by address) ============================================================================================================================================================ Start End Size S Name Memory O-Sec I-Sec Input object ============================================================================================================================================================ 0x00000290 0x00000290 0 g __TRICORE_DERIVATE_MEMORY_MAP__ *ABS* *ABS* *ABS* *ABS* 0x00000400 0x00000400 0 g LCF_ISTACK0_SIZE *ABS* *ABS* *ABS* *ABS* 0x00000400 0x00000400 0 g LCF_ISTACK1_SIZE *ABS* *ABS* *ABS* *ABS* 0x00000400 0x00000400