From 61c666212fa04571a74c27f649526459a376aa8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Kr=C3=B6ger?= Date: Fri, 24 Jun 2022 14:31:30 +0200 Subject: [PATCH] stm32wl: Do not require external SPI pins for SUBGHZ For the Seeed Studio Lora-E5 those pins conflict with the radio frontend control GPIOS (PA4 and PA5). --- embassy-stm32/src/spi/mod.rs | 12 ++++++++++++ embassy-stm32/src/subghz/mod.rs | 7 ++----- examples/stm32wl/src/bin/lorawan.rs | 2 +- examples/stm32wl/src/bin/subghz.rs | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 26fb392ef..1a00f4187 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -179,6 +179,18 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { ) } + /// Useful for on chip peripherals like SUBGHZ which are hardwired. + /// The bus can optionally be exposed externally with `Spi::new()` still. + pub fn new_internal( + peri: impl Peripheral

+ 'd, + txdma: impl Peripheral

+ 'd, + rxdma: impl Peripheral

+ 'd, + freq: Hertz, + config: Config, + ) -> Self { + Self::new_inner(peri, None, None, None, txdma, rxdma, freq, config) + } + fn new_inner( peri: impl Peripheral

+ 'd, sck: Option>, diff --git a/embassy-stm32/src/subghz/mod.rs b/embassy-stm32/src/subghz/mod.rs index a74f9a6d5..33398fa1d 100644 --- a/embassy-stm32/src/subghz/mod.rs +++ b/embassy-stm32/src/subghz/mod.rs @@ -81,7 +81,7 @@ pub use value_error::ValueError; use crate::dma::NoDma; use crate::peripherals::SUBGHZSPI; use crate::rcc::sealed::RccPeripheral; -use crate::spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0}; +use crate::spi::{BitOrder, Config as SpiConfig, Spi, MODE_0}; use crate::time::Hertz; use crate::{pac, Peripheral}; @@ -212,9 +212,6 @@ impl<'d, Tx, Rx> SubGhz<'d, Tx, Rx> { /// clock. pub fn new( peri: impl Peripheral

+ 'd, - sck: impl Peripheral

> + 'd, - mosi: impl Peripheral

> + 'd, - miso: impl Peripheral

> + 'd, txdma: impl Peripheral

+ 'd, rxdma: impl Peripheral

+ 'd, ) -> Self { @@ -227,7 +224,7 @@ impl<'d, Tx, Rx> SubGhz<'d, Tx, Rx> { let mut config = SpiConfig::default(); config.mode = MODE_0; config.bit_order = BitOrder::MsbFirst; - let spi = Spi::new(peri, sck, mosi, miso, txdma, rxdma, clk, config); + let spi = Spi::new_internal(peri, txdma, rxdma, clk, config); unsafe { wakeup() }; diff --git a/examples/stm32wl/src/bin/lorawan.rs b/examples/stm32wl/src/bin/lorawan.rs index 7e8a8946d..fdd7eb8cf 100644 --- a/examples/stm32wl/src/bin/lorawan.rs +++ b/examples/stm32wl/src/bin/lorawan.rs @@ -31,7 +31,7 @@ async fn main(_spawner: Spawner) { let ctrl3 = Output::new(p.PC5.degrade(), Level::High, Speed::High); let rfs = RadioSwitch::new(ctrl1, ctrl2, ctrl3); - let radio = SubGhz::new(p.SUBGHZSPI, p.PA5, p.PA7, p.PA6, NoDma, NoDma); + let radio = SubGhz::new(p.SUBGHZSPI, NoDma, NoDma); let irq = interrupt::take!(SUBGHZ_RADIO); static mut RADIO_STATE: SubGhzState<'static> = SubGhzState::new(); diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs index c5e9bb597..8f674d796 100644 --- a/examples/stm32wl/src/bin/subghz.rs +++ b/examples/stm32wl/src/bin/subghz.rs @@ -72,7 +72,7 @@ async fn main(_spawner: Spawner) { unsafe { interrupt::SUBGHZ_RADIO::steal() }.disable(); }); - let mut radio = SubGhz::new(p.SUBGHZSPI, p.PA5, p.PA7, p.PA6, NoDma, NoDma); + let mut radio = SubGhz::new(p.SUBGHZSPI, NoDma, NoDma); defmt::info!("Radio ready for use");