arduino / arduino/ArduinoCore-sam

UARTClass::write function loses the first character when it is called many times in series.

Open
#51 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
91
Forks
112
PR merge metrics
No merged PRs in 30d

Description

Series like this:
```
Serial.print("r=");
Serial.print(25);
Serial.print(",");
Serial.print(1);
Serial.print(";");
```
`
Output: r=25,1;r=25,1;r=25,1;r=5,1;r=25,1;r=25,1;
`

Temporary fix (in UARTClass.cpp):
```
size_t UARTClass::write( const uint8_t uc_data )
{
int nextWrite = (_tx_buffer->_iHead + 1);
if(nextWrite >= SERIAL_BUFFER_SIZE) nextWrite = 0;
while (_tx_buffer->_iTail == nextWrite)
; // Spin locks if we're about to overwrite the buffer. This continues once the data is sent

_tx_buffer->_aucBuffer[_tx_buffer->_iHead] = uc_data;
_tx_buffer->_iHead = nextWrite;

// Make sure TX interrupt is enabled
_pUart->UART_IER = UART_IER_TXRDY;
return 1;
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in UARTClass.cpp at UARTClass::write(const uint8_t uc_data) and reproduce the issue with the repeated Serial.print series shown here. Compare the current output with the temporary implementation in the issue, then verify that repeated writes no longer lose the first character.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.