目标板:C2000的28335/28069一、主要思路:1、准备升级程序(相当于一个bootloader),作为上电首先运行的程序。
进入升级程序,首先判断需不需要升级,需要升级,进入升级状态,通信完成新的主程序的接收,存入,升级成功后,进入主程序运行。
2、在主程序运行时,收到升级指令,标记升级标志,重启进入升级程序进去升级。
3、板子上电后,会调到flash启动的起始地址0x33FFF6(DSP28335),这个地址存放着程序的codestart 的其实地址。
所以,修改了0x33FFF6的存放的值,那么就能决定执行那一段程序。
还可以通过汇编跳转指令直接跳转到程序codestart执行。
二、升级程序1、具备能力:具备通信能力和Flash读写能力2、准备:Flash API移植、上位机的升级配套程序;存储升级标志位的空间(外部EEPROM,不会随便擦除的内部Flash)3、流程:接收->校验->烧写->跳转三、升级步骤1、数据接收:通过CAN/串口等方式接收数据。
由于28335内存较小,不适合缓存大量的数据,这里是接收一部分数据,校验完成后烧写进Flash,再去接收一部分数据2、数据解析:接收到的数据是hex格式的数据,所以需要解析才能放入对应的flash地址。
但由于28335能力限制,这里采用先在上位机解析完成,采用先告知地址,然后发送数据的方式完成数据通信和传输。
3、校验:这里采用crc校验。
/*******************************************************Name : crc16*Function: crc校验16位*Params : data(UInt8 *):待操作的数组 len:数据长度*Return : UInt16:返回CRC值 CRC校验码为2个字节高位在前*******************************************************/UInt16 crc16(Uint8 *data, UInt16 len){UInt16 CRC = 0xFFFF;UInt8 j, TMP = 0;UInt8 i;for (i = 0; i < len; i++){CRC ^= data[i];for (j = 0; j < 8; j++){TMP = CRC & 0x0001;CRC = CRC >> 1;if(TMP)CRC = CRC ^ 0xA001;}}return CRC;}4、数据烧写flash:运用flash API提供的接收完成数据的烧写。
这里要注意flash API必须运行在RAM 中。
5、完成数据烧写后,需要跳转到主程序。
一般采用汇编指令。
汇编指令asm("LB 0xXXXXXX")或者汇编函数。
这里采用asm的方式,跳转地址为新应用程序的起始地址,这里必须规定每次跟新的新应用程序的起始地址必须固定。
asm(" LB 0x3xxxxx");如果是使用变动的起始地址,则必须采用汇编函数,把地址作为参数传进函数。
四、主程序1、接收升级指令后,能够标志升级状态。
重启进入升级程序,进行判断,进而升级程序。
2、主程序运行后,升级状态标记为不用升级状态。
五、注意点1、升级程序与主程序要严格分开,合理分配flash空间,附升级程序和主程序cmd大致分配空间。
主程序cmd文件/*********************************************************************** File: f28335_nonBIOS_flash.cmd -- Linker command file for non-DSP/BIOS* code with DSP in Boot to Flash boot mode.** History: 09/18/07 - original (D. Alter)**********************************************************************/MEMORY{PAGE 0: /* Program Memory */BEGIN_M0 : origin = 0x000000, length = 0x000002 /* Part of M0SARAM. Used for "Bo ot to M0" bootloader mode. */FLASH_PROGRAMS : origin = 0x310000, length = 0x000010 /* On-chip FLASH */FLASH_PROGRAM : origin = 0x310010, length = 0x01FFF0 /* On-chip FLASH */ZONE7A : origin = 0x200000, length = 0x010000CSM_RSVD : origin = 0x33FF80, length = 0x000076 /* Part of FLASH Sector A. Reserve d when CSM is in use. */BEGIN_FLASH : origin = 0x33FFF6, length = 0x000002 /* Part of FLASH Sector A. Used fo r "Jump to flash" bootloader mode. */PASSWORDS : origin = 0x33FFF8, length = 0x000008 /* Part of FLASH Sector A. CSM p assword locations. */ADC_CAL : origin = 0x380080, length = 0x000009 /* ADC_cal function in Reserved me mory */OTP : origin = 0x380400, length = 0x000400 /* 1Kw OTP */IQTABLES : origin = 0x3FE000, length = 0x000B50 /* Part of Boot ROM */IQTABLES2 : origin = 0x3FEB50, length = 0x00008C /* Part of Boot ROM */FPUTABLES : origin = 0x3FEBDC, length = 0x0006A0 /* Part of Boot ROM */BOOTROM : origin = 0x3FF27C, length = 0x000D44 /* 8Kw Boot ROM */RESET : origin = 0x3FFFC0, length = 0x000002 /* part of Boot ROM */FLASH_CONST : origin = 0x300000, length = 0x010000PAGE 1 : /* Data Memory */M0SARAM : origin = 0x000002, length = 0x0003FE /* 1Kw M0 SARAM */M1SARAM : origin = 0x000400, length = 0x000400 /* 1Kw M1 SARAM */DRAM : origin = 0x008000, length = 0x008000PIEVECT : origin = 0x000D00, length = 0x000100ZONE7B : origin = 0x210000, length = 0x010000// FLASH_DATA : origin = 0x330000, length = 0x008000 /* On-chip FLASH */}SECTIONS{/*** Compiler Required Sections ***//* Program memory (PAGE 0) sections */.text1 : {DSP2833x_CodeStartBranch.obj(.text)}> FLASH_PROGRAMS, PAGE = 0.text2 : {*(.text)}> FLASH_PROGRAM, PAGE = 0.cinit : > FLASH_PROGRAM, PAGE = 0.const : > FLASH_PROGRAM, PAGE = 0.econst : > FLASH_CONST, PAGE = 0.pinit : > FLASH_PROGRAM, PAGE = 0.reset : > RESET, PAGE = 0, TYPE = DSECT /* We are not using the .reset secti on */.switch : > FLASH_PROGRAM, PAGE = 0.cio : > FLASH_PROGRAM, PAGE = 0/* Data Memory (PAGE 1) sections */.bss : > DRAM, PAGE = 1.ebss : > DRAM, PAGE = 1.stack : > DRAM, PAGE = 1.sysmem : > ZONE7B, PAGE = 1.esysmem : > ZONE7B, PAGE = 1/*** User Defined Sections ***/codestart : > BEGIN_FLASH, PAGE = 0 /* Used by file CodeStartBranch.as m */csm_rsvd : > CSM_RSVD, PAGE = 0 /* Used by file passwords.asm */ internalMemFuncs : > FLASH_PROGRAM, PAGE = 0 /* Used by file Xintf.c. Link to internal memory */passwords : > PASSWORDS, PAGE = 0 /* Used by file passwords.asm *//* Section secureRamFuncs used by file SysCtrl.c. */ramfuncs : LOAD = FLASH_PROGRAM, PAGE = 0 /* Should be Flash */RUN = ZONE7A, PAGE = 0 /* Must be CSM secured RAM */LOAD_START(_RamfuncsLoadStart),LOAD_END(_RamfuncsLoadEnd),RUN_START(_RamfuncsRunStart)/* Allocate ADC_cal function (pre-programmed by factory into TI reserved memory) */.adc_cal : load = ADC_CAL, PAGE = 0, TYPE = NOLOAD}/******************* end of file ************************/升级程序cmd文件/*********************************************************************** File: f28335_nonBIOS_flash.cmd -- Linker command file for non-DSP/BIOS* code with DSP in Boot to Flash boot mode.** History: 09/18/07 - original (D. Alter)**********************************************************************/MEMORY{PAGE 0: /* Program Memory */BEGIN_M0 : origin = 0x000000, length = 0x000002 /* Part of M0SARAM. Used for "Bo ot to M0" bootloader mode. */FLASH_PROGRAM : origin = 0x330000, length = 0x005000 /* On-chip FLASH G*/FLASH_PROGRAM1 : origin = 0x335000, length = 0x001000 /* On-chip FLASH G*/FLASH_CONST : origin = 0x336000, length = 0x001000 /* On-chip FLASH G*/ZONE7A : origin = 0x200000, length = 0x010000CSM_RSVD : origin = 0x33FF80, length = 0x000076 /* Part of FLASH Sector A. Reserve d when CSM is in use. */BEGIN_FLASH : origin = 0x33FFF6, length = 0x000002 /* Part of FLASH Sector A. Used fo r "Jump to flash" bootloader mode. */PASSWORDS : origin = 0x33FFF8, length = 0x000008 /* Part of FLASH Sector A. CSM p assword locations. */ADC_CAL : origin = 0x380080, length = 0x000009 /* ADC_cal function in Reserved me mory */OTP : origin = 0x380400, length = 0x000400 /* 1Kw OTP */IQTABLES : origin = 0x3FE000, length = 0x000B50 /* Part of Boot ROM */IQTABLES2 : origin = 0x3FEB50, length = 0x00008C /* Part of Boot ROM */FPUTABLES : origin = 0x3FEBDC, length = 0x0006A0 /* Part of Boot ROM */BOOTROM : origin = 0x3FF27C, length = 0x000D44 /* 8Kw Boot ROM */RESET : origin = 0x3FFFC0, length = 0x000002 /* part of Boot ROM */PAGE 1 : /* Data Memory */M0SARAM : origin = 0x000002, length = 0x0003FE /* 1Kw M0 SARAM */M1SARAM : origin = 0x000400, length = 0x000400 /* 1Kw M1 SARAM */DRAM : origin = 0x008000, length = 0x008000PIEVECT : origin = 0x000D00, length = 0x000100ZONE7B : origin = 0x210000, length = 0x010000//FLASH_DATA : origin = 0x330000, length = 0x008000 /* On-chip FLASH B*/}SECTIONS{Flash28_API:{-lFlash28335_API_V210.lib(.econst)-lFlash28335_API_V210.lib(.text)} LOAD = FLASH_PROGRAM1,RUN = ZONE7A,LOAD_START(_Flash28_API_LoadStart),LOAD_END(_Flash28_API_LoadEnd),RUN_START(_Flash28_API_RunStart),PAGE = 0/*** Compiler Required Sections ***//* Program memory (PAGE 0) sections */.text : > FLASH_PROGRAM, PAGE = 0.cinit : > FLASH_PROGRAM, PAGE = 0.const : > FLASH_PROGRAM, PAGE = 0.econst : > FLASH_CONST, PAGE = 0.pinit : > FLASH_PROGRAM, PAGE = 0.reset : > RESET, PAGE = 0, TYPE = DSECT /* We are not using the .reset secti on */.switch : > FLASH_PROGRAM, PAGE = 0.cio : > FLASH_PROGRAM, PAGE = 0/* Data Memory (PAGE 1) sections */.bss : > DRAM, PAGE = 1.ebss : > DRAM, PAGE = 1.stack : > DRAM, PAGE = 1.sysmem : > ZONE7B, PAGE = 1.esysmem : > ZONE7B, PAGE = 1/*** User Defined Sections ***/codestart : > BEGIN_FLASH, PAGE = 0 /* Used by file CodeStartBranch.as m */csm_rsvd : > CSM_RSVD, PAGE = 0 /* Used by file passwords.asm */ internalMemFuncs : > FLASH_PROGRAM, PAGE = 0 /* Used by file Xintf.c. Link to internal memory */passwords : > PASSWORDS, PAGE = 0 /* Used by file passwords.asm *//* Section secureRamFuncs used by file SysCtrl.c. */ramfuncs : LOAD = FLASH_PROGRAM, PAGE = 0 /* Should be Flash */RUN = ZONE7A, PAGE = 0 /* Must be CSM secured RAM */LOAD_START(_RamfuncsLoadStart),LOAD_END(_RamfuncsLoadEnd),RUN_START(_RamfuncsRunStart)/* Allocate ADC_cal function (pre-programmed by factory into TI reserved memory) */.adc_cal : load = ADC_CAL, PAGE = 0, TYPE = NOLOAD}/******************* end of file ************************/2、固定程序起始地址的方法为,codeStartBranch.asm的其实地址,即codestart的其实地址,这里使用.text1 : {DSP2833x_CodeStartBranch.obj(.text)}> FLASH_PROGRAMS, PAGE = 0.text2 : {*(.text)}> FLASH_PROGRAM, PAGE = 0详见主程序cmd文件描述。