欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

OTA功能代码

时间:2023-06-01

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作为参数保存区

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。