NXP

NXP LPC1788(ARM Cortex m3) IAP 带UcosII 完结 (1)

2019-07-12 11:25发布

    这篇文章写作QQ空间的,但是那个圈子没什么人懂,还是在这再写一遍     纠结很长时间的IAP终于解决了,写在此处备份一下,为要做IAP的省很大部分精力,升级不带Ucos的程序很容易,但是带了Ucos、EmWin等复杂的应用程序后跳转失败等,经过一番排查之后发现是堆栈地址不对,跑到了SDRAM的地址0xA02C4738中去了,至于为什么我也不知道,勾选了Keil中Options for Target中的Linker下面的Use Memory Layout form Target Dialog 后使用更据我们前面设定的Target中的Irom Iram等乱七八糟的分散加载而自动生成的SCT文件堆栈地址跑到0xA02XXXXX中,如果不把上述复杂程序做成APP的话其堆栈地址在片内RAM0x10000000地址开始处,而做成APP后点了,虽然我把SCT文件改成如下代码:
LR_IROM1 0x0000A000 0x00045FFF  {    ; load region size_region
  ER_IROM1 0x0000A000 0x00045FFF  {  ; load address = execution address    *.o (RESET, +First)    *(InRoot$$Sections)    .ANY (+RO)   }   RW_IRAM1 0x10000000 0x00010000  {  ; RW data    .ANY (+RW +ZI)   }   RW_RAM1 0xA0000000 UNINIT 0x02000000  {  ; RW data    * (VRAM, GUI_RAM, GUIDEMO_STACK)   } }
已经跟原来的Project.sct文件一样(不选Use Memory Layout form Target Dialog后 ),但是是不行的,此原因不知道为什么。 反正我们现在不点Use Memory Layout form Target Dialog ,并且打开Project.sct文件改成ROM从0xA000开始,IARM从0x10000000大小0x10000,RAM 0xA0000000 大小0x2000000(32MBSDRAM),即上述一段代码后就可以了。
上述解释了为什么跳转到IAP后运行不了的问题,也是各大论坛上询问无果的问题。

具体的IAP实现代码如下:
Bootloader部分:这段代码比较简单,也不要对Keil做特别的设置,就一普通工程
    跳转部分和MAIN
01 __asm void JMP_Boot( uint32_t address ) 02 { 03    LDR SP, [R0]                ;Load new stack pointer address 04    LDR PC, [R0, #4]          ;Load new program counter address 05 } 06 void Boot( void ) 07 { 08     SCB->VTOR = APP_START_SECTOR & 0x1FFFFF80;   09     JMP_Boot(APP_START_SECTOR); 10 } 11 int main(void) 12 { 13     CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCGPIO, ENABLE); 14     lpc1788_Uart_Init(0);       printf("uart0 init success! "); 15     lpc1788_SDRAM_Init();   16     lpc1788_Lcd_Init(); 17     LCD_test();     18     SysTick_Init(); 19     exfuns_init();              20     fs_test();  21     if(updata_num==1)     {LCD_ShowString(10,218,608,16,16,"Updata APP SUECCED!");updata_num=0;Boot();} 22     else              {LCD_ShowString(10,218,608,16,16,"Have not Updata APP!"); Boot();}  23     while(1); 24 } SD卡升级APP部分:
void fs_test(void) { FRESULT ceshi; char folder[255] = "";  uint32_t addr,ii; uint32_t u32Status; ceshi = (FRESULT)SD_Init();//³õʼ»¯SD¿¨£¬²¢°Ñ·µ»ØÖµ´«µÝ¸øceshi if(ceshi == FALSE)   {     printf("sd init error. ");     LCD_ShowString(10,26,200,16,16,"Has no SD found!");   } else  {   LCD_ShowString(10,26,608,16,16,"Press any key to updata system in 3S:");    WHITE);LCD_ShowString(320,26,200,16,16,"04S");Delay(1000);if(flag==1){flag=0;goto updata_APP;}  LCD_FillRectangle(LCD_PANEL_UPPER,320,352,26,74,WHITE);LCD_ShowString(320,26,200,16,16,"03S");Delay(1000);if(flag==1){flag=0;goto updata_APP;}  LCD_FillRectangle(LCD_PANEL_UPPER,320,352,26,74,WHITE);LCD_ShowString(320,26,200,16,16,"02S");Delay(1000);if(flag==1){flag=0;goto updata_APP;}  LCD_FillRectangle(LCD_PANEL_UPPER,320,352,26,74,WHITE);LCD_ShowString(320,26,200,16,16,"01S");Delay(1000);if(flag==1){flag=0;goto updata_APP;}  LCD_FillRectangle(LCD_PANEL_UPPER,320,352,26,74,WHITE);LCD_ShowString(320,26,200,16,16,"00S");Delay(1000);if(flag==1){flag=0;goto updata_APP;}  SysTick->CTRL=0;//¹Øµôϵͳ¶¨Ê±Æ÷·ÀÖ¹Ó°ÏìºóÃæ²Á³ý²Ù×÷ return; updata_APP:    SysTick->CTRL=0;    updata_num=1;    SystemCoreClockUpdate();    LCD_ShowString(10,42,200,16,16,"UpdataAPP:");LCD_FillRectangle(LCD_PANEL_UPPER,176,376,42,58,skyblue); ceshi = f_mount(&fs,"0:", 1);    if(ceshi != FR_OK){printf("f_mount error = %d ",ceshi);}        ceshi=f_open (&file, "UNIGBK.BIN", FA_READ);  RES_FALT(ceshi);        SIZE_UNIGBK=file.fsize;        printf(" UNIGBK.BIN ÎļþËùÕ¼´óС£º%d×Ö½Ú ",file.fsize);        ceshi=f_read(&file, UNIGBK, SIZE_UNIGBK, &br);RES_FALT(ceshi);        printf(" br µÄÖµ£º%d ",br);printf(" ");       f_close(&file);br=0;//////////////////////////////////////////////¹Ø±ÕÎļþ       LCD_FillRectangle (LCD_PANEL_UPPER,176,186,42,58,NavyBlue);   scan_files(folder);//±éÀúSD¿¨Îļþ   LCD_FillRectangle (LCD_PANEL_UPPER,186,190,42,58,NavyBlue);   __disable_irq();

  if ((u32IAP_PrepareSectors(10, 23) == IAP_STA_CMD_SUCCESS) &&(u32IAP_EraseSectors(10,23)==IAP_STA_CMD_SUCCESS))      {LCD_ShowString(10,58,200,16,16,"Erase Done!"); LCD_FillRectangle                 (LCD_PANEL_UPPER,190,200,42,58,NavyBlue);}  else {LCD_ShowString(10,58,200,16,16,"Erase FAILED!");return;}    __enable_irq();
 
ceshi=f_open (&file, "Timer.bin", FA_READ);  RES_FALT(ceshi); printf(" Application.binÎļþËùÕ¼´óС£º%d×Ö½Ú ",file.fsize);addr=0; for(ii=0;ii<((file.fsize)/512+1);ii++) { ceshi = f_read(&file, APP_CODE_ADDR, 512, &br); RES_FALT(ceshi);  __disable_irq();//NVIC_DisableIRQ(DMA_IRQn); if ((ceshi == FR_OK) || (br == 512)) { printf(" %d,%d ",br,ii); u32Status=u32IAP_PrepareSectors(10, 23);                                           printf(" PrepareSectors:%d ",u32Status); u32Status=u32IAP_CopyRAMToFlash(APP_START_SECTOR+addr,(uint32_t)APP_CODE_ADDR,512);printf(" CopyRAMToFlash:%d ",u32Status); addr += 512; LCD_FillRectangle (LCD_PANEL_UPPER,200,200+ii*176/((file.fsize)/512),42,58,NavyBlue); } __enable_irq();//NVIC_EnableIRQ(DMA_IRQn); }f_close(&file);br=0;   //SysTick_Init();NVIC_EnableIRQ(UART0_IRQn); NVIC_DisableIRQ(MCI_IRQn); __disable_irq();   }