Skip to content

Commit 377348c

Browse files
author
Jonathan Pallant (42 Technology)
committed
Don't check for txstopped when writing to UART.
It seems like endtx and txstopped race, and if we see txstopped first we return an error, causing writeln!(...).unwrap() to panic. This changes makes the UART work reliably on the nRF9160-PDK.
1 parent ed5d87d commit 377348c

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

nrf-hal-common/src/uarte.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,31 +135,26 @@ where
135135
unsafe { w.bits(1) });
136136

137137
// Wait for transmission to end.
138-
let mut endtx;
139-
let mut txstopped;
140-
loop {
141-
endtx = self.0.events_endtx.read().bits() != 0;
142-
txstopped = self.0.events_txstopped.read().bits() != 0;
143-
if endtx || txstopped {
144-
break;
145-
}
138+
while self.0.events_endtx.read().bits() == 0 {
139+
// TODO: Do something here which uses less power. Like `wfi`.
146140
}
147141

148142
// Conservative compiler fence to prevent optimizations that do not
149143
// take in to account actions by DMA. The fence has been placed here,
150144
// after all possible DMA actions have completed.
151145
compiler_fence(SeqCst);
152146

153-
if txstopped {
154-
return Err(Error::Transmit);
155-
}
156-
157147
// Lower power consumption by disabling the transmitter once we're
158148
// finished.
159149
self.0.tasks_stoptx.write(|w|
160150
// `1` is a valid value to write to task registers.
161151
unsafe { w.bits(1) });
162152

153+
// Wait for transmitter to stop.
154+
while self.0.events_txstopped.read().bits() == 0 {
155+
// Spin
156+
}
157+
163158
Ok(())
164159
}
165160

0 commit comments

Comments
 (0)