Skip to content

Commit b8d9b11

Browse files
author
Bogdan Pricop
committed
CDC-ACM: change end and init to avoid race condition.
Signed-off-by: Bogdan Pricop <bogdan.pricop@emutex.com>
1 parent 5174c9c commit b8d9b11

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

cores/arduino/CDCSerialClass.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,17 @@ void CDCSerialClass::init(const uint32_t dwBaudRate, const uint8_t modeReg)
6868
* take to clock out a byte on a standard UART at this baud rate */
6969
_writeDelayUsec = 8000000 / dwBaudRate;
7070

71-
// Make sure both ring buffers are initialized back to empty.
72-
_rx_buffer->head = _rx_buffer->tail = 0;
73-
_tx_buffer->head = _tx_buffer->tail = 0;
71+
/* Make sure both ring buffers are initialized back to empty.
72+
* Empty the Rx buffer but don't touch Tx buffer: it is drained by the
73+
* LMT one way or another */
74+
_rx_buffer->tail = _rx_buffer->head;
7475

7576
_shared_data->device_open = true;
7677
}
7778

7879
void CDCSerialClass::end( void )
7980
{
8081
_shared_data->device_open = false;
81-
82-
_rx_buffer->head = 0;
83-
_rx_buffer->tail = 0;
8482
}
8583

8684
int CDCSerialClass::available( void )

0 commit comments

Comments
 (0)