BOOT工程
分配BOOT程序地址、设置参数地址、APP程序地址、下载缓冲区地址
#define BOOT_SECTOR_ADDR 0x08000000
#define BOOT_SECTOR_SIZE 0x0000A000
#define SETTING_SECTOR_ADDR 0x0800A000
#define SETTING_SECTOR_SIZE 0x00002000
#define APP_SECTOR_ADDR 0x0800E000
#define APP_SECTOR_SIZE 0x00019000
#define DOWNLOAD_SECTOR_ADDR 0x08027000
#define DOWNLOAD_SECTOR_SIZE 0x00019000
程序跳转函数
uint16_t JumpToApp(void)
{
void (*SysJumpToApp)(void); /* 声明一个函数指针 */
__IO uint32_t AppAddr = APP_SECTOR_ADDR; /* STM32的系统BootLoader地址 */
if (((*(__IO uint32_t * )AppAddr) & MSP_MASK ) == 0x20000000) /*检测MSP是否在内存地址内 */
{
/* 跳转到系统App,首地址是MSP,地址+4是复位中断服务程序地址 */
SysJumpToApp = (void (*)(void)) (*((uint32_t *) (AppAddr + 4)));
/* 设置主堆栈指针 */
__set_MSP(*(__IO uint32_t *)AppAddr);
/* 跳转到系统App */
SysJumpToApp();
}
/* 跳转成功的话,不会执行到这里,用户可以在这里添加代码 */
while (1)
{
}
}
ROM地址及大小设置
代码优化等级设置
JLINK设置内FLASH下载地址设置
APP工程
中断向量表偏移地址修改
#define USER_VECT_TAB_ADDRESS
#if defined(USER_VECT_TAB_ADDRESS)
/*!< Uncomment the following line if you need to relocate your vector Table
in Sram else user remap will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM1_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x0000E000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x0000E000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */