BootLoader:
main里调用函数跳转到APP地址0x8003000
typedef void (*pFunction)(void);
#define ApplicationAddress 0x8003000
void UserAppStart(void)
{
if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)
{
/* Jump to user application */
JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
Jump_To_Application = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) ApplicationAddress);
Jump_To_Application();
}
}
APP:
main 函数添加
#define APPLICATION_ADDRESS ((uint32_t)0x08003000)
#if (defined ( __CC_ARM ))
__IO uint32_t VectorTable[48] __attribute__((at(0x20000000)));
#elif (defined (__ICCARM__))
#pragma location = 0x20000000
__no_init __IO uint32_t VectorTable[48];
#elif defined ( __GNUC__ )
__IO uint32_t VectorTable[48] __attribute__((section(".RAMVectorTable")));
#elif defined ( __TASKING__ )
__IO uint32_t VectorTable[48] __at(0x20000000);
#endif
/* USER CODE BEGIN 1 */
uint32_t i = 0;
/* Relocate by software the vector table to the internal SRAM at 0x20000000 ***/
/* Copy the vector table from the Flash (mapped at the base of the application
load address 0x08003000) to the base address of the SRAM at 0x20000000. */
for(i = 0; i < 48; i++)
{
VectorTable[i] = *(__IO uint32_t*)(APPLICATION_ADDRESS + (i<<2));
}
// Enable the SYSCFG peripheral clock
__HAL_RCC_SYSCFG_CLK_ENABLE();
// Remap SRAM at 0x00000000
__HAL_SYSCFG_REMAPMEMORY_SRAM();
stm32f0 没有中断偏移寄存器,所以将中断向量表读取到RAM中,然后重映射到RAM地址.
参考:
http://bbs.21ic.com/icview-571430-1-1.html (5L&10L)
http://bbs.21ic.com/icview-822770-1