File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -112,11 +112,10 @@ void SERCOM::enableUART()
112112void SERCOM::flushUART ()
113113{
114114 // Skip checking transmission completion if data register is empty
115- // if(isDataRegisterEmptyUART())
116- // return ;
115+ // Wait for transmission to complete, if ok to do so.
116+ while (!sercom-> USART . INTFLAG . bit . TXC && onFlushWaitUartTXC) ;
117117
118- // Wait for transmission to complete
119- while (!sercom->USART .INTFLAG .bit .TXC );
118+ onFlushWaitUartTXC = false ;
120119}
121120
122121void SERCOM::clearStatusUART ()
@@ -183,6 +182,10 @@ int SERCOM::writeDataUART(uint8_t data)
183182
184183 // Put data into DATA register
185184 sercom->USART .DATA .reg = (uint16_t )data;
185+
186+ // indicate it's ok to wait for TXC flag when flushing
187+ onFlushWaitUartTXC = true ;
188+
186189 return 1 ;
187190}
188191
Original file line number Diff line number Diff line change @@ -218,6 +218,11 @@ class SERCOM
218218 uint8_t calculateBaudrateSynchronous (uint32_t baudrate) ;
219219 uint32_t division (uint32_t dividend, uint32_t divisor) ;
220220 void initClockNVIC ( void ) ;
221+
222+ // Flag set when data is loaded into sercom->USART.DATA.reg.
223+ // Helps with preventing UART lockups when flushing on startup
224+ // and the asyncronous nature of the DRE and TXC interrupt flags.
225+ bool onFlushWaitUartTXC = false ;
221226};
222227
223228#endif
You can’t perform that action at this time.
0 commit comments