Skip to content

Commit

Permalink
Added fn to work around debug breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
David-OConnor committed Apr 3, 2021
1 parent f713979 commit b6b056a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
8 changes: 4 additions & 4 deletions examples/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ setup_globals!((EXAMPLE_OUTPUT, GpioBPin));
fn example_type_sigs<O: OutputPin>(pin1: &mut O, pin2: &mut GpioBPin) {
let setting = pin2.is_high();

pin1.set_low();
pin1.set_low().ok();
}

/// An example function to set up the pins that don't need to be interacted with directly later.
Expand Down Expand Up @@ -110,7 +110,7 @@ fn main() -> ! {
example_type_sigs(&mut example_output, &mut example_input);

// Set high using the `OutputPin` trait.
example_output.set_high();
example_output.set_high().ok();

// Unmask interrupt lines associated with the input pins we've configured interrupts
// for in `setup_pins`.
Expand All @@ -135,7 +135,7 @@ fn EXTI3() {
access_global!(EXAMPLE_OUTPUT, example_output, cs);

// Set a pin high;
example_output.set_high();
example_output.set_high().ok();
});
}

Expand All @@ -151,6 +151,6 @@ fn EXTI4() {
let mut p = EXAMPLE_OUTPUT.borrow(cs).borrow_mut();
let mut example_output = p.as_mut().unwrap();

example_output.set_low();
example_output.set_low().ok();
});
}
4 changes: 4 additions & 0 deletions examples/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ fn TIM3() {
free(|cs| {
// Clear the interrupt flag. If you ommit this, it will fire repeatedly.
unsafe { (*pac::TIM3::ptr()).sr.modify(|_, w| w.uif().clear()) }

// Alternatively, if you have the timer set up in a global mutex:
// access_global!(TIMER, timer, cs);
// timer.clear_interrupt();
});

// Do something.
Expand Down
1 change: 0 additions & 1 deletion src/clocks/h7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ impl Clocks {
rcc.apb4rstr.modify(|_, w| w.syscfgrst().set_bit());
rcc.apb4rstr.modify(|_, w| w.syscfgrst().clear_bit());


Ok(())
}

Expand Down
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,27 @@ macro_rules! make_simple_globals {
};
}

// todo: Remove this function on MCUs that don't require it. Ie, is this required on G4? G0?

#[cfg(not(any(feature = "g0", feature = "h7")))]
/// Workaround due to debugger disconnecting in WFI (and low-power) modes.
/// This affects most (all?) STM32 devices. In production on battery-powered
/// devices that don't use DMA, consider removing this, to prevent power
/// use by the DMA clock.
/// For example, see STM32F446 errata, section 2.1.1.
pub fn debug_workaround(dbgmcu: &mut pac::DBGMCU, rcc: &mut pac::RCC) {
#[cfg(not(feature = "l5"))]
dbgmcu.cr.modify(|_, w| w.dbg_sleep().set_bit());
dbgmcu.cr.modify(|_, w| w.dbg_stop().set_bit());
dbgmcu.cr.modify(|_, w| w.dbg_standby().set_bit());

#[cfg(feature = "f3")]
rcc.ahbenr.modify(|_, w| w.dma1en().set_bit());

#[cfg(not(feature = "f3"))]
rcc.ahb1enr.modify(|_, w| w.dma1en().set_bit());
}

/// In the prelude, we export the `embedded-hal` traits we implement, and
/// some custom ones.
pub mod prelude {
Expand Down

0 comments on commit b6b056a

Please sign in to comment.