|
Target board: C2000 28335/28069
I. Main ideas:
1. Prepare an upgrade program (equivalent to a bootloader) as the first program to run when powered on. Enter the upgrade program, first determine whether it needs to be upgraded, if it needs to be upgraded, enter the upgrade state, complete the communication, receive the new main program, store it, and after the upgrade is successful, enter the main program to run.
2. When the main program is running, receive the upgrade instruction, mark the upgrade flag, restart and enter the upgrade program to upgrade.
3. After the board is powered on, it will be adjusted to the starting address of flash startup 0x33FFF6 (DSP28335), which stores the actual address of the program codestart. Therefore, by modifying the value stored in 0x33FFF6, you can decide which section of the program to execute. You can also jump directly to the program codestart execution through the assembly jump instruction.
II. Upgrade Procedure
1. Capabilities: Communication capability and Flash reading and writing capability
2. Preparation: Flash API migration, host computer upgrade supporting program; space for storing upgrade flags (external EEPROM, internal Flash that will not be erased casually)
3. Process: Receive->Verify->Burn->Jump
3. Upgrade steps
1. Data reception: Receive data through CAN/serial port, etc. Since the 28335 memory is small, it is not suitable for caching a large amount of data. Here, a part of the data is received, and after verification, it is burned into the Flash, and then another part of the data is received.
2. Data parsing: The received data is in hex format, so it needs to be parsed before it can be put into the corresponding flash address. However, due to the limitation of 28335 capability, the upper computer is used to parse it first, and the data communication and transmission is completed by first informing the address and then sending the data.
3. Verification: CRC verification is used here.
/******************************************************
*Name : crc16
*Function: crc check 16 bits
*Params : data (UInt8 *): array to be operated len: data length
*Return : UInt16: return CRC value CRC check code is 2 bytes, high bit first
*******************************************************/
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. Data burning into flash: Use the reception provided by flash API to complete data burning. It should be noted that flash API must be run in RAM.
5. After the data is burned, you need to jump to the main program. Generally, assembly instructions are used. Assembly instructions asm ("LB 0xXXXXXX") or assembly functions.
Here, the asm method is used, and the jump address is the starting address of the new application. It must be stipulated here that the starting address of each new application must be fixed.
asm ("LB 0x3xxxxx");
If a variable starting address is used, an assembly function must be used and the address must be passed into the function as a parameter.
4. Main program
1. After receiving the upgrade command, it can mark the upgrade status. Restart to enter the upgrade program, make a judgment, and then upgrade the program.
2. After the main program is running, the upgrade status is marked as no upgrade required.
5. Notes
1. The upgrade program and the main program should be strictly separated, and the flash space should be allocated reasonably. The following is the approximate space allocation of the upgrade program and the main program cmd.
Main program cmd file
/***************************************************************************
* 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 "Boot 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 = 0x010000
CSM_RSVD : origin = 0x33FF80, length = 0x000076 /* Part of FLASH Sector A. Reserved when CSM is in use. */
BEGIN_FLASH : origin = 0x33FFF6, length = 0x000002 /* Part of FLASH Sector A. Used for "Jump to flash" bootloader mode. */
PASSWORDS : origin = 0x33FFF8, length = 0x000008 /* Part of FLASH Sector A. CSM password locations. */
ADC_CAL : origin = 0x380080, length = 0x000009 /* ADC_cal function in Reserved memory */
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 = 0x010000
PAGE 1 : /* Data Memory */
M0SARAM : origin = 0x000002, length = 0x0003FE /* 1Kw M0 SARAM */
M1SARAM : origin = 0x000400, length = 0x000400 /* 1Kw M1 SARAM */
DRAM : origin = 0x008000, length = 0x008000
PIEVECT : origin = 0x000D00, length = 0x000100
ZONE7B : origin = 0 x210000, 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 section */
.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.asm */
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 ************************/
Upgrade program cmd file
/************************************************ *************************
* 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 "Boot 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 = 0x010000
CSM_RSVD : origin = 0x33FF80, length = 0x000076 /* Part of FLASH Sector A. Reserved when CSM is in use. */
BEGIN_FLASH : origin = 0x33FFF6, length = 0x000002 /* Part of FLASH Sector A. Used for "Jump to flash" bootloader mode. */
PASSWORDS : origin = 0x33FFF8, length = 0x000008 /* Part of FLASH Sector A. CSM password locations. */
ADC_CAL : origin = 0x380080, length = 0x000009 /* ADC_cal function in Reserved memory */
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 = 0x008000
PIEVECT : origin = 0x000D00, length = 0x000100
ZONE7B : 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(_F lash28_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 section */
.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.asm */
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. The method to fix the program starting address is to use the actual address of codeStartBranch.asm, that is, the actual address of codestart. Here,
.text1 is used: {DSP2833x_CodeStartBranch.obj(.text)}> FLASH_PROGRAMS, PAGE = 0
.text2: {*(.text)}> FLASH_PROGRAM, PAGE = 0.
For details, see the main program cmd file description.
3. After the upgrade, the program will jump to the main program but cannot be executed, so a solution must be provided. Several solutions are provided here:
(1) After entering the main program, modify the upgrade flag.
(2) After starting the upgrade program, before entering the main program, leave a way to communicate with the host computer so that the upgrade mode can be entered again.
(3) After starting the upgrade program, a command must be received before jumping to the main program for execution.
|