dsp 28377在线升级 实例总结

来源:互联网 发布:决战武林进阶数据弩炮 编辑:程序博客网 时间:2024/06/07 03:38

使用dsp品台28377d来实现在线升级的功能。


方案 : 升级程序  +  应用程序


升级程序 : 主要的目的是将上位机发送过来的应用程序数据(ccs编译生成的.bin文件)烧写到指定位置,之后在跳转到应用程序执行。


应用程序 : 等待升级的程序



//-------------------------------------------------------------------------------------------------------------------------------------------------------------------

升级代码段 :


flash_programming_cpu01.c1 //#########################################################################2 // FILE: flash_programming_cpu01.c3 // TITLE: Flash Programming Example for F2837xD.4 //5 //! \addtogroup dual_example_list6 //! <h1> Flash Programming </h1>7 //!8 //! This example demonstrates F021 Flash API usage.9 //10 //#########################################################################11 // $TI Release: F2837xD Support Library v170 $12 // $Release Date: Mon Sep 21 16:52:10 CDT 2015 $13 // $Copyright: Copyright (C) 2013-2015 Texas Instruments Incorporated -14 // http://www.ti.com/ ALL RIGHTS RESERVED $15 //#########################################################################1617 #include "F28x_Project.h" // Device Headerfile and Examples IncludeFile18 #include "F2837xD_Ipc_drivers.h"1920 #include <string.h>2122 //Include Flash API example header file23 #include "flash_programming_c28.h"2425 #define ENTRYADDR 0x880002627 extern void lightflash(void);2829 //*************************************************************************30 // FILE Flash API include file31 //*************************************************************************32 #include "F021_F2837xD_C28x.h"3334 //Data/Program Buffer used for testing the flash API functions35 #define WORDS_IN_FLASH_BUFFER 3608 // Programming data buffer, words3637 uint16 Buffer[WORDS_IN_FLASH_BUFFER + 1];38 uint32 *Buffer32 = (uint32 *)Buffer;3940 #pragma DATA_SECTION(pbuffer , "PDATASAVE");41 uint16 pbuffer[WORDS_IN_FLASH_BUFFER]= {42 #include "P_DATA.h"43 };4445 //*************************************************************************46 // Prototype of the functions used in this example47 //*************************************************************************48 void Example_CallFlashAPI(void);4950 //*************************************************************************51 // This is an example code demonstrating F021 Flash API usage.52 // This code is in Flash53 //*************************************************************************54 void main(void)55 {56 // Step 1. Initialize System Control:57 // Enable Peripheral Clocks58 // This example function is found in the F2837xD_SysCtrl.c file.59 InitSysCtrl();6061 IPCBootCPU2(C1C2_BROM_BOOTMODE_BOOT_FROM_FLASH);6263 InitGpio();6465 InitPieCtrl();6667 IER = 0x0000;68 IFR = 0x0000;6970 InitPieVectTable();7172 EINT; // Enable Global interrupt INTM7374 // Jump to RAM and call the Flash API functions75 Example_CallFlashAPI();7677 DELAY_US(100000);7879 static void (*APPEntry)(void);8081 APPEntry = (void (*)(void))(ENTRYADDR);8283 ESTOP0;8485 (*APPEntry)();8687 while(1);8889 }9091 //*************************************************************************92 // Example_CallFlashAPI93 //94 // This function will interface to the flash API.95 // Flash API functions used in this function are executed from RAM96 //*************************************************************************97 #pragma CODE_SECTION(Example_CallFlashAPI , "ramfuncs");98 void Example_CallFlashAPI(void)99 {100 uint32 u32Index = 0;101 uint16 i = 0;102103 Fapi_StatusType oReturnCheck;104 volatile Fapi_FlashStatusType oFlashStatus;105106 // Gain pump semaphore107 SeizeFlashPump();108109 EALLOW;110 Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0x0;111 EDIS;112113 EALLOW;114115 oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 200);//for now keeping it out116117 if(oReturnCheck != Fapi_Status_Success)118 {119 // Check Flash API documentation for possible errors120 while(1);121 }122123 oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);124 if(oReturnCheck != Fapi_Status_Success)125 {126 // Check Flash API documentation for possible errors127 while(1);128 }129130 oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,131 (uint32 *)ENTRYADDR);132133 while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}134135 // In this case just fill a buffer with data to program into the flash.136 for(i=0, u32Index = ENTRYADDR;137138 (u32Index < (ENTRYADDR + WORDS_IN_FLASH_BUFFER))&& (oReturnCheck ==Fapi_Status_Success);139140 i=i+1, u32Index = u32Index + 1)141 {142 oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index,&pbuffer[i],143 1,144 0,145 0,146 Fapi_DataOnly);147148 while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);149150 if(oReturnCheck != Fapi_Status_Success)151 {152 // Check Flash API documentation for possible errors153 while(1);154 }155156 // Read FMSTAT register contents to know the status of FSM after157 // program command for any debug158 oFlashStatus = Fapi_getFsmStatus();159 }160161 // Leave control over flash pump162 ReleaseFlashPump();163 }


第98行的函数 :

Example_CallFlashAPI(void)

将数据烧写到地址为0x88000地址为首地址的flash内存当中。并且函数在ramfunc中运行,ramfunc和首地址的跳转在cmd文件中有体现


2837xD_FLASH_lnk_cpu1.cmdMEMORY3 {4 PAGE 0 : /* Program Memory */5 /* Memory (RAM/FLASH) blocks can be moved to PAGE1 for dataallocation */6 /* BEGIN is used for the "boot to Flash" bootloader mode */78BEGIN : origin = 0x080000, length = 0x0000029 RAMM0 : origin = 0x000122, length = 0x0002DE10 RAMD0 : origin = 0x00B000, length = 0x00080011 RAMLS0 : origin = 0x008000, length = 0x00080012 RAMLS1 : origin = 0x008800, length = 0x00080013 RAMLS2 : origin = 0x009000, length = 0x00080014 RAMLS3 : origin = 0x009800, length = 0x00080015 RAMLS4 : origin = 0x00A000, length = 0x00080016 RAMGS14 : origin = 0x01A000, length = 0x00100017 RAMGS15 : origin = 0x01B000, length = 0x00100018 RESET : origin = 0x3FFFC0, length = 0x0000021920 /* Flash sectors */21 FLASHA : origin = 0x080002, length = 0x001FFE /* on-chipFlash */22 FLASHB : origin = 0x082000, length = 0x002000 /* on-chipFlash */23 FLASHC : origin = 0x084000, length = 0x002000 /* on-chipFlash */24 FLASHD : origin = 0x086000, length = 0x002000 /* on-chipFlash */25 FLASHE : origin = 0x088000, length = 0x008000 /* on-chipFlash */26 FLASHF : origin = 0x090000, length = 0x008000 /* on-chipFlash */27 FLASHG : origin = 0x098000, length = 0x008000 /* on-chipFlash */28 FLASHH : origin = 0x0A0000, length = 0x008000 /* on-chipFlash */29 FLASHI : origin = 0x0A8000, length = 0x008000 /* on-chipFlash */30 FLASHJ : origin = 0x0B0000, length = 0x008000 /* on-chipFlash */31 FLASHK : origin = 0x0B8000, length = 0x002000 /* on-chipFlash */32 FLASHL : origin = 0x0BA000, length = 0x002000 /* on-chipFlash */33 FLASHM : origin = 0x0BC000, length = 0x002000 /* on-chipFlash */34 FLASHN : origin = 0x0BE000, length = 0x002000 /* on-chipFlash */36 PAGE 1 : /* Data Memory */37 /* Memory (RAM/FLASH) blocks can be moved to PAGE0 for programallocation */3839 BOOT_RSVD : origin = 0x000002, length = 0x000120 /* Part ofM0, BOOT rom will use this for stack */40 RAMM1 : origin = 0x000400, length = 0x000400 /* on-chipRAM block M1 */41 RAMD1 : origin = 0x00B800, length = 0x0008004243 RAMLS5 : origin = 0x00A800, length = 0x0008004445 RAMGS0 : origin = 0x00C000, length = 0x00100046 RAMGS1 : origin = 0x00D000, length = 0x00100047 RAMGS2 : origin = 0x00E000, length = 0x00100048 RAMGS3 : origin = 0x00F000, length = 0x00100049 RAMGS4 : origin = 0x010000, length = 0x00100050 RAMGS5 : origin = 0x011000, length = 0x00100051 RAMGS6 : origin = 0x012000, length = 0x00100052 RAMGS7 : origin = 0x013000, length = 0x00100053 RAMGS8 : origin = 0x014000, length = 0x00100054 RAMGS9 : origin = 0x015000, length = 0x00100055 RAMGS10 : origin = 0x016000, length = 0x00100056 RAMGS11 : origin = 0x017000, length = 0x00100057 RAMGS12 : origin = 0x018000, length = 0x00100058 RAMGS13 : origin = 0x019000, length = 0x001000596061 CPU2TOCPU1RAM : origin = 0x03F800, length = 0x00040062 CPU1TOCPU2RAM : origin = 0x03FC00, length = 0x00040063 }646566 SECTIONS67 {68 /* Allocate program areas: */69 .cinit : > FLASHB PAGE = 0, ALIGN(4)70 .pinit : > FLASHB, PAGE = 0, ALIGN(4)71 .text : >> FLASHB | FLASHC | FLASHD PAGE = 0,ALIGN(4)72 codestart : > BEGIN PAGE = 0, ALIGN(4)73 ramfuncs : LOAD = FLASHD,74 RUN = RAMLS0 | RAMLS1 | RAMLS2 |RAMLS3,75 LOAD_START(_RamfuncsLoadStart),76 LOAD_SIZE(_RamfuncsLoadSize),77 LOAD_END(_RamfuncsLoadEnd),78 RUN_START(_RamfuncsRunStart),79 RUN_SIZE(_RamfuncsRunSize),80 RUN_END(_RamfuncsRunEnd),81 PAGE = 0, ALIGN(4)8283 /* Allocate uninitalized data sections: */84 .stack : > RAMM1 PAGE = 185 .ebss : >> RAMLS5 | RAMGS0 | RAMGS1 PAGE = 186 .esysmem : > RAMLS5 PAGE = 18788 /* Initalized sections go in Flash */89 .econst : >> FLASHF | FLASHG | FLASHH PAGE = 0,ALIGN(4)90 .switch : > FLASHB PAGE = 0, ALIGN(4)9192 .reset : > RESET, PAGE = 0, TYPE = DSECT /* not used,*/9394 Filter_RegsFile : > RAMGS0, PAGE = 19596 SHARERAMGS0 : > RAMGS0, PAGE = 197 SHARERAMGS1 : > RAMGS1, PAGE = 198 ramgs0 : > RAMGS0, PAGE = 199 ramgs1 : > RAMGS1, PAGE = 1100101 #ifdef __TI_COMPILER_VERSION102 #if __TI_COMPILER_VERSION >= 15009000103 .TI.ramfunc : {} LOAD = FLASHD,104 RUN = RAMLS0 | RAMLS1 | RAMLS2 |RAMLS3,105 LOAD_START(_RamfuncsLoadStart),106 LOAD_SIZE(_RamfuncsLoadSize),107 LOAD_END(_RamfuncsLoadEnd),108 RUN_START(_RamfuncsRunStart),109 RUN_SIZE(_RamfuncsRunSize),110 RUN_END(_RamfuncsRunEnd),111 PAGE = 0, ALIGN(4)112 #endif113 #endif114115 /* The following section definitions are required when using the IPC API Drivers */116 GROUP : > CPU1TOCPU2RAM, PAGE = 1117 {118 PUTBUFFER119 PUTWRITEIDX120 GETREADIDX121 }122123 GROUP : > CPU2TOCPU1RAM, PAGE = 1124 {125 GETBUFFER : TYPE = DSECT126 GETWRITEIDX : TYPE = DSECT127 PUTREADIDX : TYPE = DSECT128 }129130 /* The following section definition are for SDFM examples */131 Filter1_RegsFile : > RAMGS1, PAGE = 1, fill=0x1111132 Filter2_RegsFile : > RAMGS2, PAGE = 1, fill=0x2222133 Filter3_RegsFile : > RAMGS3, PAGE = 1, fill=0x3333134 Filter4_RegsFile : > RAMGS4, PAGE = 1, fill=0x4444135 Difference_RegsFile : >RAMGS5, PAGE = 1, fill=0x3333136 PDATASAVE : > RAMGS0 , PAGE = 1137138 }139140 /*141 //===========================================================================142 // End of file.143 //===========================================================================144 */145




应用程序代码如下所示 :

blinky_cpu01.c1 //#########################################################################2 // FILE: blinky_cpu01.c3 // TITLE: LED Blink Example for F2837xD.4 //5 //! \addtogroup cpu01_example_list6 //! <h1> Blinky </h1>7 //!8 //! This example blinks LED X9 //10 //#########################################################################11 // $TI Release: F2837xD Support Library v180 $12 // $Release Date: Fri Nov 6 16:19:46 CST 2015 $13 // $Copyright: Copyright (C) 2013-2015 Texas Instruments Incorporated -14 // http://www.ti.com/ ALL RIGHTS RESERVED $15 //#########################################################################1617 #include "F28x_Project.h" // Device Headerfile and Examples IncludeFile18 #include <string.h>1920 Uint16 test = 0;2122 //void setup_emif1_pinmux_async_16bit(Uint16 cpu_sel);23 //***************************************************************24 //usart initial block25 //***************************************************************26 void UsartInit(void)27 {28 GPIO_SetupPinMux(28, GPIO_MUX_CPU1, 1);29 GPIO_SetupPinOptions(28, GPIO_INPUT, GPIO_PUSHPULL);30 GPIO_SetupPinMux(29, GPIO_MUX_CPU1, 1);31 GPIO_SetupPinOptions(29, GPIO_OUTPUT, GPIO_ASYNC);3233 //---- USART configuration ----------34 SciaRegs.SCIFFTX.all=0xE040;35 SciaRegs.SCIFFRX.all=0x2044;36 SciaRegs.SCIFFCT.all=0x0;3738 SciaRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback39 // No parity,8 char bits,40 // async mode, idle-line protocol41 SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,42 // Disable RX ERR, SLEEP, TXWAKE43 SciaRegs.SCICTL2.all =0x0003;44 SciaRegs.SCICTL2.bit.TXINTENA =1;45 SciaRegs.SCICTL2.bit.RXBKINTENA =1;46 SciaRegs.SCIHBAUD.all =0x0002;Page 1blinky_cpu01.c47 SciaRegs.SCILBAUD.all =0x008B;48 // SciaRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back49 SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset5051 //-DMA configuration52 }5354 //***************************************************************55 //usart UsartSendData block56 //just fit for 8 bit data to send57 //***************************************************************58 void UsartSendData(uint16_t data_in)59 {60 SciaRegs.SCITXBUF.all = data_in;61 while(SciaRegs.SCIFFTX.bit.TXFFST !=0); // wait for RRDY/RXFFST =1 fordata available in FIFO62 }636465 void main(void)66 {67 InitSysCtrl();6869 InitGpio();7071 DINT;7273 InitPieCtrl();7475 // Disable CPU interrupts and clear all CPU interrupt flags:76 IER = 0x0000;77 IFR = 0x0000;7879 InitPieVectTable();8081 EINT; // Enable Global interrupt INTM8283 UsartInit();848586 EALLOW;87 GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 0;88 GpioCtrlRegs.GPADIR.bit.GPIO10 = 1;89 EDIS;9091 GpioDataRegs.GPADAT.bit.GPIO10 = 0;9293 while(1){9495 GpioDataRegs.GPADAT.bit.GPIO10 = 0;9697 DELAY_US(50000);9899 GpioDataRegs.GPADAT.bit.GPIO10 = 1;100101 DELAY_US(50000);102103 if(test == 255) test = 0;104105 test = test + 1;106107 UsartSendData(test);108109 DELAY_US(1000);110 }123 }124

应用程序在调试的时候出现了一个问题 :

就是在在线调试的过程中,从升级程序跳转到应用程序的时候:

static void (*APPEntry)(void);8081 APPEntry = (void (*)(void))(ENTRYADDR);8283 ESTOP0;8485 (*APPEntry)();

进入应用程序,应用程序总是会在一些地方跳转到异常中断,最后找问题找到是在应用程序中的IntiFlash()函数,屏蔽掉该函数就正常啦。


IntiFlash()函数是嵌入到InitSysCtrl();中,就是应用程序最开始调用的那个函数。


2837xD_FLASH_lnk_cpu1.cmd12MEMORY3 {4 PAGE 0 : /* Program Memory */5 /* Memory (RAM/FLASH) blocks can be moved to PAGE1 for data allocation */6 /* BEGIN is used for the "boot to Flash" bootloader mode */78BEGIN : origin = 0x088000, length = 0x0000029 RAMM0 : origin = 0x000122, length = 0x0002DE10 RAMD0 : origin = 0x00B000, length = 0x00080011 RAMLS0 : origin = 0x008000, length = 0x00080012 RAMLS1 : origin = 0x008800, length = 0x00080013 RAMLS2 : origin = 0x009000, length = 0x00080014 RAMLS3 : origin = 0x009800, length = 0x00080015 RAMLS4 : origin = 0x00A000, length = 0x00080016 RAMGS14 : origin = 0x01A000, length = 0x00100017 RAMGS15 : origin = 0x01B000, length = 0x00100018 RESET : origin = 0x3FFFC0, length = 0x0000021920 /* Flash sectors */21 FLASHA : origin = 0x080002, length = 0x001FFE /* on-chipFlash */22 FLASHB : origin = 0x082000, length = 0x002000 /* on-chipFlash */23 FLASHC : origin = 0x084000, length = 0x002000 /* on-chipFlash */24 FLASHD : origin = 0x086000, length = 0x002000 /* on-chipFlash */25 FLASHE : origin = 0x088002, length = 0x007FFE /* on-chipFlash */26 FLASHF : origin = 0x090000, length = 0x008000 /* on-chipFlash */27 FLASHG : origin = 0x098000, length = 0x008000 /* on-chipFlash */28 FLASHH : origin = 0x0A0000, length = 0x008000 /* on-chipFlash */29 FLASHI : origin = 0x0A8000, length = 0x008000 /* on-chipFlash */30 FLASHJ : origin = 0x0B0000, length = 0x008000 /* on-chipFlash */31 FLASHK : origin = 0x0B8000, length = 0x002000 /* on-chipFlash */32 FLASHL : origin = 0x0BA000, length = 0x002000 /* on-chipFlash */33 FLASHM : origin = 0x0BC000, length = 0x002000 /* on-chipFlash */34 FLASHN : origin = 0x0BE000, length = 0x002000 /* on-chipFlash */35Page 12837xD_FLASH_lnk_cpu1.cmd36 PAGE 1 : /* Data Memory */37 /* Memory (RAM/FLASH) blocks can be moved to PAGE0 for programallocation */3839 BOOT_RSVD : origin = 0x000002, length = 0x000120 /* Part ofM0, BOOT rom will use this for stack */40 RAMM1 : origin = 0x000400, length = 0x000400 /* on-chipRAM block M1 */41 RAMD1 : origin = 0x00B800, length = 0x0008004243 RAMLS5 : origin = 0x00A800, length = 0x0008004445 RAMGS0 : origin = 0x00C000, length = 0x00100046 RAMGS1 : origin = 0x00D000, length = 0x00100047 RAMGS2 : origin = 0x00E000, length = 0x00100048 RAMGS3 : origin = 0x00F000, length = 0x00100049 RAMGS4 : origin = 0x010000, length = 0x00100050 RAMGS5 : origin = 0x011000, length = 0x00100051 RAMGS6 : origin = 0x012000, length = 0x00100052 RAMGS7 : origin = 0x013000, length = 0x00100053 RAMGS8 : origin = 0x014000, length = 0x00100054 RAMGS9 : origin = 0x015000, length = 0x00100055 RAMGS10 : origin = 0x016000, length = 0x00100056 RAMGS11 : origin = 0x017000, length = 0x00100057 RAMGS12 : origin = 0x018000, length = 0x00100058 RAMGS13 : origin = 0x019000, length = 0x001000596061 CPU2TOCPU1RAM : origin = 0x03F800, length = 0x00040062 CPU1TOCPU2RAM : origin = 0x03FC00, length = 0x00040063 }646566 SECTIONS67 {68 /* Allocate program areas: */69 .cinit : > FLASHE PAGE = 0, ALIGN(4)70 .pinit : > FLASHE, PAGE = 0, ALIGN(4)71 .text : >> FLASHE PAGE = 0, ALIGN(4)72 codestart : > BEGIN PAGE = 0, ALIGN(4)73 ramfuncs : LOAD = FLASHE,74 RUN = RAMLS0 | RAMLS1 | RAMLS2 |RAMLS3,75 LOAD_START(_RamfuncsLoadStart),76 LOAD_SIZE(_RamfuncsLoadSize),77 LOAD_END(_RamfuncsLoadEnd),78 RUN_START(_RamfuncsRunStart),79 RUN_SIZE(_RamfuncsRunSize),80 RUN_END(_RamfuncsRunEnd),81 PAGE = 0, ALIGN(4)8283 /* Allocate uninitalized data sections: */84 .stack : > RAMM1 PAGE = 185 .ebss : >> RAMLS5 | RAMGS0 | RAMGS1 PAGE = 186 .esysmem : > RAMLS5 PAGE = 18788 /* Initalized sections go in Flash */89 .econst : >> FLASHE PAGE = 0, ALIGN(4)90 .switch : > FLASHE PAGE = 0, ALIGN(4)9192 .reset : > RESET, PAGE = 0, TYPE = DSECT /* not used,*/9394 Filter_RegsFile : > RAMGS0, PAGE = 19596 SHARERAMGS0 : > RAMGS0, PAGE = 197 SHARERAMGS1 : > RAMGS1, PAGE = 198 ramgs0 : > RAMGS0, PAGE = 199 ramgs1 : > RAMGS1, PAGE = 1100101 #ifdef __TI_COMPILER_VERSION102 #if __TI_COMPILER_VERSION >= 15009000103 .TI.ramfunc : {} LOAD = FLASHE,104 RUN = RAMLS0 | RAMLS1 | RAMLS2 |RAMLS3,105 LOAD_START(_RamfuncsLoadStart),106 LOAD_SIZE(_RamfuncsLoadSize),107 LOAD_END(_RamfuncsLoadEnd),108 RUN_START(_RamfuncsRunStart),109 RUN_SIZE(_RamfuncsRunSize),110 RUN_END(_RamfuncsRunEnd),111 PAGE = 0, ALIGN(4)112 #endif113 #endif114115 /* The following section definitions are required when using the IPC APIDrivers */116 GROUP : > CPU1TOCPU2RAM, PAGE = 1117 {118 PUTBUFFER119 PUTWRITEIDX120 GETREADIDX121 }122123 GROUP : > CPU2TOCPU1RAM, PAGE = 1124 {125 GETBUFFER : TYPE = DSECT126 GETWRITEIDX : TYPE = DSECT127 PUTREADIDX : TYPE = DSECT128 }129130 /* The following section definition are for SDFM examples */131 Filter1_RegsFile : > RAMGS1, PAGE = 1, fill=0x1111132 Filter2_RegsFile : > RAMGS2, PAGE = 1, fill=0x2222133 Filter3_RegsFile : > RAMGS3, PAGE = 1, fill=0x3333134 Filter4_RegsFile : > RAMGS4, PAGE = 1, fill=0x4444135 Difference_RegsFile : >RAMGS5, PAGE = 1, fill=0x3333136137 }138139 /*140 //===========================================================================141 // End of file.142 //===========================================================================143 */144

升级程序完成,可用




1 0
原创粉丝点击