@@ -139,12 +139,14 @@ static void hw_cdc_isr_handler(void *arg) {
139139}
140140
141141static void ARDUINO_ISR_ATTR cdc0_write_char (char c) {
142- if (xPortInIsrContext ()){
143- xRingbufferSendFromISR (tx_ring_buf, (void *) (&c), 1 , NULL );
144- } else {
145- xRingbufferSend (tx_ring_buf, (void *) (&c), 1 , tx_timeout_ms / portTICK_PERIOD_MS);
142+ if (initial_empty){
143+ if (xPortInIsrContext ()){
144+ xRingbufferSendFromISR (tx_ring_buf, (void *) (&c), 1 , NULL );
145+ } else {
146+ xRingbufferSend (tx_ring_buf, (void *) (&c), 1 , tx_timeout_ms / portTICK_PERIOD_MS);
147+ }
148+ usb_serial_jtag_ll_ena_intr_mask (USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
146149 }
147- usb_serial_jtag_ll_ena_intr_mask (USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
148150}
149151
150152HWCDC::HWCDC () {
@@ -245,7 +247,7 @@ int HWCDC::availableForWrite(void)
245247
246248size_t HWCDC::write (const uint8_t *buffer, size_t size)
247249{
248- if (buffer == NULL || size == 0 || tx_ring_buf == NULL || tx_lock == NULL ){
250+ if (buffer == NULL || size == 0 || tx_ring_buf == NULL || tx_lock == NULL || initial_empty == false ){
249251 return 0 ;
250252 }
251253 if (xSemaphoreTake (tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){
@@ -293,7 +295,7 @@ size_t HWCDC::write(uint8_t c)
293295
294296void HWCDC::flush (void )
295297{
296- if (tx_ring_buf == NULL || tx_lock == NULL ){
298+ if (tx_ring_buf == NULL || tx_lock == NULL || initial_empty == false ){
297299 return ;
298300 }
299301 if (xSemaphoreTake (tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){
0 commit comments