IAPStm32在线升级,串口下载后 app不运行
我使用的芯片信号为stm32f103rbt6
BootLoade代码部分
在跳转APP的代码部分是不用增加任何关闭中断系统的东西,程序不运行的愿意是app用户中,需要设置中断便宜变量
int8_t IAP_RunApp(void)
{
//如果指向地址为,则跳转地址
if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)
{
SerialPutString("\r\n Run to app.\r\n");
JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
Jump_To_Application = (pFunction) JumpAddress;
__set_MSP(*(__IO uint32_t*) ApplicationAddress);
Jump_To_Application();
return 0;
}
else
{
SerialPutString("\r\n Run to app error.\r\n");//传输串口数据,错误
return -1;
}
}
APP用户部分需要增加偏移量
STM32_FLASH_BASE是flash起始位置0x08000000,IAP_FLASH_SIZE是Bootloader区域大小,我的bootloader为0x3000,按你的需求来
int main(void)
{
u16 times=0;
NVIC_SetVectorTable(STM32_FLASH_BASE, IAP_FLASH_SIZE);//设置中断向量表
/*还有一种写法如下
//SCB->VTOR=STM32_FLASH_BASE|IAP_FLASH_SIZE;
本质上都是清除bootloader带来的标志位等中断问题,不需要关闭中断开关,然后在打开
也是可以的*/
sys_Init();//程序进入之后首先执行iap初始化 将标志位清除
while(1)
{ ....
......
}
}