@@ -39,7 +39,7 @@ class USBCDC::AsyncWrite: public AsyncOp {
39
39
AsyncWrite (USBCDC *serial, uint8_t *buf, uint32_t size):
40
40
serial (serial), tx_buf(buf), tx_size(size), result(false )
41
41
{
42
-
42
+ need_zlp = (size % CDC_MAX_PACKET_SIZE == 0 ) ? true : false ;
43
43
}
44
44
45
45
virtual ~AsyncWrite ()
@@ -59,6 +59,12 @@ class USBCDC::AsyncWrite: public AsyncOp {
59
59
tx_size -= actual_size;
60
60
tx_buf += actual_size;
61
61
if (tx_size == 0 ) {
62
+ // For ZLP case, not ending yet and need one more time to invoke process to send zero packet.
63
+ if (need_zlp) {
64
+ need_zlp = false ;
65
+ serial->_send_isr_start ();
66
+ return false ;
67
+ }
62
68
result = true ;
63
69
return true ;
64
70
}
@@ -72,6 +78,7 @@ class USBCDC::AsyncWrite: public AsyncOp {
72
78
uint8_t *tx_buf;
73
79
uint32_t tx_size;
74
80
bool result;
81
+ bool need_zlp;
75
82
};
76
83
77
84
class USBCDC ::AsyncRead: public AsyncOp {
@@ -186,6 +193,7 @@ void USBCDC::_init()
186
193
_rx_in_progress = false ;
187
194
_rx_buf = _rx_buffer;
188
195
_rx_size = 0 ;
196
+ _trans_zlp = false ;
189
197
}
190
198
191
199
void USBCDC::callback_reset ()
@@ -383,10 +391,16 @@ void USBCDC::send_nb(uint8_t *buffer, uint32_t size, uint32_t *actual, bool now)
383
391
uint32_t free = sizeof (_tx_buffer) - _tx_size;
384
392
uint32_t write_size = free > size ? size : free;
385
393
if (size > 0 ) {
386
- memcpy (_tx_buf, buffer, write_size);
394
+ memcpy (_tx_buf + _tx_size , buffer, write_size);
387
395
}
388
396
_tx_size += write_size;
389
397
*actual = write_size;
398
+
399
+ /* Enable ZLP flag as while send_nb() zero size */
400
+ if (size == 0 ) {
401
+ _trans_zlp = true ;
402
+ }
403
+
390
404
if (now) {
391
405
_send_isr_start ();
392
406
}
@@ -404,6 +418,14 @@ void USBCDC::_send_isr_start()
404
418
_tx_in_progress = true ;
405
419
}
406
420
}
421
+
422
+ /* Send ZLP write start */
423
+ if (!_tx_in_progress && _trans_zlp) {
424
+ if (USBDevice::write_start (_bulk_in, _tx_buffer, 0 )) {
425
+ _tx_in_progress = true ;
426
+ _trans_zlp = false ;
427
+ }
428
+ }
407
429
}
408
430
409
431
/*
0 commit comments