Skip to content

[UART] Add frame and parity error handling #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cores/arduino/SERCOM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ bool SERCOM::isUARTError()
return sercom->USART.INTFLAG.bit.ERROR;
}

bool SERCOM::isParityOrFrameError()
{
return (sercom->USART.STATUS.reg & (SERCOM_USART_STATUS_FERR | SERCOM_USART_STATUS_PERR));
}

void SERCOM::acknowledgeUARTError()
{
sercom->USART.INTFLAG.bit.ERROR = 1;
Expand All @@ -152,6 +157,18 @@ bool SERCOM::isFrameErrorUART()
return sercom->USART.STATUS.bit.FERR;
}

void SERCOM::clearFrameErrorUART()
{
// clear FERR bit writing 1 status bit
sercom->USART.STATUS.bit.FERR = 1;
}

void SERCOM::clearParityErrorUART()
{
// clear FERR bit writing 1 status bit
sercom->USART.STATUS.bit.PERR = 1;
}

bool SERCOM::isParityErrorUART()
{
//PERR : Parity Error
Expand Down
3 changes: 3 additions & 0 deletions cores/arduino/SERCOM.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ class SERCOM
uint8_t readDataUART( void ) ;
int writeDataUART(uint8_t data) ;
bool isUARTError() ;
void clearFrameErrorUART() ;
void clearParityErrorUART() ;
bool isParityOrFrameError() ;
void acknowledgeUARTError() ;
void enableDataRegisterEmptyInterruptUART();
void disableDataRegisterEmptyInterruptUART();
Expand Down
18 changes: 17 additions & 1 deletion cores/arduino/Uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,23 @@ void Uart::flush()
void Uart::IrqHandler()
{
if (sercom->availableDataUART()) {
rxBuffer.store_char(sercom->readDataUART());
// Check if there is a parity or frame error
if (!sercom->isParityOrFrameError()) {
// no error, store the value
rxBuffer.store_char(sercom->readDataUART());
} else {
// read the invalid data and discard it
sercom->readDataUART();

// clear any errors that are set
if (sercom->isFrameErrorUART()) {
sercom->clearFrameErrorUART();
}

if (sercom->isFrameErrorUART()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this block should check for parity error, not frame error again.

sercom->clearFrameErrorUART();
}
}

if (uc_pinRTS != NO_RTS_PIN) {
// RX buffer space is below the threshold, de-assert RTS
Expand Down