Skip to content

Commit a1a82ba

Browse files
Jonathan Pallant (42 Technology)Yatekii
authored andcommitted
Fixup UART driver to support UARTE1 on 9160.
Also disables TX to save power.
1 parent 3fbff4c commit a1a82ba

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

nrf52-hal-common/src/uarte.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use core::fmt;
1212
use crate::target::{
1313
uarte0_ns as uarte0,
1414
UARTE0_NS as UARTE0,
15+
UARTE1_NS as UARTE1,
1516
};
1617

1718
#[cfg(not(feature="9160"))]
@@ -123,7 +124,8 @@ impl<T> Uarte<T> where T: Instance {
123124
return Err(Error::TxBufferTooLong);
124125
}
125126

126-
if !crate::slice_in_ram(tx_buffer){
127+
// We can only DMA out of RAM
128+
if !crate::slice_in_ram(tx_buffer) {
127129
return Err(Error::BufferNotInRAM);
128130
}
129131

@@ -133,8 +135,8 @@ impl<T> Uarte<T> where T: Instance {
133135
compiler_fence(SeqCst);
134136

135137
// Reset the events.
136-
self.0.events_endtx.write(|w| w);
137-
self.0.events_txstopped.write(|w| w);
138+
self.0.events_endtx.reset();
139+
self.0.events_txstopped.reset();
138140

139141
// Set up the DMA write
140142
self.0.txd.ptr.write(|w|
@@ -180,6 +182,12 @@ impl<T> Uarte<T> where T: Instance {
180182
return Err(Error::Transmit);
181183
}
182184

185+
// Lower power consumption by disabling the transmitter once we're
186+
// finished
187+
self.0.tasks_stoptx.write(|w|
188+
// `1` is a valid value to write to task registers.
189+
unsafe { w.bits(1) });
190+
183191
Ok(())
184192
}
185193

@@ -384,3 +392,6 @@ pub enum Error {
384392
pub trait Instance: Deref<Target = uarte0::RegisterBlock> {}
385393

386394
impl Instance for UARTE0 {}
395+
396+
#[cfg(feature="9160")]
397+
impl Instance for UARTE1 {}

0 commit comments

Comments
 (0)