这套SD IAP程序可以升级一些不带中断的和串口中断的程序,但是稍微复杂一些比如SD卡FATFS和带Ucos的就不行了,调试很久无果
mian.c:
[mw_shl_code=c,true]__asm void JMP_Boot( uint32_t address )
{
LDR SP, [R0] ;Load new stack pointer address
LDR PC, [R0, #4] ;Load new program counter address
}
void Boot( void )
{
SCB->VTOR = APP_START_SECTOR & 0x1FFFFF80;
JMP_Boot(APP_START_SECTOR);
}
int main(void)
{
CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCGPIO, ENABLE);
lpc1788_Uart_Init(0); printf("uart0 init success!\n\r");
lpc1788_SDRAM_Init();
lpc1788_Lcd_Init();
LCD_test();
SysTick_Init();
exfuns_init();
fs_test();
if(updata_num==1) {LCD_ShowString(10,218,608,16,16,"Updata APP SUECCED!");updata_num=0;Boot();}
else {LCD_ShowString(10,218,608,16,16,"Have not Updata APP!"); Boot();}
while(1);
}
[/mw_shl_code]
SD 卡升级部分:
[mw_shl_code=c,true]void fs_test(void)
{
FRESULT ceshi;
char folder[255] = "";
uint32_t addr,ii;
uint32_t u32Status;
ceshi = (FRESULT)SD_Init()
if(ceshi == FALSE)
{
printf("sd init error.\n\r");
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:");
// LCD_FillRectangle (LCD_PANEL_UPPER, 320,352,26,74, WHITE);LCD_ShowString(320,26,200,16,16,"10S");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,"09S");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,"08S");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,"07S");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,"06S");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,"05S");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,"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:
updata_num=1;
SystemCoreClockUpdate();
LCD_ShowString(10,42,200,16,16,"Updata APP:");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\n\r",ceshi);}
ceshi=f_open (&file, "UNIGBK.BIN", FA_READ); RES_FALT(ceshi);
SIZE_UNIGBK=file.fsize;
printf("\n UNIGBK.BIN ?????ù???ó????%d×??? \n",file.fsize);
ceshi=f_read(&file, UNIGBK, SIZE_UNIGBK, &br); RES_FALT(ceshi);
printf("\nbr ??????%d\n",br);printf("\n");
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, 21) == IAP_STA_CMD_SUCCESS) &&(u32IAP_EraseSectors (10, 21) == 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, "V002.bin", FA_READ); RES_FALT(ceshi);
printf("\n V002.bin?????ù???ó????%d×??? \n\r",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("\n %d,%d ",br,ii);
u32Status=u32IAP_PrepareSectors(10, 21); printf(" PrepareSectors:%d ",u32Status);
u32Status=u32IAP_CopyRAMToFlash(APP_START_SECTOR+addr,(uint32_t)APP_CODE_ADDR,512);printf(" CopyRAMToFlash:%d \n\r",u32Status);
addr += 512;
LCD_FillRectangle (LCD_PANEL_UPPER,200,200+ii*176/((file.fsize)/512),42,58,NavyBlue);
}
__enable_irq();
}f_close(&file);br=0;
NVIC_DisableIRQ(MCI_IRQn);
__disable_irq();
}
return;
}[/mw_shl_code]
|