编写BOOT程序,和APP程序。
BOOT程序检查OTA参数,执行OTA升级,然后跳转到APP代码。
记录一下跳转APP需要修改得东西:
1、BOOT程序 修改跳转地址
先检查APP地址是否有效
然后关闭外设 反初始化
设置MSP指针,进行跳转
/*** @brief Jump from boot to app function.* @param [in] u32Addr APP address* @retval LL_ERR APP address error*/
int32_t IAP_JumpToApp(uint32_t u32Addr)
{uint32_t u32StackTop = *((__IO uint32_t *)u32Addr);uint32_t JumpAddr;func_ptr_t JumpToApp;/* Check stack top pointer. */if ((u32StackTop > SRAM_BASE) && (u32StackTop <= (SRAM_BASE + 0x010000UL))) {IAP_PeriphDeinit();/* Jump to user application */JumpAddr = *(__IO uint32_t *)(u32Addr + 4U);JumpToApp = (func_ptr_t)JumpAddr;/* Initialize user application's Stack Pointer */__set_MSP(u32StackTop);JumpToApp();}return LL_ERR;
}
2、APP程序修改起始地址
修改VECT_TAB_OFFSET定义值 与BOOT对应
/*** @brief Setup the microcontroller system. Initialize the System and update* the SystemCoreClock variable.* @param None* @retval None*/
void SystemInit(void)
{/* FPU settings */
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)SCB->CPACR |= ((3UL << 20) | (3UL << 22)); /* set CP10 and CP11 Full Access */
#endifSystemCoreClockUpdate();
#if defined (ROM_EXT_QSPI)SystemInit_QspiMem();
#endif /* ROM_EXT_QSPI *//* Configure the Vector Table relocation */SCB->VTOR = VECT_TAB_OFFSET; /* Vector Table Relocation */
}
3、APP程序修改内存加载文件
如下图,如果不勾选该项,则要手动修改ACT文件的LR_IROM1区的起始地址和结束地址
如果勾选,则要在target选项中设置起始地址和结束地址
ACT文件一般格式:
; ****************************************************************
; Scatter-Loading Description File
; ****************************************************************
LR_IROM1 0x00004000 0x00040000 { ; load region size_regionER_IROM1 0x00004000 0x00040000 { ; load address = execution address*.o (RESET, +First)*(InRoot$$Sections).ANY (+RO).ANY (+XO)}RW_IRAM1 0x1FFF8000 UNINIT 0x00000008 { ; RW data*(.bss.noinit)}RW_IRAM2 0x1FFF8008 0x0000FFF8 { ; RW data.ANY (+RW +ZI).ANY (RAMCODE)}RW_IRAMB 0x200F0000 0x00001000 { ; RW data.ANY (+RW +ZI)}
}