Skip to content
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
Add isUARTEnable API
added API for check the UART status in Uart::flush(),  befor to start the flush
  • Loading branch information
Rocketct committed Nov 8, 2018
commit 3546e4874815d86d0aaaac2ab6c87191788238c4
5 changes: 5 additions & 0 deletions cores/arduino/SERCOM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ void SERCOM::enableUART()
while(sercom->USART.SYNCBUSY.bit.ENABLE);
}

bool SERCOM::isUARTEnabled() {
// check for Uart Enable state
return sercom->USART.CTRLA.bit.ENABLE & SERCOM_USART_CTRLA_ENABLE;
}

void SERCOM::flushUART()
{
// Skip checking transmission completion if data register is empty
Expand Down
5 changes: 3 additions & 2 deletions cores/arduino/SERCOM.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ class SERCOM
uint8_t readDataUART( void ) ;
int writeDataUART(uint8_t data) ;
bool isUARTError() ;
bool isUARTEnabled() ;
void acknowledgeUARTError() ;
void enableDataRegisterEmptyInterruptUART();
void disableDataRegisterEmptyInterruptUART();
void enableDataRegisterEmptyInterruptUART() ;
void disableDataRegisterEmptyInterruptUART() ;

/* ========== SPI ========== */
void initSPI(SercomSpiTXPad mosi, SercomRXPad miso, SercomSpiCharSize charSize, SercomDataOrder dataOrder) ;
Expand Down
4 changes: 4 additions & 0 deletions cores/arduino/Uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ void Uart::end()

void Uart::flush()
{
if (!sercom->isUARTEnabled()) {
return;
}

while(txBuffer.available()); // wait until TX buffer is empty

sercom->flushUART();
Expand Down