mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-25 11:06:48 +08:00
Make _write wait for CDC transmission to finish
This commit is contained in:
+15
-1
@@ -5,7 +5,9 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <cmsis_os.h>
|
||||
#include <freertos_vars.h>
|
||||
#include <usbd_cdc_if.h>
|
||||
#include <usart.h>
|
||||
#include <commands.h>
|
||||
@@ -19,6 +21,8 @@
|
||||
|
||||
#define UART_TX_BUFFER_SIZE 64
|
||||
static uint8_t uart_tx_buf[UART_TX_BUFFER_SIZE];
|
||||
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
||||
extern USBD_HandleTypeDef hUsbDeviceFS;
|
||||
|
||||
int _write(int file, char *data, int len) {
|
||||
//number of bytes written
|
||||
@@ -49,5 +53,15 @@ int _write(int file, char *data, int len) {
|
||||
} break;
|
||||
}
|
||||
|
||||
// Wait for transmission to complete
|
||||
USBD_CDC_HandleTypeDef* hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
|
||||
while (hcdc->TxState != 0) {
|
||||
osSemaphoreWait(sem_usb_irq, 0);
|
||||
// We have a new incoming USB transmission: handle it
|
||||
HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
|
||||
// Let the irq (OTG_FS_IRQHandler) fire again.
|
||||
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user