Stm32F030用Coocox工程进行Bootloader升级时程序跑飞
扫描二维码
随时随地手机看文章
最近做STM32F030C8的Bootloader升级,使用的是Coocox的工程,发现Bootloader可以正常跳转,但是到应用程序时,就直接跑飞,经过仔细查看,发现是中断向量表没有映射,但是在把中断向量表映射后,程序依旧跑飞。一直自己找了好几天,在Nick的帮助下,终于解决了,方法如下:
1、在Bootloader里设置跳转:
/* 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
}
在以上完成中断向量映射后,就要修改连接文件了,我对比了Coocox自带的link文件和向Coocox要的link文件,发现自带的link文件,缺少向量重新映射的配置代码,具体如下:
.ARM.attributes 0 : { *(.ARM.attributes) }
/* RAM space for the vector table */
.RAMVectorTable(NOLOAD): {*(.RAMVectorTable)} >VTRAM
当把以上的代码加在自带的link文件_sidata = __etext;代码后面,重新编译生成bin文件,再次用Bootloader升级后,发现程序正常执行。