1.CMD文件的作用 CMD文件的作用就像仓库的货物摆放记录一样,为程序代码和数据分配指定的空间。
2.C语言生成的段 C语言生成的段大致分为两大类:初始化和未初始化,已初始化的段含有真正的指令和数据,未初始化段只是保留变量的地址空间。已初始化段通常放在程序空间,未初始化段通常放在数据空间。
已初始化段:
.text——C语言编译生成的汇编指令代码存放于此
.cinit——存放初始化的全局和静态变量
.const——字符串常量和const定义的全局和静态变量
.econst——字符串常量和far const定义的全局和静态变量
.print——全局构造器(C++)程序列表
.switch——存放switch语句产生的常数表格
以.const段为例:
- const int a = 10; //注意必须是全局的 如果声明为局部const初始化变量,不会放在.const段,局部变量都是运行时放在.bss段中
- char * p = "ABC";
- 数组和结构体的初始值——是局部变量时,产生的是.const,如果是全局变量,产生的是.cinit
未初始化段:
.bss——为全局变量和局部变量保留的空间,程序上电时,.cinit空间中的数据复制出来并存放在.bss空间中
.ebss——为使用大寄存器模式时预留的全局和局部变量空间,程序上电时,.cinit空间中的数据复制出来并存放在.bss空间中
.stack——堆栈空间,主要用于函数传递变量或为局部变量分配空间
.system——为动态存储分配保留的空间(malloc),如果有宏函数,此空间被占用
.esystem——为动态存储分配保留的空间(far malloc),如果有far函数,此空间会被占用
3.自定义段上面的都是官方预先定义好的,我们可以定义自己的段么?可以,使用如下语句:
- #pragma CODE_SECTION(symbol, "section name");
- #pragma DATA_SECTION(symbol, "section name");
symbol——符号,可以是函数名/变量名
section name——自定义的段名
CODE_SECTION用来定义代码段
DATA_SECTION用来定义数据段
注意:
不能再函数体内声明#pragma;
必须在符号被定义和使用之前声明#pragma
例子:
- #pragma DATA_SECTION(data, "data_name");
- char data[100];
4.CMD文件 在DSP28335工程文件里(不用BIOS产生CMD文件),手写CMD文件一般有两个,RAM里调试时用的两个CMD文件分别为DSP2833x_Headers_nonBIOS.cmd和28335_RAM_lnk.cmd,烧写到flash里时用的两个CMD文件分别为DSP2833x_Headers_nonBIOS.cmd和F28335.cmd,其中DSP2833x_Headers_nonBIOS.cmd文件可以在所有工程文件中通用,主要作用是把外设寄存器产生的数据段映射到对应的存储空间,可以跟DSP2833x_GlobalVariableDefs.c文件对照一下看看。在我的上一篇文章中也有提到。
其实我们也不需要详细的知道如何编写cmd文件,可以照着原有的修改就可以了。
下面是官方28335_RAM_lnk.cmd,一般情况下直接用TI给的,不需要做修改即可满足调试用,模式较固定,当然你也可以做相应的修改用到哪块RAM存储空间,在CMD文件里做相应的分配即可。
- MEMORY
- {
- PAGE 0 :
- /* BEGIN is used for the "boot to SARAM" bootloader mode */
-
- BEGIN : origin = 0x000000, length = 0x000002 /* Boot to M0 will go here */
- RAMM0 : origin = 0x000050, length = 0x0003B0
- RAML0 : origin = 0x008000, length = 0x001000
- RAML1 : origin = 0x009000, length = 0x001000
- RAML2 : origin = 0x00A000, length = 0x001000
- RAML3 : origin = 0x00B000, length = 0x001000
- ZONE7A : origin = 0x200000, length = 0x00FC00 /* XINTF zone 7 - program space */
- CSM_RSVD : origin = 0x33FF80, length = 0x000076 /* Part of FLASHA. Program with all 0x0000 when CSM is in use. */
- CSM_PWL : origin = 0x33FFF8, length = 0x000008 /* Part of FLASHA. CSM password locations in FLASHA */
- ADC_CAL : origin = 0x380080, length = 0x000009
- RESET : origin = 0x3FFFC0, length = 0x000002
- IQTABLES : origin = 0x3FE000, length = 0x000b50
- IQTABLES2 : origin = 0x3FEB50, length = 0x00008c
- FPUTABLES : origin = 0x3FEBDC, length = 0x0006A0
- BOOTROM : origin = 0x3FF27C, length = 0x000D44
-
-
- PAGE 1 :
- /* BOOT_RSVD is used by the boot ROM for stack. */
- /* This section is only reserved to keep the BOOT ROM from */
- /* corrupting this area during the debug process */
-
- BOOT_RSVD : origin = 0x000002, length = 0x00004E /* Part of M0, BOOT rom will use this for stack */
- RAMM1 : origin = 0x000400, length = 0x000400 /* on-chip RAM block M1 */
- RAML4 : origin = 0x00C000, length = 0x001000
- RAML5 : origin = 0x00D000, length = 0x001000
- RAML6 : origin = 0x00E000, length = 0x001000
- RAML7 : origin = 0x00F000, length = 0x001000
- ZONE7B : origin = 0x20FC00, length = 0x000400 /* XINTF zone 7 - data space */
- }
-
- SECTIONS
- {
- /* Setup for "boot to SARAM" mode:
- The codestart section (found in DSP28_CodeStartBranch.asm)
- re-directs execution to the start of user code. */
- codestart : > BEGIN, PAGE = 0
- ramfuncs : > RAML0, PAGE = 0
- .text : > RAML1, PAGE = 0
- .cinit : > RAML0, PAGE = 0
- .pinit : > RAML0, PAGE = 0
- .switch : > RAML0, PAGE = 0
-
- .stack : > RAMM1, PAGE = 1
- .ebss : > RAML4, PAGE = 1
- .econst : > RAML5, PAGE = 1
- .esysmem : > RAMM1, PAGE = 1
-
- IQmath : > RAML1, PAGE = 0
- IQmathTables : > IQTABLES, PAGE = 0, TYPE = NOLOAD
-
- /* Uncomment the section below if calling the IQNexp() or IQexp()
- functions from the IQMath.lib library in order to utilize the
- relevant IQ Math table in Boot ROM (This saves space and Boot ROM
- is 1 wait-state). If this section is not uncommented, IQmathTables2
- will be loaded into other memory (SARAM, Flash, etc.) and will take
- up space, but 0 wait-state is possible.
- */
- /*
- IQmathTables2 : > IQTABLES2, PAGE = 0, TYPE = NOLOAD
- {
-
- IQmath.lib<IQNexpTable.obj> (IQmathTablesRam)
-
- }
- */
-
- FPUmathTables : > FPUTABLES, PAGE = 0, TYPE = NOLOAD
-
- DMARAML4 : > RAML4, PAGE = 1
- DMARAML5 : > RAML5, PAGE = 1
- DMARAML6 : > RAML6, PAGE = 1
- DMARAML7 : > RAML7, PAGE = 1
-
- ZONE7DATA : > ZONE7B, PAGE = 1
-
- .reset : > RESET, PAGE = 0, TYPE = DSECT /* not used */
- csm_rsvd : > CSM_RSVD PAGE = 0, TYPE = DSECT /* not used for SARAM examples */
- csmpasswds : > CSM_PWL PAGE = 0, TYPE = DSECT /* not used for SARAM examples */
-
- /* Allocate ADC_cal function (pre-programmed by factory into TI reserved memory) */
- .adc_cal : load = ADC_CAL, PAGE = 0, TYPE = NOLOAD
-
- }
-
- /*
- //===========================================================================
- // End of file.
- //===========================================================================
- */
下面是官方F28335.cmd;
编写用于flash烧写的F28335.cmd文件时相对来说较复杂些,根据不同的情况需要做一些修改。
1 不需要把部分代码copy到RAM里,一般情况不需要外扩RAM等时直接用TI的F28335.cmd即可。
3 从时间开销方面考虑,需要把整个程序从flash复制到RAM里,这时程序及CMD文件都要做相应的修改,具体参考博文https://bbs.eeworld.com.cn/thread-458525-1-1.html
- MEMORY
- {
- PAGE 0: /* Program Memory */
- /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */
-
- ZONE0 : origin = 0x004000, length = 0x001000 /* XINTF zone 0 */
- RAML0 : origin = 0x008000, length = 0x001000 /* on-chip RAM block L0 */
- RAML1 : origin = 0x009000, length = 0x001000 /* on-chip RAM block L1 */
- RAML2 : origin = 0x00A000, length = 0x001000 /* on-chip RAM block L2 */
- RAML3 : origin = 0x00B000, length = 0x001000 /* on-chip RAM block L3 */
- ZONE6 : origin = 0x0100000, length = 0x100000 /* XINTF zone 6 */
- ZONE7A : origin = 0x0200000, length = 0x00FC00 /* XINTF zone 7 - program space */
- FLASHH : origin = 0x300000, length = 0x008000 /* on-chip FLASH */
- FLASHG : origin = 0x308000, length = 0x008000 /* on-chip FLASH */
- FLASHF : origin = 0x310000, length = 0x008000 /* on-chip FLASH */
- FLASHE : origin = 0x318000, length = 0x008000 /* on-chip FLASH */
- FLASHD : origin = 0x320000, length = 0x008000 /* on-chip FLASH */
- FLASHC : origin = 0x328000, length = 0x008000 /* on-chip FLASH */
- FLASHA : origin = 0x338000, length = 0x007F80 /* on-chip FLASH */
- CSM_RSVD : origin = 0x33FF80, length = 0x000076 /* Part of FLASHA. Program with all 0x0000 when CSM is in use. */
- BEGIN : origin = 0x33FFF6, length = 0x000002 /* Part of FLASHA. Used for "boot to Flash" bootloader mode. */
- CSM_PWL : origin = 0x33FFF8, length = 0x000008 /* Part of FLASHA. CSM password locations in FLASHA */
- OTP : origin = 0x380400, length = 0x000400 /* on-chip OTP */
- ADC_CAL : origin = 0x380080, length = 0x000009 /* ADC_cal function in Reserved memory */
-
- IQTABLES : origin = 0x3FE000, length = 0x000b50 /* IQ Math Tables in Boot ROM */
- IQTABLES2 : origin = 0x3FEB50, length = 0x00008c /* IQ Math Tables in Boot ROM */
- FPUTABLES : origin = 0x3FEBDC, length = 0x0006A0 /* FPU Tables in Boot ROM */
- ROM : origin = 0x3FF27C, length = 0x000D44 /* 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 */
-
- BOOT_RSVD : origin = 0x000000, length = 0x000050 /* Part of M0, BOOT rom will use this for stack */
- RAMM0 : origin = 0x000050, length = 0x0003B0 /* on-chip RAM block M0 */
- RAMM1 : origin = 0x000400, length = 0x000400 /* on-chip RAM block M1 */
- RAML4 : origin = 0x00C000, length = 0x001000 /* on-chip RAM block L1 */
- RAML5 : origin = 0x00D000, length = 0x001000 /* on-chip RAM block L1 */
- RAML6 : origin = 0x00E000, length = 0x001000 /* on-chip RAM block L1 */
- RAML7 : origin = 0x00F000, length = 0x001000 /* on-chip RAM block L1 */
- ZONE7B : origin = 0x20FC00, length = 0x000400 /* XINTF zone 7 - data space */
- FLASHB : origin = 0x330000, length = 0x008000 /* on-chip FLASH */
- }
-
- /* Allocate sections to memory blocks.
- Note:
- codestart user defined section in DSP28_CodeStartBranch.asm used to redirect code
- execution when booting to flash
- ramfuncs user defined section to store functions that will be copied from Flash into RAM
- */
-
- SECTIONS
- {
-
- /* Allocate program areas: */
- .cinit : > FLASHA PAGE = 0
- .pinit : > FLASHA, PAGE = 0
- .text : > FLASHA PAGE = 0
- codestart : > BEGIN PAGE = 0
- ramfuncs : LOAD = FLASHD,
- RUN = RAML0,
- LOAD_START(_RamfuncsLoadStart),
- LOAD_END(_RamfuncsLoadEnd),
- RUN_START(_RamfuncsRunStart),
- PAGE = 0
-
- csmpasswds : > CSM_PWL PAGE = 0
- csm_rsvd : > CSM_RSVD PAGE = 0
-
- /* Allocate uninitalized data sections: */
- .stack : > RAMM1 PAGE = 1
- .ebss : > RAML4 PAGE = 1
- .esysmem : > RAMM1 PAGE = 1
-
- /* Initalized sections go in Flash */
- /* For SDFlash to program these, they must be allocated to page 0 */
- .econst : > FLASHA PAGE = 0
- .switch : > FLASHA PAGE = 0
-
- /* Allocate IQ math areas: */
- IQmath : > FLASHC PAGE = 0 /* Math Code */
- IQmathTables : > IQTABLES, PAGE = 0, TYPE = NOLOAD
-
- /* Uncomment the section below if calling the IQNexp() or IQexp()
- functions from the IQMath.lib library in order to utilize the
- relevant IQ Math table in Boot ROM (This saves space and Boot ROM
- is 1 wait-state). If this section is not uncommented, IQmathTables2
- will be loaded into other memory (SARAM, Flash, etc.) and will take
- up space, but 0 wait-state is possible.
- */
- /*
- IQmathTables2 : > IQTABLES2, PAGE = 0, TYPE = NOLOAD
- {
-
- IQmath.lib<IQNexpTable.obj> (IQmathTablesRam)
-
- }
- */
-
- FPUmathTables : > FPUTABLES, PAGE = 0, TYPE = NOLOAD
-
- /* Allocate DMA-accessible RAM sections: */
- DMARAML4 : > RAML4, PAGE = 1
- DMARAML5 : > RAML5, PAGE = 1
- DMARAML6 : > RAML6, PAGE = 1
- DMARAML7 : > RAML7, PAGE = 1
-
- /* Allocate 0x400 of XINTF Zone 7 to storing data */
- ZONE7DATA : > ZONE7B, PAGE = 1
-
- /* .reset is a standard section used by the compiler. It contains the */
- /* the address of the start of _c_int00 for C Code. /*
- /* When using the boot ROM this section and the CPU vector */
- /* table is not needed. Thus the default type is set here to */
- /* DSECT */
- .reset : > RESET, PAGE = 0, TYPE = DSECT
- vectors : > VECTORS PAGE = 0, TYPE = DSECT
-
- /* Allocate ADC_cal function (pre-programmed by factory into TI reserved memory) */
- .adc_cal : load = ADC_CAL, PAGE = 0, TYPE = NOLOAD
-
- }
-
- /*
- //===========================================================================
- // End of file.
- //===========================================================================
- */