From c05a3607ef19ea026c4a48880842ac8244e59a43 Mon Sep 17 00:00:00 2001 From: Jinxi Chen Date: Fri, 10 Jul 2020 16:59:32 +0800 Subject: [PATCH] fix:fix issue of the M300 without usb connected Fix issue of the M300 without usb connected. --- .../platform/STM32/OnBoardSDK_STM32/Linker/hal/osdkhal_stm32.c | 3 +++ sample/platform/STM32/OnBoardSDK_STM32/User/usbh_usr.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/sample/platform/STM32/OnBoardSDK_STM32/Linker/hal/osdkhal_stm32.c b/sample/platform/STM32/OnBoardSDK_STM32/Linker/hal/osdkhal_stm32.c index abf6f77ab..001614d1d 100644 --- a/sample/platform/STM32/OnBoardSDK_STM32/Linker/hal/osdkhal_stm32.c +++ b/sample/platform/STM32/OnBoardSDK_STM32/Linker/hal/osdkhal_stm32.c @@ -29,10 +29,12 @@ #include "stm32f4xx.h" #include "FreeRTOS.h" #include "queue.h" +#include "stdbool.h" extern QueueHandle_t UartDataRecvQueue; extern QueueHandle_t ACMDataRecvQueue; extern QueueHandle_t ACMDataSendQueue; +extern bool USBConnected; enum STM32_LINK_FD { @@ -98,6 +100,7 @@ E_OsdkStat OsdkSTM32_UartInit(const char *port, const int baudrate, obj->uartObject.fd = UART_FD; } else if (strcmp(port, ACM_PORT) == 0) { obj->uartObject.fd = ACM_FD; + if (USBConnected == false) return OSDK_STAT_ERR; } else { obj->uartObject.fd = INVALID_FD; } diff --git a/sample/platform/STM32/OnBoardSDK_STM32/User/usbh_usr.cpp b/sample/platform/STM32/OnBoardSDK_STM32/User/usbh_usr.cpp index c41de7a7a..6311ced27 100644 --- a/sample/platform/STM32/OnBoardSDK_STM32/User/usbh_usr.cpp +++ b/sample/platform/STM32/OnBoardSDK_STM32/User/usbh_usr.cpp @@ -49,6 +49,7 @@ extern CDC_Usercb_TypeDef UserCb; CDC_Demo_State CDCUsrState; extern QueueHandle_t ACMDataSendQueue; +bool USBConnected = false; USBH_Usr_cb_TypeDef USR_Callbacks = { @@ -85,11 +86,13 @@ void USBH_USR_Init(void) void USBH_USR_DeviceAttached(void) { + USBConnected = true; USB_DEBUG("USBH_USR_DeviceAttached!"); } void USBH_USR_DeviceDisconnected (void) { + USBConnected = false; USB_DEBUG("USBH_USR_DeviceDisconnected!"); }