Skip to content

Commit

Permalink
Commented out to enable turning uarte on/off again, see nrf-rs#381
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Feb 22, 2022
1 parent c5d9168 commit 6fde055
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions nrf-hal-common/src/uarte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,36 +129,37 @@ where
self.0.tasks_stoptx.write(|w| unsafe { w.bits(1) });
}

// NB Safety: This is taken from Nordic's driver -
// https://github.com/NordicSemiconductor/nrfx/blob/master/drivers/src/nrfx_uarte.c#L197
if unsafe { core::ptr::read_volatile(rxenable_reg) } == 1 {
self.0.enable.write(|w| w.enable().enabled());
self.0.tasks_stoprx.write(|w| unsafe { w.bits(1) });

let mut workaround_succeded = false;
// The UARTE is able to receive up to four bytes after the STOPRX task has been triggered.
// On lowest supported baud rate (1200 baud), with parity bit and two stop bits configured
// (resulting in 12 bits per data byte sent), this may take up to 40 ms.
for _ in 0..40000 {
// NB Safety: This is taken from Nordic's driver -
// https://github.com/NordicSemiconductor/nrfx/blob/master/drivers/src/nrfx_uarte.c#L197
if unsafe { core::ptr::read_volatile(rxenable_reg) } == 0 {
workaround_succeded = true;
break;
} else {
// Need to sleep for 1us here
}
}

if !workaround_succeded {
panic!("Failed to apply workaround for UART");
}

let errors = self.0.errorsrc.read().bits();
// NB Safety: safe to write back the bits we just read to clear them
self.0.errorsrc.write(|w| unsafe { w.bits(errors) });
self.0.enable.write(|w| w.enable().disabled());
}
// Commented out to enable turning uarte on/off again, see https://github.com/nrf-rs/nrf-hal/issues/381
// // NB Safety: This is taken from Nordic's driver -
// // https://github.com/NordicSemiconductor/nrfx/blob/master/drivers/src/nrfx_uarte.c#L197
// if unsafe { core::ptr::read_volatile(rxenable_reg) } == 1 {
// self.0.enable.write(|w| w.enable().enabled());
// self.0.tasks_stoprx.write(|w| unsafe { w.bits(1) });
//
// let mut workaround_succeded = false;
// // The UARTE is able to receive up to four bytes after the STOPRX task has been triggered.
// // On lowest supported baud rate (1200 baud), with parity bit and two stop bits configured
// // (resulting in 12 bits per data byte sent), this may take up to 40 ms.
// for _ in 0..40000 {
// // NB Safety: This is taken from Nordic's driver -
// // https://github.com/NordicSemiconductor/nrfx/blob/master/drivers/src/nrfx_uarte.c#L197
// if unsafe { core::ptr::read_volatile(rxenable_reg) } == 0 {
// workaround_succeded = true;
// break;
// } else {
// // Need to sleep for 1us here
// }
// }
//
// if !workaround_succeded {
// panic!("Failed to apply workaround for UART");
// }
//
// let errors = self.0.errorsrc.read().bits();
// // NB Safety: safe to write back the bits we just read to clear them
// self.0.errorsrc.write(|w| unsafe { w.bits(errors) });
// self.0.enable.write(|w| w.enable().disabled());
// }
}

/// Write via UARTE.
Expand Down

0 comments on commit 6fde055

Please sign in to comment.