目前在做一個STM32定位模塊的IAP 遠程升級的功能, boot跳轉到APP后,APP只執行了main函式開始一段代碼就掛住了,window10上開 usb串口也變成未知USB設備:
boot主要代碼如下:
int main(void)
{
u16 len = 0, data_len =0;
int ret = 0, i =0, n = 0;
u32 offset = 0;
USB_Config();
USB_Cable_Config(ENABLE);
//Init_Image_tx();
//led_on (LED_ALL);
while(1)
{
len = 0;
memset(UWBRxBuff, 0x0,sizeof(UWBRxBuff));
len = USB_RxRead(UWBRxBuff, sizeof(UWBRxBuff));
if(UWBRxBuff[0] == 0x19 && UWBRxBuff[1] == 0xF1)
{
jumpToApp(0x080005000);
return 0;
}
else
{
n = sprintf(SendBuff,"waite for jump command!!");
USB_TxWrite(SendBuff,n);
}
Sleep(1000);
}
}
void jumpToApp(uint32_t appxaddr)
{
int n = 0;
n = sprintf((char*)&SendBuff[0], "%s\r\n", "Reay ...");
USB_TxWrite(SendBuff, n);
n = sprintf((char*)&SendBuff[0], "addr:%08x\r\n", appxaddr);
USB_TxWrite(SendBuff, n);
if (((*(volatile uint32_t*)appxaddr) & 0x2FFE0000 ) == 0x20000000)
{
n = sprintf((char*)&SendBuff[0], "%s", "Go!\r\n");
USB_TxWrite(SendBuff, n);
/* Jump to user application */
JumpAddress = *(volatile uint32_t*) (ApplicationAddress + 4);
Jump_To_Application = (pFunction) JumpAddress;
n = sprintf((char*)&SendBuff[0], "JumpAddress:%08x\r\n", JumpAddress);
USB_TxWrite(SendBuff, n);
/* Initialize user application's Stack Pointer */
//USB_Cable_Config(DISABLE);
//INTX_DISABLE();
__disable_irq();
SCB->VTOR = FLASH_BASE | ApplicationAddress;
__set_MSP(*(volatile uint32_t*) appxaddr);
Jump_To_Application();
}
}
APP main代碼
int main(void)
{
volatile u16 adcx;
INTX_DISABLE();
SCB->VTOR = FLASH_BASE | 0x00005000UL;
USB_Config();
USB_Cable_Config(ENABLE);
uart_init(UART_BAUDRATE);
GPIO_Configuration(); //PB6/PB7 LED0-1
SPI_Configuration(); /*SPI1, CS->GPIOA PIN4/5/6/7*/
peripherals_init();
INTX_ENABLE();
//Flash_Configuration();
led_on(LED_ALL);
printf("0123456789\r\n");
printf("abcdefghjk\r\n");
printf("xxxxxxxxxx\r\n"); //boot跳轉后,從串口輸出在這里停止了。后面Display_UWBInfo(1);也有printf 輸出,但是沒有列印出來
//RTC_Alarm_Configuration();//Init RTC ALARM
//MYDMA_Config(DMA1_Channel4,(u32)&USART1->DR, (u32)DMA_USART_Buff, 3000);
//USART_DMACmd(USART1, USART_DMAReq_Tx,ENABLE); //DMA
Display_UWBInfo(1);
waittingForCleConfig(0);
return 0;
}
boot 和APP 獨立刷機是可以正常運行的;用xcom 發送跳轉命令,跳轉后app上的列印在串口上有輸出,說明跳轉是成功的;
APP開始運行一段后就掛住,USB虛擬串口在window10上也不能正常識別了,請大家幫忙分析看看是什么原因,謝謝大家!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/212821.html
標籤:單片機/工控
