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("重启\r\nsystem_config=%x\r\nnewFirmware_crc=%x\r\nnewFirmware_size=%x\r\n",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)....\r\n",address);
/* Jump to user application */
//debug("jump to application\r\n");
JumpAddress = *(__IO uint32_t*) (address + 4);
/* Initialize user application's Stack Pointer */
__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作为参数保存区
版权声明:本文为weixin_44439612原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。