@@ -393,15 +393,13 @@ void usb_cdcacm_putc(char ch) {
393393 ;
394394}
395395
396- /* This function is non- blocking.
396+ /* This function is blocking.
397397 *
398398 * It copies data from a usercode buffer into the USB peripheral TX
399399 * buffer, and returns the number of bytes copied. */
400400uint32 usb_cdcacm_tx (const uint8 * buf , uint32 len ) {
401401 /* Last transmission hasn't finished, so abort. */
402- if (usb_cdcacm_is_transmitting ()) {
403- return 0 ;
404- }
402+ while ( usb_cdcacm_is_transmitting ()> 0 ) ; // wait for end of transmission
405403
406404 /* We can only put USB_CDCACM_TX_EPSIZE bytes in the buffer. */
407405 if (len > USB_CDCACM_TX_EPSIZE ) {
@@ -451,7 +449,7 @@ uint32 usb_cdcacm_rx(uint8* buf, uint32 len) {
451449
452450 /* If all bytes have been read, re-enable the RX endpoint, which
453451 * was set to NAK when the current batch of bytes was received. */
454- if (n_unread_bytes <= ( CDC_SERIAL_BUFFER_SIZE - USB_CDCACM_RX_EPSIZE ) ) {
452+ if (n_unread_bytes <=0 ) {
455453 usb_set_ep_rx_count (USB_CDCACM_RX_ENDP , USB_CDCACM_RX_EPSIZE );
456454 usb_set_ep_rx_stat (USB_CDCACM_RX_ENDP , USB_EP_STAT_RX_VALID );
457455 }
@@ -567,7 +565,7 @@ static void vcomDataRxCb(void) {
567565
568566 n_unread_bytes += ep_rx_size ;
569567
570- if (n_unread_bytes <= ( CDC_SERIAL_BUFFER_SIZE - USB_CDCACM_RX_EPSIZE ) ) {
568+ if ( n_unread_bytes <= 0 ) {
571569 usb_set_ep_rx_count (USB_CDCACM_RX_ENDP , USB_CDCACM_RX_EPSIZE );
572570 usb_set_ep_rx_stat (USB_CDCACM_RX_ENDP , USB_EP_STAT_RX_VALID );
573571 }
0 commit comments