app中重要代码
.c
//固件数据发送完成 User_Flash_Write(addr,(u8*)data,FLASH_PAGE_SIZE); addr=APP_BACK_ADDR_START; system_config.ota.have_new=1; system_config.ota.newFirmware_crc=*(__IO uint32_t *)(APP_BACK_ADDR_START+position-4); system_config.ota.newFirmware_size = position-4; reboot_s=2;
SYSTEM_DEBUG("重启rnsystem_config=%xrnnewFirmware_crc=%xrnnewFirmware_size=%xrn",system_config.ota.have_new,system_config.ota.newFirmware_crc,system_config.ota.newFirmware_size); HAL_NVIC_SystemReset();
.h
#define BOOT_SIZE (6*1024) //Boot区#define APP_SIZE (60*1024) //app备份区尺寸#define APP_BACKUP_SIZE (60*1024) //app备份区尺寸#define APP_ENTRY_ADDRESS (FLASH_base + BOOT_SIZE) //宏定义跳转app首地址#define APP_BACK_ADDR_START (FLASH_base + BOOT_SIZE + APP_SIZE)//app备份区首地址#define USER_FLASH_CONFIG_ADDR (FLASH_base+126*1024) // 最后2k作为参数保存区
引导区代码
.c
typedef void (*pFunction)(void);uint32_t JumpAddress;pFunction JumpToApplication;void JumpToApp(u32 address){if(((*(__IO uint32_t*)address) & 0x2FFE0000 ) == 0x20000000){ SYSTEM_DEBUG("start jump to app(0x%0x)....rn",address);//debug("jump to applicationrn");JumpAddress = *(__IO uint32_t*) (address + 4);__set_MSP(*(__IO uint32_t*) address);JumpToApplication = (pFunction) JumpAddress;JumpToApplication();}}
.h
#define BOOT_SIZE (6*1024) //Boot区#define APP_SIZE (60*1024) //app备份区尺寸#define APP_BACKUP_SIZE (60*1024) //app备份区尺寸#define APP_ENTRY_ADDRESS (FLASH_base + BOOT_SIZE) //宏定义跳转app首地址#define APP_BACK_ADDR_START (FLASH_base + BOOT_SIZE + APP_SIZE)//app备份区首地址#define USER_FLASH_CONFIG_ADDR (FLASH_base+126*1024) // 最后2k作为参数保存区