typedef void (*pFunction)(void); pFunction Jump_To_Application; uint32_t JumpAddress; Boot_para_s boot_struct; static void Jump_To_App(void ) { if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000) { JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4); Jump_To_Application = (pFunction) JumpAddress; __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS); LocalPrintf("Jump To App... "); Jump_To_Application(); } LocalPrintf("not find app prj... "); } static void StoreSwitch(void) { uint8_t res = 0,tmp_data[1024]; uint32_t wr_size = 0,wr_addr, total_size; FeedWatchDog(); McuFlashRead(BOOT_PARA_CONFIG_ADDR,(uint8_t*)&boot_struct.uApp_UpDataFlg,sizeof(Boot_para_s)); if(boot_struct.uApp_UpDataFlg != VALID_VAL_DWORD_AA) { LocalPrintf("Not find updataflg "); goto jump_lab; } LocalPrintf("app updata size is %d bytes ", boot_struct.uApp_DataSize); if(boot_struct.uApp_DataSize > APPLICATION_FLASH_SIZE) { McuFlashErase(APPLICATION_UPDATE_ADDRESS,APPLICATION_FLASH_SIZE); BootParaInit(); goto jump_lab; } res = McuFlashErase(APPLICATION_ADDRESS,APPLICATION_FLASH_SIZE); if(!res) { goto jump_lab; } IRQ_DISABLE(); total_size = boot_struct.uApp_DataSize; wr_addr = 0; while(total_size > 0) { FeedWatchDog(); if(total_size >= 1024) { wr_size = 1024; } else { wr_size = total_size; } McuFlashRead(APPLICATION_UPDATE_ADDRESS+wr_addr,tmp_data,wr_size); res = McuFlashWrite(APPLICATION_ADDRESS+wr_addr,tmp_data,wr_size); if(!res) { LocalPrintf("app updata fail! "); break; } wr_addr += wr_size; total_size -= wr_size; LocalPrintf("app total size is %d ", total_size); } IRQ_ENABLE(); if(total_size == 0) { LocalPrintf("app updata OK! "); BootParaInit(); } jump_lab: FeedWatchDog(); }
/* USER CODE BEGIN Private defines */ #define IRQ_DISABLE() (__disable_irq()) #define IRQ_ENABLE() (__enable_irq()) #define VALID_VAL_DWORD_AA 0xAAAAAAAA #define INVALID_VAL_DWORD_55 0x55555555 /*编译宏*/ #define APP_VALID_FLG 0 //0:app1 1:app2 typedef struct { uint32_t uApp_UpDataFlg; uint32_t uApp_DataSize; }Boot_para_s; /* USER CODE END Private defines */
/*-------------------------------------------------------------------------- 0ooo ooo0 ( ) ( ) ) / ( (_/ \_) ----------------------------------------------------------------------------*/