From 1bad6a498930991fcdc7454ad38e371d0966087d Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Fri, 3 Jun 2022 19:47:17 +0200 Subject: [PATCH 1/3] Add example for using a Signal. --- examples/stm32h7/src/bin/signal.rs | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/stm32h7/src/bin/signal.rs diff --git a/examples/stm32h7/src/bin/signal.rs b/examples/stm32h7/src/bin/signal.rs new file mode 100644 index 00000000..d2531b2b --- /dev/null +++ b/examples/stm32h7/src/bin/signal.rs @@ -0,0 +1,41 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +// global logger +use defmt::{info, unwrap}; +use defmt_rtt as _; + +use panic_probe as _; + +use embassy::channel::Signal; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; + +use embassy_stm32::Peripherals; + +static SIGNAL: Signal = Signal::new(); + +#[embassy::task] +async fn my_sending_task() { + let mut counter: u32 = 0; + + loop { + Timer::after(Duration::from_secs(1)).await; + + SIGNAL.signal(counter); + + counter = counter.wrapping_add(1); + } +} + +#[embassy::main] +async fn main(spawner: Spawner, _p: Peripherals) { + unwrap!(spawner.spawn(my_sending_task())); + + loop { + let received_counter = SIGNAL.wait().await; + + info!("signalled, counter: {}", received_counter); + } +} From b0ffd9a1cc6ae19f4698f704df037e5dd6f5fb97 Mon Sep 17 00:00:00 2001 From: chemicstry Date: Mon, 6 Jun 2022 17:05:37 +0300 Subject: [PATCH 2/3] Fix AF pullup configuration for GPIOv1 --- embassy-stm32/src/gpio.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index b6982e91..f7a5da0a 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs @@ -424,9 +424,14 @@ pub(crate) mod sealed { } } + #[inline] + unsafe fn set_as_af(&self, af_num: u8, af_type: AFType) { + self.set_as_af_pull(af_num, af_type, Pull::None); + } + #[cfg(gpio_v1)] #[inline] - unsafe fn set_as_af(&self, _af_num: u8, af_type: AFType) { + unsafe fn set_as_af_pull(&self, _af_num: u8, af_type: AFType, pull: Pull) { // F1 uses the AFIO register for remapping. // For now, this is not implemented, so af_num is ignored // _af_num should be zero here, since it is not set by stm32-data @@ -435,9 +440,21 @@ pub(crate) mod sealed { let crlh = if n < 8 { 0 } else { 1 }; match af_type { AFType::Input => { + let cnf = match pull { + Pull::Up => { + r.bsrr().write(|w| w.set_bs(n, true)); + vals::CnfIn::PULL + } + Pull::Down => { + r.bsrr().write(|w| w.set_br(n, true)); + vals::CnfIn::PULL + } + Pull::None => vals::CnfIn::FLOATING, + }; + r.cr(crlh).modify(|w| { w.set_mode(n % 8, vals::Mode::INPUT); - w.set_cnf_in(n % 8, vals::CnfIn::FLOATING); + w.set_cnf_in(n % 8, cnf); }); } AFType::OutputPushPull => { @@ -455,12 +472,6 @@ pub(crate) mod sealed { } } - #[cfg(gpio_v2)] - #[inline] - unsafe fn set_as_af(&self, af_num: u8, af_type: AFType) { - self.set_as_af_pull(af_num, af_type, Pull::None); - } - #[cfg(gpio_v2)] #[inline] unsafe fn set_as_af_pull(&self, af_num: u8, af_type: AFType, pull: Pull) { From fdc6cfed3e813aadffae607a5374e5b358bd9231 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 6 Jun 2022 17:43:55 +0200 Subject: [PATCH 3/3] stm32: add stm32f103re to CI --- ci.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ci.sh b/ci.sh index 1085ad96..ff33c8ad 100755 --- a/ci.sh +++ b/ci.sh @@ -59,6 +59,7 @@ cargo batch \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32wl54jc-cm0p,defmt,exti,time-driver-any,embassy/time-tick-32768hz,unstable-traits \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wle5ub,defmt,exti,time-driver-any,embassy/time-tick-32768hz,unstable-traits \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f107vc,defmt,exti,time-driver-any,embassy/time-tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f103re,defmt,exti,time-driver-any,embassy/time-tick-32768hz,unstable-traits \ --- build --release --manifest-path embassy-boot/nrf/Cargo.toml --target thumbv7em-none-eabi --features embassy-nrf/nrf52840 \ --- build --release --manifest-path embassy-boot/stm32/Cargo.toml --target thumbv7em-none-eabi --features embassy-stm32/stm32wl55jc-cm4,embassy/time-tick-32768hz \ --- build --release --manifest-path docs/modules/ROOT/examples/basic/Cargo.toml --target thumbv7em-none-eabi \