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升级后,发现程序正常执行。

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值