新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2020-11-12
- 在线时间
- 2 小时
|
2金钱
STM32 新手一枚,目前在做一个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();
- 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开始运行打印出
- printf("xxxxxxxxxx\r\n");
复制代码
就挂住,USB虚拟串口在window10上也不能正常识别了,请大家帮忙分析看看是什么原因,谢谢大家!
|
|