因为F0没有网上大家常用的设置vector的方式。
无意中在芯片参考手册中发现了如下的说明
Physical remap
Once the boot mode is selected, the application software can modify the memory accessible in the code area. This modification is performed by programming the MEM_MODE bits in
the SYSCFG configuration register 1 (SYSCFG_CFGR1). Unlike Cortex® M3 and M4, the
M0 CPU does not support the vector table relocation. For application code which is located in a different address than 0x0800 0000, some additional code must be added in order to be able to serve the application interrupts. A solution will be to relocate by software the vector
table to the internal SRAM:
• Copy the vector table from the Flash (mapped at the base of the application load address) to the base address of the SRAM at 0x2000 0000.
• Remap SRAM at address 0x0000 0000, using SYSCFG configuration register 1.
• Then once an interrupt occurs, the Cortex®-M0 processor will fetch the interrupt
handler start address from the relocated vector table in SRAM, then it will jump to
execute the interrupt handler located in the Flash. This operation should be done at the initialization phase of the application. Please refer to
AN4065 and attached IAP code from www.st.com for more details.
所以我用如下方式重定义中断向量表到SRAM,这个函数是可以直接用到CUBE生成的HAL库的stm32f0程序里面的。
#define ApplicationAddress ((uint32_t)0x08002000) //APP程序起始地址,根据你实际情况填写
void APP_SetVectorTable(void)
{
uint8_t i;
uint32_t *pVecTab=(uint32_t *)(0x20000000);
//复制中断向量表到SRAM首地址
for(i = 0; i < 48; i++)
{
*(pVecTab++) = *(__IO uint32_t*)(ApplicationAddress + (i<<2));
}
//开启 SYSCFG 时钟
__HAL_RCC_SYSCFG_CLK_ENABLE();
//重映射 SRAM 地址到 0x00000000
__HAL_SYSCFG_REMAPMEMORY_SRAM();
}
上面的APP_SetVectorTable()函数是写在APP程序里面的首先在main中调用的,不是写在boot里面。
APP keil中内存地址的设置,参考下图芯片stm32f072c8的
总结:
我的地址32K内存,4K RAM
APP中,
start: 0x8001400 size: 0x6C00 1400+6C00=32K
start: 0x200000C0 size: 0x1740 C0+1740=1800=6K
上面的C0是192,是4倍48,因为M0有48个中断向量。这个地址要空出来。
参考连接:
1, http://www.stmcu.org.cn/module/forum/forum.php?mod=viewthread&tid=606108&highlight=f0%2Biap
2, http://www.stmcu.org.cn/module/forum/forum.php?mod=viewthread&tid=599964&highlight=f0%2Biap
本文地址: STM32F0系列iap中断向量表设置