首先,我们必须要知道一些基本的概念,然后再分析,这里引用书本的一些话。
28335的cmd文件有两个,一个是关于寄存器的,一个是关于程序的。
关于寄存器的cmd文件,包括两部分,一部分是section,这部分是定义的寄存器文件,一部分是map,就是为那些寄存器文件分配地址:
[html]view plaincopy
MEMORY { PAGE0:/*ProgramMemory*/ PAGE1:/*DataMemory*/ DEV_EMU:origin=0x000880,length=0x000180/*deviceemulationregisters*/ FLASH_REGS:origin=0x000A80,length=0x000060/*FLASHregisters*/ CSM:origin=0x000AE0,length=0x000010/*codesecuritymoduleregisters*/ ADC_MIRROR:origin=0x000B00,length=0x000010/*ADCResultsregistermirror*/ XINTF:origin=0x000B20,length=0x000020/*externalinterfaceregisters*/ CPU_TIMER0:origin=0x000C00,length=0x000008/*CPUTimer0registers*/ CPU_TIMER1:origin=0x000C08,length=0x000008/*CPUTimer0registers(CPUTimer1&Timer2reservedTIuse)*/ CPU_TIMER2:origin=0x000C10,length=0x000008/*CPUTimer0registers(CPUTimer1&Timer2reservedTIuse)*/ PIE_CTRL:origin=0x000CE0,length=0x000020/*PIEcontrolregisters*/ PIE_VECT:origin=0x000D00,length=0x000100/*PIEVectorTable*/ DMA:origin=0x001000,length=0x000200/*DMARev0registers*/ MCBSPA:origin=0x005000,length=0x000040/*McBSP-Aregisters*/ MCBSPB:origin=0x005040,length=0x000040/*McBSP-Bregisters*/ ECANA:origin=0x006000,length=0x000040/*eCAN-Acontrolandstatusregisters*/ ECANA_LAM:origin=0x006040,length=0x000040/*eCAN-Alocalacceptancemasks*/ ECANA_MOTS:origin=0x006080,length=0x000040/*eCAN-Amessageobjecttimestamps*/ ECANA_MOTO:origin=0x0060C0,length=0x000040/*eCAN-Aobjecttime-outregisters*/ ECANA_MBOX:origin=0x006100,length=0x000100/*eCAN-Amailboxes*/ ECANB:origin=0x006200,length=0x000040/*eCAN-Bcontrolandstatusregisters*/ ECANB_LAM:origin=0x006240,length=0x000040/*eCAN-Blocalacceptancemasks*/ ECANB_MOTS:origin=0x006280,length=0x000040/*eCAN-Bmessageobjecttimestamps*/ ECANB_MOTO:origin=0x0062C0,length=0x000040/*eCAN-Bobjecttime-outregisters*/ ECANB_MBOX:origin=0x006300,length=0x000100/*eCAN-Bmailboxes*/ EPWM1:origin=0x006800,length=0x000022/*EnhancedPWM1registers*/ EPWM2:origin=0x006840,length=0x000022/*EnhancedPWM2registers*/ EPWM3:origin=0x006880,length=0x000022/*EnhancedPWM3registers*/ EPWM4:origin=0x0068C0,length=0x000022/*EnhancedPWM4registers*/ EPWM5:origin=0x006900,length=0x000022/*EnhancedPWM5registers*/ EPWM6:origin=0x006940,length=0x000022/*EnhancedPWM6registers*/ ECAP1:origin=0x006A00,length=0x000020/*EnhancedCapture1registers*/ ECAP2:origin=0x006A20,length=0x000020/*EnhancedCapture2registers*/ ECAP3:origin=0x006A40,length=0x000020/*EnhancedCapture3registers*/ ECAP4:origin=0x006A60,length=0x000020/*EnhancedCapture4registers*/ ECAP5:origin=0x006A80,length=0x000020/*EnhancedCapture5registers*/ ECAP6:origin=0x006AA0,length=0x000020/*EnhancedCapture6registers*/ EQEP1:origin=0x006B00,length=0x000040/*EnhancedQEP1registers*/ EQEP2:origin=0x006B40,length=0x000040/*EnhancedQEP2registers*/ GPIOCTRL:origin=0x006F80,length=0x000040/*GPIOcontrolregisters*/ GPIODAT:origin=0x006FC0,length=0x000020/*GPIOdataregisters*/ GPIOINT:origin=0x006FE0,length=0x000020/*GPIOinterrupt/LPMregisters*/ SYSTEM:origin=0x007010,length=0x000020/*Systemcontrolregisters*/ SPIA:origin=0x007040,length=0x000010/*SPI-Aregisters*/ SCIA:origin=0x007050,length=0x000010/*SCI-Aregisters*/ XINTRUPT:origin=0x007070,length=0x000010/*externalinterruptregisters*/ ADC:origin=0x007100,length=0x000020/*ADCregisters*/ SCIB:origin=0x007750,length=0x000010/*SCI-Bregisters*/ SCIC:origin=0x007770,length=0x000010/*SCI-Cregisters*/ I2CA:origin=0x007900,length=0x000040/*I2C-Aregisters*/ CSM_PWL:origin=0x33FFF8,length=0x000008/*PartofFLASHA.CSMpasswordlocations.*/ } SECTIONS { PieVectTableFile:>PIE_VECT,PAGE=1 /***PeripheralFrame0RegisterStructures***/ DevEmuRegsFile:>DEV_EMU,PAGE=1 FlashRegsFile:>FLASH_REGS,PAGE=1 CsmRegsFile:>CSM,PAGE=1 AdcMirrorFile:>ADC_MIRROR,PAGE=1 XintfRegsFile:>XINTF,PAGE=1 CpuTimer0RegsFile:>CPU_TIMER0,PAGE=1 CpuTimer1RegsFile:>CPU_TIMER1,PAGE=1 CpuTimer2RegsFile:>CPU_TIMER2,PAGE=1 PieCtrlRegsFile:>PIE_CTRL,PAGE=1 DmaRegsFile:>DMA,PAGE=1 /***PeripheralFrame3RegisterStructures***/ McbspaRegsFile:>MCBSPA,PAGE=1 McbspbRegsFile:>MCBSPB,PAGE=1 /***PeripheralFrame1RegisterStructures***/ ECanaRegsFile:>ECANA,PAGE=1 ECanaLAMRegsFile:>ECANA_LAMPAGE=1 ECanaMboxesFile:>ECANA_MBOXPAGE=1 ECanaMOTSRegsFile:>ECANA_MOTSPAGE=1 ECanaMOTORegsFile:>ECANA_MOTOPAGE=1 ECanbRegsFile:>ECANB,PAGE=1 ECanbLAMRegsFile:>ECANB_LAMPAGE=1 ECanbMboxesFile:>ECANB_MBOXPAGE=1 ECanbMOTSRegsFile:>ECANB_MOTSPAGE=1 ECanbMOTORegsFile:>ECANB_MOTOPAGE=1 EPwm1RegsFile:>EPWM1PAGE=1 EPwm2RegsFile:>EPWM2PAGE=1 EPwm3RegsFile:>EPWM3PAGE=1 EPwm4RegsFile:>EPWM4PAGE=1 EPwm5RegsFile:>EPWM5PAGE=1 EPwm6RegsFile:>EPWM6PAGE=1 ECap1RegsFile:>ECAP1PAGE=1 ECap2RegsFile:>ECAP2PAGE=1 ECap3RegsFile:>ECAP3PAGE=1 ECap4RegsFile:>ECAP4PAGE=1 ECap5RegsFile:>ECAP5PAGE=1 ECap6RegsFile:>ECAP6PAGE=1 EQep1RegsFile:>EQEP1PAGE=1 EQep2RegsFile:>EQEP2PAGE=1 GpioCtrlRegsFile:>GPIOCTRLPAGE=1 GpioDataRegsFile:>GPIODATPAGE=1 GpioIntRegsFile:>GPIOINTPAGE=1 /***PeripheralFrame2RegisterStructures***/ SysCtrlRegsFile:>SYSTEM,PAGE=1 SpiaRegsFile:>SPIA,PAGE=1 SciaRegsFile:>SCIA,PAGE=1 XIntruptRegsFile:>XINTRUPT,PAGE=1 AdcRegsFile:>ADC,PAGE=1 ScibRegsFile:>SCIB,PAGE=1 ScicRegsFile:>SCIC,PAGE=1 I2caRegsFile:>I2CA,PAGE=1 /***CodeSecurityModuleRegisterStructures***/ CsmPwlFile:>CSM_PWL,PAGE=1
关于寄存器的cmd文件没有什么很难理解的地方,关键是程序的cmd文件,要好好学习一下。
[html]view plaincopy
MEMORY { PAGE0: /*BEGINisusedforthe"boottoSARAM"bootloadermode*/ /*BOOT_RSVDisusedbythebootROMforstack.*/ /*ThissectionisonlyreservedtokeeptheBOOTROMfrom*/ /*corruptingthisareaduringthedebugprocess*/ BEGIN:origin=0x000000,length=0x000002/*BoottoM0willgohere*/ BOOT_RSVD:origin=0x000002,length=0x00004E/*PartofM0,BOOTromwillusethisforstack*/ 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 ZONE6A:origin=0x100000,length=0x00FC00/*XINTFzone6-programspace*/ CSM_RSVD:origin=0x33FF80,length=0x000076/*PartofFLASHA.Programwithall0x0000whenCSMisinuse.*/ CSM_PWL:origin=0x33FFF8,length=0x000008/*PartofFLASHA.CSMpasswordlocationsinFLASHA*/ 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 PAGE1: RAMM1:origin=0x000400,length=0x000400/*on-chipRAMblockM1*/ RAML4:origin=0x00C000,length=0x001000 RAML5:origin=0x00D000,length=0x001000 RAML6:origin=0x00E000,length=0x001000 RAML7:origin=0x00F000,length=0x001000 ZONE6B:origin=0x10FC00,length=0x000400/*XINTFzone6-dataspace*/ } SECTIONS { /*Setupfor"boottoSARAM"mode: Thecodestartsection(foundinDSP28_CodeStartBranch.asm) re-directsexecutiontothestartofusercode.*/ 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 IQmathTables2:>IQTABLES2,PAGE=0,TYPE=NOLOAD FPUmathTables:>FPUTABLES,PAGE=0,TYPE=NOLOAD DMARAML4:>RAML4,PAGE=1 DMARAML5:>RAML5,PAGE=1 DMARAML6:>RAML6,PAGE=1 DMARAML7:>RAML7,PAGE=1 ZONE6DATA:>ZONE6B,PAGE=1 .reset:>RESET,PAGE=0,TYPE=DSECT/*notused*/ csm_rsvd:>CSM_RSVDPAGE=0,TYPE=DSECT/*notusedforSARAMexamples*/ csmpasswds:>CSM_PWLPAGE=0,TYPE=DSECT/*notusedforSARAMexamples*/ /*AllocateADC_calfunction(pre-programmedbyfactoryintoTIreservedmemory)*/ .adc_cal:load=ADC_CAL,PAGE=0,TYPE=NOLOAD }
也是分为两个部分,下面是段,上面是为那些段分配的地址,当然有些段在程序中比较大,但是给他分配的地址又不够,这个时候就报错了,这个时候需要修改程序或者修改cmd文件了,这样,大致的思路就清晰了。PAGE 0代表程序空间,PAGE 1代表数据空间,我们可以将一个大的空间分成两部分,然后将一些段放在这两部分空间里,但这两空间的总和不能超过原有的空间,上述是运行在ram的cmd文件,下面这个cmd文件我报错的cmd文件,对比一下就可以知道原因了。
[html]view plaincopy
MEMORY { PAGE0:/*ProgramMemory*/ /*Memory(RAM/FLASH/OTP)blockscanbemovedtoPAGE1fordataallocation*/ ZONE0:origin=0x004000,length=0x001000/*XINTFzone0*/ RAM_L0L1L2L3:origin=0x008000,length=0x004000/*on-chipRAM*/ OTP:origin=0x380400,length=0x000400/*on-chipOTP*/ ZONE6:origin=0x100000,length=0x100000/*XINTFzone6*/ ZONE7A:origin=0x200000,length=0x00FC00/*XINTFzone7-programspace*/ FLASHH:origin=0x300000,length=0x008000/*on-chipFLASH*/ FLASHG:origin=0x308000,length=0x008000/*on-chipFLASH*/ FLASHF:origin=0x310000,length=0x008000/*on-chipFLASH*/ FLASHE:origin=0x318000,length=0x008000/*on-chipFLASH*/ FLASHD:origin=0x320000,length=0x008000/*on-chipFLASH*/ FLASHC:origin=0x328000,length=0x008000/*on-chipFLASH*/ FLASHA:origin=0x338000,length=0x007F80/*on-chipFLASH*/ CSM_RSVD:origin=0x33FF80,length=0x000076/*PartofFLASHA.Programwithall0x0000whenCSMisinuse.*/ BEGIN_FLASH:origin=0x33FFF6,length=0x000002/*PartofFLASHA.Usedfor"boottoFlash"bootloadermode.*/ CSM_PWL:origin=0x33FFF8,length=0x000008/*PartofFLASHA.CSMpasswordlocationsinFLASHA*/ ADC_CAL:origin=0x380080,length=0x000009/*PartofTIOTP*/ IQTABLES:origin=0x3FE000,length=0x000b50/*IQMathTablesinBootROM*/ IQTABLES2:origin=0x3FEB50,length=0x00008c/*IQMathTablesinBootROM*/ FPUTABLES:origin=0x3FEBDC,length=0x0006A0/*FPUTablesinBootROM*/ ROM:origin=0x3FF27C,length=0x000D44/*BootROM*/ RESET:origin=0x3FFFC0,length=0x000002/*partofbootROM*/ VECTORS:origin=0x3FFFC2,length=0x00003E/*partofbootROM*/ PAGE1:/*DataMemory*/ /*Memory(RAM/FLASH/OTP)blockscanbemovedtoPAGE0forprogramallocation*/ /*RegistersremainonPAGE1*/ RAMM0:origin=0x000000,length=0x000400/*on-chipRAMblockM0*/ BOOT_RSVD:origin=0x000400,length=0x000080/*PartofM1,BOOTromwillusethisforstack*/ RAMM1:origin=0x000480,length=0x000380/*on-chipRAMblockM1*/ RAML4:origin=0x00C000,length=0x001000/*on-chipRAMblockL4*/ RAML5:origin=0x00D000,length=0x001000/*on-chipRAMblockL5*/ RAML6:origin=0x00E000,length=0x001000/*on-chipRAMblockL6*/ RAML7:origin=0x00F000,length=0x001000/*on-chipRAMblockL7*/ ZONE7B:origin=0x20FC00,length=0x000400/*XINTFzone7-dataspace*/ } /**************************************************************/ /*Linkalluserdefinedsections*/ /**************************************************************/ SECTIONS { }
看下M1分成了两个部分,ebss的部分当然就没有0x400了,这也是为什么会报错的原因了,这是学习cmd文件最基本的东西,要真正学好还有很长的一段距离,只能慢慢来了。
上面这张图为编译工程文件时的链接过程,可以解决我们一部分的疑惑。也解释了我第一段中text过大的原因,在工程中有些文件你虽然没有调用,但是他是占text的空间的,这也是我最初删除了一些不用的c文件就编译成功的原因。
最后:排爆机器人基于dsp+fpga中有些特色还没写出来,包括串口状态机(这部分比较好,继承师兄的),还有就是dsp读写fpga这部分吧(基于xintf的),然后还用到了pwm模块,哦,还有一个就是烧写到flash里面,拷贝到ram里面运行,不过这东西是借鉴的别人的,慢慢记录下来吧。