File tree 2 files changed +12
-4
lines changed
2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -112,11 +112,10 @@ void SERCOM::enableUART()
112
112
void SERCOM::flushUART ()
113
113
{
114
114
// 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) ;
117
117
118
- // Wait for transmission to complete
119
- while (!sercom->USART .INTFLAG .bit .TXC );
118
+ onFlushWaitUartTXC = false ;
120
119
}
121
120
122
121
void SERCOM::clearStatusUART ()
@@ -183,6 +182,10 @@ int SERCOM::writeDataUART(uint8_t data)
183
182
184
183
// Put data into DATA register
185
184
sercom->USART .DATA .reg = (uint16_t )data;
185
+
186
+ // indicate it's ok to wait for TXC flag when flushing
187
+ onFlushWaitUartTXC = true ;
188
+
186
189
return 1 ;
187
190
}
188
191
Original file line number Diff line number Diff line change @@ -218,6 +218,11 @@ class SERCOM
218
218
uint8_t calculateBaudrateSynchronous (uint32_t baudrate) ;
219
219
uint32_t division (uint32_t dividend, uint32_t divisor) ;
220
220
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 ;
221
226
};
222
227
223
228
#endif
You can’t perform that action at this time.
0 commit comments