@@ -165,6 +165,7 @@ extern const tUSBBuffer g_sRxBuffer;
165
165
166
166
// Global flag indicating that a USB configuration has been set.
167
167
static volatile bool g_bUSBConfigured = false;
168
+ static bool g_bUSBSerialConfigured = false;
168
169
169
170
static void GetLineCoding (tLineCoding * psLineCoding ) {
170
171
//
@@ -328,6 +329,7 @@ unsigned int ControlHandler(void *pvCBData, unsigned int ulEvent, unsigned int u
328
329
//
329
330
case USB_EVENT_DISCONNECTED :
330
331
g_bUSBConfigured = false;
332
+ g_bUSBSerialConfigured = false;
331
333
process_poll (& pbdrv_usb_process );
332
334
break ;
333
335
@@ -348,6 +350,8 @@ unsigned int ControlHandler(void *pvCBData, unsigned int ulEvent, unsigned int u
348
350
// Set the current serial communication parameters.
349
351
//
350
352
case USBD_CDC_EVENT_SET_CONTROL_LINE_STATE :
353
+ g_bUSBSerialConfigured = true;
354
+ process_poll (& pbdrv_usb_process );
351
355
//
352
356
// TODO: If configured with GPIOs controlling the handshake lines,
353
357
// set them appropriately depending upon the flags passed in the wValue
@@ -502,7 +506,16 @@ pbdrv_usb_bcd_t pbdrv_usb_get_bcd(void) {
502
506
}
503
507
504
508
uint32_t pbdrv_usb_write (const uint8_t * data , uint32_t size ) {
505
- return USBBufferWrite ((tUSBBuffer * )& g_sTxBuffer , data , size );
509
+ // Attempt to write to the USB buffer.
510
+ uint32_t written = USBBufferWrite ((tUSBBuffer * )& g_sTxBuffer , data , size );
511
+
512
+ // If configured, return the number of bytes written so we can await completion.
513
+ if (g_bUSBSerialConfigured ) {
514
+ return written ;
515
+ }
516
+
517
+ // If not configured, return the size requested so that caller doesn't block.
518
+ return size ;
506
519
}
507
520
508
521
uint32_t pbdrv_usb_rx_data_available (void ) {
0 commit comments