File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -166,6 +166,21 @@ size_t HardwareSerial::write(const uint8_t uc_data) {
166166 int nextWrite = _tx_buffer->_iHead + 1 ;
167167 if (nextWrite >= SERIAL_BUFFER_SIZE)
168168 nextWrite = 0 ;
169+
170+ // This should always be false but in case transmission is completed before buffer, we need
171+ // to reenable IRQ
172+ if (XMC_USIC_CH_GetTransmitBufferStatus (_XMC_UART_config->channel ) !=
173+ XMC_USIC_CH_TBUF_STATUS_BUSY) {
174+ XMC_UART_CH_EnableEvent (_XMC_UART_config->channel , XMC_UART_CH_EVENT_TRANSMIT_BUFFER);
175+ XMC_UART_CH_Transmit (_XMC_UART_config->channel ,
176+ _tx_buffer->_aucBuffer [_tx_buffer->_iTail ]);
177+ _tx_buffer->_iTail ++;
178+ if (_tx_buffer->_iTail >= SERIAL_BUFFER_SIZE)
179+ _tx_buffer->_iTail = _tx_buffer->_iTail -
180+ SERIAL_BUFFER_SIZE; // If iTail is larger than Serial Buffer
181+ // Size calculate the correct index value
182+ }
183+
169184 while (_tx_buffer->_iTail == nextWrite)
170185 ; // Spin locks if we're about to overwrite the buffer. This continues once the data is
171186 // sent
@@ -207,9 +222,10 @@ void HardwareSerial::IrqHandler(void) {
207222 _tx_buffer->_iTail ++;
208223 if (_tx_buffer->_iTail >= SERIAL_BUFFER_SIZE)
209224 _tx_buffer->_iTail = 0 ;
210- } else
225+ } else {
211226 // Mask off transmit interrupt so we don't get it any more
212227 XMC_UART_CH_DisableEvent (_XMC_UART_config->channel , XMC_UART_CH_EVENT_TRANSMIT_BUFFER);
228+ }
213229 }
214230}
215231
You can’t perform that action at this time.
0 commit comments