Stm32F030用Coocox工程進(jìn)行Bootloader升級(jí)時(shí)程序跑飛
最近做STM32F030C8的Bootloader升級(jí),使用的是Coocox的工程,發(fā)現(xiàn)Bootloader可以正常跳轉(zhuǎn),但是到應(yīng)用程序時(shí),就直接跑飛,經(jīng)過(guò)仔細(xì)查看,發(fā)現(xiàn)是中斷向量表沒(méi)有映射,但是在把中斷向量表映射后,程序依舊跑飛。一直自己找了好幾天,在Nick的幫助下,終于解決了,方法如下:
1、在Bootloader里設(shè)置跳轉(zhuǎn):
/* Jump to user application */
JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
Jump_To_Application = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
/* Jump to application */
Jump_To_Application();
2、在Application里重新映射中斷向量表;并修改連接文件,十分重要的是不能用Coocox自帶的連接文件,要重新向Coocox公司要一份新的,否則向量映射不成功,程序就跑飛。
#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);
#else
#error "it should define the vector table"
#endif
int main(void)
{
#if 1
uint32_t i;
/* Relocate by software the vector table to the internal SRAM at 0x20000000 ***/
for(i = 0; i < 48; i++)
{
VectorTable[i] = *(__IO uint32_t*)(APPLICATION_ADDRESS + (i<<2));
}
/* Enable the SYSCFG peripheral clock*/
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Remap SRAM at 0x00000000 */
SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM);
#endif
}
在以上完成中斷向量映射后,就要修改連接文件了,我對(duì)比了Coocox自帶的link文件和向Coocox要的link文件,發(fā)現(xiàn)自帶的link文件,缺少向量重新映射的配置代碼,具體如下:
.ARM.attributes 0 : { *(.ARM.attributes) }
/* RAM space for the vector table */
.RAMVectorTable(NOLOAD): {*(.RAMVectorTable)} >VTRAM
當(dāng)把以上的代碼加在自帶的link文件_sidata = __etext;代碼后面,重新編譯生成bin文件,再次用Bootloader升級(jí)后,發(fā)現(xiàn)程序正常執(zhí)行。