bootloader跳转app失败解决方法之一
一、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
①在KEIL中设置APP下载地址
②在main函数中添加app下载地址
1 int main(void) 2 { 3 /* USER CODE BEGIN 1 */ 4 SCB->VTOR = 0x08020000; //APP下载的地址