首页 > 移动平台 > 详细

bootloader跳转app失败解决方法之一

时间:2021-01-13 17:54:54      阅读:0      评论:0      收藏:0      [点我收藏+]

一、bootloader

bootloader中要添加的内容

1 #define   APPLICATION_ADDRESS ADDR_FLASH_SECTOR_1_BANK1      //地址flash地址
2 typedef   void (*pFunction)(void);
3 pFunction JumpToApplication;
4 uint32_t JumpAddress;

main函数:

跳转前要关闭所有外设:

 1 char  TxMes[128]={0};
 2 uchar num = 1;
 3 int main(void)
 4 {
 5   HAL_Init();
 6   SystemClock_Config();
 7   MX_GPIO_Init();
 8   MX_DMA_Init();
 9   MX_TIM2_Init();
10   MX_USART6_UART_Init(9600);
11   HAL_UART_Receive_DMA(&huart6,RxDMABuf_6,RXBUF_6_SIZE);
12   HAL_Delay(100);
13   STMFLASH_Read(ADDR_FLASH_SECTOR_3_BANK1,&UPtest[0],2);
14   if((UPtest[0] == 0XA5)&&(UPtest[1] == 0X5A)&&(repair == 0x00))
15   {
16     if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FF00000 ) == 0x24000000)  
17      {  
18         MX_GPIO_DeInit();        
19         HAL_RCC_DeInit();//关闭外设 
20         HAL_TIM_Base_DeInit(&htim2);    
21         HAL_UART_MspDeInit(&huart6);            
22         HAL_NVIC_DisableIRQ(TIM2_IRQn);                
23         HAL_NVIC_DisableIRQ(USART6_IRQn);
24         HAL_NVIC_EnableIRQ(DMA2_Stream4_IRQn);
25         HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn);
26         /* 跳转到系统BootLoader,首地址是MSP,地址+4是复位中断服务程序地址 */            
27        JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
28        JumpToApplication = (pFunction) JumpAddress;
29         /* 设置主堆栈指针 */
30         __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
31         /* 跳转到系统BootLoader */
32         JumpToApplication();                 
33      }            
34    }
35   while (1)
36   {
37      if(num == 1)    
38      {
39         sprintf(TxMes,"APP 等待升级\r\n");
40         HAL_UART_Transmit(&huart6,(uint8_t*)TxMes,strlen(TxMes),1000);
41         HAL_Delay(1000);            
42         num = 0;
43      }
44   }
45 }

二、app

 

bootloader跳转app失败解决方法之一

原文:https://www.cnblogs.com/better-day/p/14273142.html

(0)
(0)
   
举报
评论 一句话评论(0
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号