@@ -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 {
@@ -388,7 +395,9 @@ void USBCDC::send_nb(uint8_t *buffer, uint32_t size, uint32_t *actual, bool now)
388
395
}
389
396
_tx_size += write_size;
390
397
*actual = write_size;
391
- if ((CDC_MAX_PACKET_SIZE == size) && (CDC_MAX_PACKET_SIZE == write_size)) {
398
+
399
+ /* Enable ZLP flag as while send_nb() zero size */
400
+ if (size == 0 ) {
392
401
_trans_zlp = true ;
393
402
}
394
403
@@ -409,6 +418,14 @@ void USBCDC::_send_isr_start()
409
418
_tx_in_progress = true ;
410
419
}
411
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
+ }
412
429
}
413
430
414
431
/*
@@ -419,11 +436,6 @@ void USBCDC::_send_isr()
419
436
{
420
437
assert_locked ();
421
438
422
- /* Send ZLP write start after last alignment packet sent */
423
- if (_trans_zlp && USBDevice::write_start (_bulk_in, _tx_buffer, 0 )) {
424
- _trans_zlp = false ;
425
- }
426
-
427
439
write_finish (_bulk_in);
428
440
_tx_buf = _tx_buffer;
429
441
_tx_size = 0 ;
0 commit comments