From 6b1d802caa9ca5a2b6d33bf345c0599b990311fa Mon Sep 17 00:00:00 2001
From: bofh <123368+bofh@users.noreply.github.com>
Date: Sun, 30 Jul 2023 18:01:34 +0200
Subject: [PATCH 1/9] Move frequency to SPI config
---
embassy-stm32/src/spi/mod.rs | 66 ++++++++++++++++++++++++++----------
1 file changed, 49 insertions(+), 17 deletions(-)
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs
index bdf3c85b..bbc7c3b9 100644
--- a/embassy-stm32/src/spi/mod.rs
+++ b/embassy-stm32/src/spi/mod.rs
@@ -36,6 +36,7 @@ pub enum BitOrder {
pub struct Config {
pub mode: Mode,
pub bit_order: BitOrder,
+ pub frequency: Hertz,
}
impl Default for Config {
@@ -43,6 +44,7 @@ impl Default for Config {
Self {
mode: MODE_0,
bit_order: BitOrder::MsbFirst,
+ frequency: Hertz(1_000_000),
}
}
}
@@ -88,7 +90,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
miso: impl Peripheral
> + 'd,
txdma: impl Peripheral
+ 'd,
rxdma: impl Peripheral
+ 'd,
- freq: Hertz,
config: Config,
) -> Self {
into_ref!(peri, sck, mosi, miso);
@@ -112,7 +113,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
Some(miso.map_into()),
txdma,
rxdma,
- freq,
config,
)
}
@@ -123,7 +123,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
miso: impl Peripheral
> + 'd,
txdma: impl Peripheral
+ 'd, // TODO remove
rxdma: impl Peripheral
+ 'd,
- freq: Hertz,
config: Config,
) -> Self {
into_ref!(sck, miso);
@@ -139,7 +138,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
Some(miso.map_into()),
txdma,
rxdma,
- freq,
config,
)
}
@@ -150,7 +148,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
mosi: impl Peripheral
> + 'd,
txdma: impl Peripheral
+ 'd,
rxdma: impl Peripheral
+ 'd, // TODO remove
- freq: Hertz,
config: Config,
) -> Self {
into_ref!(sck, mosi);
@@ -166,7 +163,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
None,
txdma,
rxdma,
- freq,
config,
)
}
@@ -176,14 +172,13 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
mosi: impl Peripheral
> + 'd,
txdma: impl Peripheral
+ 'd,
rxdma: impl Peripheral
+ 'd, // TODO: remove
- freq: Hertz,
config: Config,
) -> Self {
into_ref!(mosi);
mosi.set_as_af_pull(mosi.af_num(), AFType::OutputPushPull, Pull::Down);
mosi.set_speed(crate::gpio::Speed::Medium);
- Self::new_inner(peri, None, Some(mosi.map_into()), None, txdma, rxdma, freq, config)
+ Self::new_inner(peri, None, Some(mosi.map_into()), None, txdma, rxdma, config)
}
#[cfg(stm32wl)]
@@ -201,7 +196,8 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
let mut config = Config::default();
config.mode = MODE_0;
config.bit_order = BitOrder::MsbFirst;
- Self::new_inner(peri, None, None, None, txdma, rxdma, freq, config)
+ config.frequency = freq;
+ Self::new_inner(peri, None, None, None, txdma, rxdma, config)
}
#[allow(dead_code)]
@@ -209,10 +205,9 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
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)
+ Self::new_inner(peri, None, None, None, txdma, rxdma, config)
}
fn new_inner(
@@ -222,12 +217,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
miso: Option>,
txdma: impl Peripheral + 'd,
rxdma: impl Peripheral
+ 'd,
- freq: Hertz,
config: Config,
) -> Self {
into_ref!(peri, txdma, rxdma);
let pclk = T::frequency();
+ let freq = config.frequency;
let br = compute_baud_rate(pclk, freq.into());
let cpha = config.raw_phase();
@@ -334,19 +329,29 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
let lsbfirst = config.raw_byte_order();
+ let pclk = T::frequency();
+ let freq = config.frequency;
+ let br = compute_baud_rate(pclk, freq.into());
+
#[cfg(any(spi_v1, spi_f1, spi_v2))]
T::REGS.cr1().modify(|w| {
w.set_cpha(cpha);
w.set_cpol(cpol);
+ w.set_br(br);
w.set_lsbfirst(lsbfirst);
});
#[cfg(any(spi_v3, spi_v4, spi_v5))]
- T::REGS.cfg2().modify(|w| {
- w.set_cpha(cpha);
- w.set_cpol(cpol);
- w.set_lsbfirst(lsbfirst);
- });
+ {
+ T::REGS.cfg2().modify(|w| {
+ w.set_cpha(cpha);
+ w.set_cpol(cpol);
+ w.set_lsbfirst(lsbfirst);
+ });
+ T::REGS.cfg1().modify(|w| {
+ w.set_mbr(br);
+ });
+ }
}
pub fn get_current_config(&self) -> Config {
@@ -354,6 +359,9 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
let cfg = T::REGS.cr1().read();
#[cfg(any(spi_v3, spi_v4, spi_v5))]
let cfg = T::REGS.cfg2().read();
+ #[cfg(any(spi_v3, spi_v4, spi_v5))]
+ let cfg1 = T::REGS.cfg1().read();
+
let polarity = if cfg.cpol() == vals::Cpol::IDLELOW {
Polarity::IdleLow
} else {
@@ -371,9 +379,18 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
BitOrder::MsbFirst
};
+ #[cfg(any(spi_v1, spi_f1, spi_v2))]
+ let br = cfg.br();
+ #[cfg(any(spi_v3, spi_v4, spi_v5))]
+ let br = cfg1.mbr();
+
+ let pclk = T::frequency();
+ let frequency = compute_frequency(pclk, br);
+
Config {
mode: Mode { polarity, phase },
bit_order,
+ frequency,
}
}
@@ -653,6 +670,21 @@ fn compute_baud_rate(clocks: Hertz, freq: Hertz) -> Br {
Br::from_bits(val)
}
+fn compute_frequency(clocks: Hertz, br: Br) -> Hertz {
+ let div: u16 = match br {
+ Br::DIV2 => 2,
+ Br::DIV4 => 4,
+ Br::DIV8 => 8,
+ Br::DIV16 => 16,
+ Br::DIV32 => 32,
+ Br::DIV64 => 64,
+ Br::DIV128 => 128,
+ Br::DIV256 => 256,
+ };
+
+ clocks / div
+}
+
trait RegsExt {
fn tx_ptr(&self) -> *mut W;
fn rx_ptr(&self) -> *mut W;
From aef93246b429cf892ad212aefc8ca0e5ddc29c18 Mon Sep 17 00:00:00 2001
From: bofh <123368+bofh@users.noreply.github.com>
Date: Sun, 30 Jul 2023 18:11:39 +0200
Subject: [PATCH 2/9] Fix Spi::new_internal call in i2s
---
embassy-stm32/src/i2s.rs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs
index 1ccad732..f5103676 100644
--- a/embassy-stm32/src/i2s.rs
+++ b/embassy-stm32/src/i2s.rs
@@ -165,7 +165,9 @@ impl<'d, T: Instance, Tx, Rx> I2S<'d, T, Tx, Rx> {
mck.set_as_af(mck.af_num(), AFType::OutputPushPull);
mck.set_speed(crate::gpio::Speed::VeryHigh);
- let spi = Spi::new_internal(peri, txdma, rxdma, freq, SpiConfig::default());
+ let mut spi_cfg = SpiConfig::default();
+ spi_cfg.freq = freq;
+ let spi = Spi::new_internal(peri, txdma, rxdma, spi_cfg);
#[cfg(all(rcc_f4, not(stm32f410)))]
let pclk = unsafe { get_freqs() }.plli2s.unwrap();
From 1d815f4ba09b7be88e650690806e18c8a4d8e051 Mon Sep 17 00:00:00 2001
From: bofh <123368+bofh@users.noreply.github.com>
Date: Sun, 30 Jul 2023 18:20:36 +0200
Subject: [PATCH 3/9] Fix typo
---
embassy-stm32/src/i2s.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs
index f5103676..8fd3a8c6 100644
--- a/embassy-stm32/src/i2s.rs
+++ b/embassy-stm32/src/i2s.rs
@@ -166,7 +166,7 @@ impl<'d, T: Instance, Tx, Rx> I2S<'d, T, Tx, Rx> {
mck.set_speed(crate::gpio::Speed::VeryHigh);
let mut spi_cfg = SpiConfig::default();
- spi_cfg.freq = freq;
+ spi_cfg.frequency = freq;
let spi = Spi::new_internal(peri, txdma, rxdma, spi_cfg);
#[cfg(all(rcc_f4, not(stm32f410)))]
From d2127f6b82e7a97744c81e2a3628ced59d8f1b49 Mon Sep 17 00:00:00 2001
From: bofh <123368+bofh@users.noreply.github.com>
Date: Sun, 30 Jul 2023 18:58:40 +0200
Subject: [PATCH 4/9] Fix stm32 SPI examples
---
examples/stm32f3/src/bin/spi_dma.rs | 2 --
examples/stm32f4/src/bin/spi.rs | 12 +-----------
examples/stm32f4/src/bin/spi_dma.rs | 2 --
examples/stm32g0/src/bin/spi_neopixel.rs | 4 +++-
examples/stm32l0/src/bin/spi.rs | 2 --
examples/stm32l1/src/bin/spi.rs | 2 --
examples/stm32l4/src/bin/spi.rs | 12 +-----------
examples/stm32l4/src/bin/spi_blocking_async.rs | 2 --
examples/stm32l4/src/bin/spi_dma.rs | 2 --
9 files changed, 5 insertions(+), 35 deletions(-)
diff --git a/examples/stm32f3/src/bin/spi_dma.rs b/examples/stm32f3/src/bin/spi_dma.rs
index 95b2b686..d8cdb7e6 100644
--- a/examples/stm32f3/src/bin/spi_dma.rs
+++ b/examples/stm32f3/src/bin/spi_dma.rs
@@ -8,7 +8,6 @@ use core::str::from_utf8;
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::spi::{Config, Spi};
-use embassy_stm32::time::Hertz;
use heapless::String;
use {defmt_rtt as _, panic_probe as _};
@@ -24,7 +23,6 @@ async fn main(_spawner: Spawner) {
p.PB4,
p.DMA1_CH3,
p.DMA1_CH2,
- Hertz(1_000_000),
Config::default(),
);
diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs
index 05b48f47..b0c62b3f 100644
--- a/examples/stm32f4/src/bin/spi.rs
+++ b/examples/stm32f4/src/bin/spi.rs
@@ -7,7 +7,6 @@ use defmt::*;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
-use embassy_stm32::time::Hertz;
use {defmt_rtt as _, panic_probe as _};
#[entry]
@@ -16,16 +15,7 @@ fn main() -> ! {
let p = embassy_stm32::init(Default::default());
- let mut spi = Spi::new(
- p.SPI3,
- p.PC10,
- p.PC12,
- p.PC11,
- NoDma,
- NoDma,
- Hertz(1_000_000),
- Config::default(),
- );
+ let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, Config::default());
let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh);
diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs
index 3d2a1a1a..d421b9d5 100644
--- a/examples/stm32f4/src/bin/spi_dma.rs
+++ b/examples/stm32f4/src/bin/spi_dma.rs
@@ -8,7 +8,6 @@ use core::str::from_utf8;
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::spi::{Config, Spi};
-use embassy_stm32::time::Hertz;
use heapless::String;
use {defmt_rtt as _, panic_probe as _};
@@ -24,7 +23,6 @@ async fn main(_spawner: Spawner) {
p.PB4,
p.DMA2_CH3,
p.DMA2_CH2,
- Hertz(1_000_000),
Config::default(),
);
diff --git a/examples/stm32g0/src/bin/spi_neopixel.rs b/examples/stm32g0/src/bin/spi_neopixel.rs
index 81fdd15c..ee7aaf33 100644
--- a/examples/stm32g0/src/bin/spi_neopixel.rs
+++ b/examples/stm32g0/src/bin/spi_neopixel.rs
@@ -76,7 +76,9 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Start test using spi as neopixel driver");
- let mut spi = Spi::new_txonly_nosck(p.SPI1, p.PB5, p.DMA1_CH3, NoDma, Hertz(4_000_000), Config::default());
+ let mut config = Config::default();
+ config.frequency = Hertz(4_000_000);
+ let mut spi = Spi::new_txonly_nosck(p.SPI1, p.PB5, p.DMA1_CH3, NoDma, config);
let mut neopixels = Ws2812::new();
diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs
index 9b5b3e27..54b7a2dd 100644
--- a/examples/stm32l0/src/bin/spi.rs
+++ b/examples/stm32l0/src/bin/spi.rs
@@ -7,7 +7,6 @@ use embassy_executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
-use embassy_stm32::time::Hertz;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@@ -22,7 +21,6 @@ async fn main(_spawner: Spawner) {
p.PA6,
NoDma,
NoDma,
- Hertz(1_000_000),
Config::default(),
);
diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs
index 0a532e8e..34faf061 100644
--- a/examples/stm32l1/src/bin/spi.rs
+++ b/examples/stm32l1/src/bin/spi.rs
@@ -7,7 +7,6 @@ use embassy_executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
-use embassy_stm32::time::Hertz;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@@ -22,7 +21,6 @@ async fn main(_spawner: Spawner) {
p.PA6,
NoDma,
NoDma,
- Hertz(1_000_000),
Config::default(),
);
diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs
index 76e316a2..a3097fb4 100644
--- a/examples/stm32l4/src/bin/spi.rs
+++ b/examples/stm32l4/src/bin/spi.rs
@@ -6,7 +6,6 @@ use defmt::*;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
-use embassy_stm32::time::Hertz;
use {defmt_rtt as _, panic_probe as _};
#[cortex_m_rt::entry]
@@ -15,16 +14,7 @@ fn main() -> ! {
let p = embassy_stm32::init(Default::default());
- let mut spi = Spi::new(
- p.SPI3,
- p.PC10,
- p.PC12,
- p.PC11,
- NoDma,
- NoDma,
- Hertz(1_000_000),
- Config::default(),
- );
+ let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, Config::default());
let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh);
diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs
index 62ef0130..868e2211 100644
--- a/examples/stm32l4/src/bin/spi_blocking_async.rs
+++ b/examples/stm32l4/src/bin/spi_blocking_async.rs
@@ -8,7 +8,6 @@ use embassy_executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::spi::{Config, Spi};
-use embassy_stm32::time::Hertz;
use embedded_hal_async::spi::SpiBus;
use {defmt_rtt as _, panic_probe as _};
@@ -24,7 +23,6 @@ async fn main(_spawner: Spawner) {
p.PC11,
NoDma,
NoDma,
- Hertz(1_000_000),
Config::default(),
);
diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs
index 89471db5..01265c49 100644
--- a/examples/stm32l4/src/bin/spi_dma.rs
+++ b/examples/stm32l4/src/bin/spi_dma.rs
@@ -6,7 +6,6 @@ use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::spi::{Config, Spi};
-use embassy_stm32::time::Hertz;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@@ -21,7 +20,6 @@ async fn main(_spawner: Spawner) {
p.PC11,
p.DMA1_CH1,
p.DMA1_CH2,
- Hertz(1_000_000),
Config::default(),
);
From 4f791799a9c05e7e34c70d47ac0b2e885d5714a0 Mon Sep 17 00:00:00 2001
From: bofh <123368+bofh@users.noreply.github.com>
Date: Sun, 30 Jul 2023 19:12:49 +0200
Subject: [PATCH 5/9] Fix formatting
---
examples/stm32f3/src/bin/spi_dma.rs | 10 +---------
examples/stm32f4/src/bin/spi_dma.rs | 10 +---------
examples/stm32l0/src/bin/spi.rs | 10 +---------
examples/stm32l1/src/bin/spi.rs | 10 +---------
examples/stm32l4/src/bin/spi_blocking_async.rs | 10 +---------
5 files changed, 5 insertions(+), 45 deletions(-)
diff --git a/examples/stm32f3/src/bin/spi_dma.rs b/examples/stm32f3/src/bin/spi_dma.rs
index d8cdb7e6..6a39097d 100644
--- a/examples/stm32f3/src/bin/spi_dma.rs
+++ b/examples/stm32f3/src/bin/spi_dma.rs
@@ -16,15 +16,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
- let mut spi = Spi::new(
- p.SPI1,
- p.PB3,
- p.PB5,
- p.PB4,
- p.DMA1_CH3,
- p.DMA1_CH2,
- Config::default(),
- );
+ let mut spi = Spi::new(p.SPI1, p.PB3, p.PB5, p.PB4, p.DMA1_CH3, p.DMA1_CH2, Config::default());
for n in 0u32.. {
let mut write: String<128> = String::new();
diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs
index d421b9d5..4edea93a 100644
--- a/examples/stm32f4/src/bin/spi_dma.rs
+++ b/examples/stm32f4/src/bin/spi_dma.rs
@@ -16,15 +16,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
- let mut spi = Spi::new(
- p.SPI1,
- p.PB3,
- p.PB5,
- p.PB4,
- p.DMA2_CH3,
- p.DMA2_CH2,
- Config::default(),
- );
+ let mut spi = Spi::new(p.SPI1, p.PB3, p.PB5, p.PB4, p.DMA2_CH3, p.DMA2_CH2, Config::default());
for n in 0u32.. {
let mut write: String<128> = String::new();
diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs
index 54b7a2dd..24ea9a68 100644
--- a/examples/stm32l0/src/bin/spi.rs
+++ b/examples/stm32l0/src/bin/spi.rs
@@ -14,15 +14,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World, folks!");
- let mut spi = Spi::new(
- p.SPI1,
- p.PB3,
- p.PA7,
- p.PA6,
- NoDma,
- NoDma,
- Config::default(),
- );
+ let mut spi = Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, NoDma, NoDma, Config::default());
let mut cs = Output::new(p.PA15, Level::High, Speed::VeryHigh);
diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs
index 34faf061..53523140 100644
--- a/examples/stm32l1/src/bin/spi.rs
+++ b/examples/stm32l1/src/bin/spi.rs
@@ -14,15 +14,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World, folks!");
- let mut spi = Spi::new(
- p.SPI1,
- p.PA5,
- p.PA7,
- p.PA6,
- NoDma,
- NoDma,
- Config::default(),
- );
+ let mut spi = Spi::new(p.SPI1, p.PA5, p.PA7, p.PA6, NoDma, NoDma, Config::default());
let mut cs = Output::new(p.PA4, Level::High, Speed::VeryHigh);
diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs
index 868e2211..45af8a9f 100644
--- a/examples/stm32l4/src/bin/spi_blocking_async.rs
+++ b/examples/stm32l4/src/bin/spi_blocking_async.rs
@@ -16,15 +16,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
- let spi = Spi::new(
- p.SPI3,
- p.PC10,
- p.PC12,
- p.PC11,
- NoDma,
- NoDma,
- Config::default(),
- );
+ let spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, Config::default());
let mut spi = BlockingAsync::new(spi);
From 55fb1d51268e87b522ba47e4cdc04978e9880ab0 Mon Sep 17 00:00:00 2001
From: bofh <123368+bofh@users.noreply.github.com>
Date: Sun, 30 Jul 2023 19:26:24 +0200
Subject: [PATCH 6/9] Fix more stm32 SPI examples
---
examples/stm32h7/src/bin/spi.rs | 6 ++++--
examples/stm32h7/src/bin/spi_dma.rs | 6 ++++--
examples/stm32l0/src/bin/lora_cad.rs | 6 ++++--
examples/stm32l0/src/bin/lora_lorawan.rs | 6 ++++--
examples/stm32l0/src/bin/lora_p2p_receive.rs | 6 ++++--
examples/stm32l0/src/bin/lora_p2p_send.rs | 6 ++++--
tests/stm32/src/bin/spi.rs | 1 -
tests/stm32/src/bin/spi_dma.rs | 1 -
8 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs
index 1f407f00..051a8392 100644
--- a/examples/stm32h7/src/bin/spi.rs
+++ b/examples/stm32h7/src/bin/spi.rs
@@ -43,6 +43,9 @@ fn main() -> ! {
config.rcc.pll1.q_ck = Some(mhz(100));
let p = embassy_stm32::init(config);
+ let mut spi_config = spi::Config::default();
+ spi_config.frequency = mhz(1);
+
let spi = spi::Spi::new(
p.SPI3,
p.PB3,
@@ -50,8 +53,7 @@ fn main() -> ! {
p.PB4,
NoDma,
NoDma,
- mhz(1),
- spi::Config::default(),
+ spi_config,
);
let executor = EXECUTOR.init(Executor::new());
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs
index 53004fc9..5e878ee6 100644
--- a/examples/stm32h7/src/bin/spi_dma.rs
+++ b/examples/stm32h7/src/bin/spi_dma.rs
@@ -39,6 +39,9 @@ fn main() -> ! {
config.rcc.pll1.q_ck = Some(mhz(100));
let p = embassy_stm32::init(config);
+ let mut spi_config = spi::Config::default();
+ spi_config.frequency = mhz(1);
+
let spi = spi::Spi::new(
p.SPI3,
p.PB3,
@@ -46,8 +49,7 @@ fn main() -> ! {
p.PB4,
p.DMA1_CH3,
p.DMA1_CH4,
- mhz(1),
- spi::Config::default(),
+ spi_config,
);
let executor = EXECUTOR.init(Executor::new());
diff --git a/examples/stm32l0/src/bin/lora_cad.rs b/examples/stm32l0/src/bin/lora_cad.rs
index 588cea1e..ae2393e5 100644
--- a/examples/stm32l0/src/bin/lora_cad.rs
+++ b/examples/stm32l0/src/bin/lora_cad.rs
@@ -27,6 +27,9 @@ async fn main(_spawner: Spawner) {
config.rcc.enable_hsi48 = true;
let p = embassy_stm32::init(config);
+ let mut spi_config = spi::Config::default();
+ spi_config.frequency = khz(200);
+
// SPI for sx1276
let spi = spi::Spi::new(
p.SPI1,
@@ -35,8 +38,7 @@ async fn main(_spawner: Spawner) {
p.PA6,
p.DMA1_CH3,
p.DMA1_CH2,
- khz(200),
- spi::Config::default(),
+ spi_config,
);
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
diff --git a/examples/stm32l0/src/bin/lora_lorawan.rs b/examples/stm32l0/src/bin/lora_lorawan.rs
index c397edd5..2202deea 100644
--- a/examples/stm32l0/src/bin/lora_lorawan.rs
+++ b/examples/stm32l0/src/bin/lora_lorawan.rs
@@ -32,6 +32,9 @@ async fn main(_spawner: Spawner) {
config.rcc.enable_hsi48 = true;
let p = embassy_stm32::init(config);
+ let mut spi_config = spi::Config::default();
+ spi_config.frequency = khz(200);
+
// SPI for sx1276
let spi = spi::Spi::new(
p.SPI1,
@@ -40,8 +43,7 @@ async fn main(_spawner: Spawner) {
p.PA6,
p.DMA1_CH3,
p.DMA1_CH2,
- khz(200),
- spi::Config::default(),
+ spi_config,
);
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
diff --git a/examples/stm32l0/src/bin/lora_p2p_receive.rs b/examples/stm32l0/src/bin/lora_p2p_receive.rs
index bb750950..9b6b18b8 100644
--- a/examples/stm32l0/src/bin/lora_p2p_receive.rs
+++ b/examples/stm32l0/src/bin/lora_p2p_receive.rs
@@ -27,6 +27,9 @@ async fn main(_spawner: Spawner) {
config.rcc.enable_hsi48 = true;
let p = embassy_stm32::init(config);
+ let mut spi_config = spi::Config::default();
+ spi_config.frequency = khz(200);
+
// SPI for sx1276
let spi = spi::Spi::new(
p.SPI1,
@@ -35,8 +38,7 @@ async fn main(_spawner: Spawner) {
p.PA6,
p.DMA1_CH3,
p.DMA1_CH2,
- khz(200),
- spi::Config::default(),
+ spi_config,
);
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
diff --git a/examples/stm32l0/src/bin/lora_p2p_send.rs b/examples/stm32l0/src/bin/lora_p2p_send.rs
index e6fadc01..90bae31e 100644
--- a/examples/stm32l0/src/bin/lora_p2p_send.rs
+++ b/examples/stm32l0/src/bin/lora_p2p_send.rs
@@ -27,6 +27,9 @@ async fn main(_spawner: Spawner) {
config.rcc.enable_hsi48 = true;
let p = embassy_stm32::init(config);
+ let mut spi_config = spi::Config::default();
+ spi_config.frequency = khz(200);
+
// SPI for sx1276
let spi = spi::Spi::new(
p.SPI1,
@@ -35,8 +38,7 @@ async fn main(_spawner: Spawner) {
p.PA6,
p.DMA1_CH3,
p.DMA1_CH2,
- khz(200),
- spi::Config::default(),
+ spi_config,
);
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs
index 819ecae3..72a8c92e 100644
--- a/tests/stm32/src/bin/spi.rs
+++ b/tests/stm32/src/bin/spi.rs
@@ -42,7 +42,6 @@ async fn main(_spawner: Spawner) {
miso, // Arduino D12
NoDma,
NoDma,
- Hertz(1_000_000),
spi::Config::default(),
);
diff --git a/tests/stm32/src/bin/spi_dma.rs b/tests/stm32/src/bin/spi_dma.rs
index 78aad24e..443aab57 100644
--- a/tests/stm32/src/bin/spi_dma.rs
+++ b/tests/stm32/src/bin/spi_dma.rs
@@ -41,7 +41,6 @@ async fn main(_spawner: Spawner) {
miso, // Arduino D12
tx_dma,
rx_dma,
- Hertz(1_000_000),
spi::Config::default(),
);
From 04ed45941a22867c8879582586677ba719bc2b4b Mon Sep 17 00:00:00 2001
From: bofh <123368+bofh@users.noreply.github.com>
Date: Sun, 30 Jul 2023 19:31:22 +0200
Subject: [PATCH 7/9] Fix format in stm32 SPI examples
---
examples/stm32h7/src/bin/spi.rs | 10 +---------
examples/stm32h7/src/bin/spi_dma.rs | 10 +---------
examples/stm32l0/src/bin/lora_cad.rs | 10 +---------
examples/stm32l0/src/bin/lora_lorawan.rs | 10 +---------
examples/stm32l0/src/bin/lora_p2p_receive.rs | 10 +---------
examples/stm32l0/src/bin/lora_p2p_send.rs | 10 +---------
6 files changed, 6 insertions(+), 54 deletions(-)
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs
index 051a8392..28bba2b8 100644
--- a/examples/stm32h7/src/bin/spi.rs
+++ b/examples/stm32h7/src/bin/spi.rs
@@ -46,15 +46,7 @@ fn main() -> ! {
let mut spi_config = spi::Config::default();
spi_config.frequency = mhz(1);
- let spi = spi::Spi::new(
- p.SPI3,
- p.PB3,
- p.PB5,
- p.PB4,
- NoDma,
- NoDma,
- spi_config,
- );
+ let spi = spi::Spi::new(p.SPI3, p.PB3, p.PB5, p.PB4, NoDma, NoDma, spi_config);
let executor = EXECUTOR.init(Executor::new());
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs
index 5e878ee6..f6e30cfa 100644
--- a/examples/stm32h7/src/bin/spi_dma.rs
+++ b/examples/stm32h7/src/bin/spi_dma.rs
@@ -42,15 +42,7 @@ fn main() -> ! {
let mut spi_config = spi::Config::default();
spi_config.frequency = mhz(1);
- let spi = spi::Spi::new(
- p.SPI3,
- p.PB3,
- p.PB5,
- p.PB4,
- p.DMA1_CH3,
- p.DMA1_CH4,
- spi_config,
- );
+ let spi = spi::Spi::new(p.SPI3, p.PB3, p.PB5, p.PB4, p.DMA1_CH3, p.DMA1_CH4, spi_config);
let executor = EXECUTOR.init(Executor::new());
diff --git a/examples/stm32l0/src/bin/lora_cad.rs b/examples/stm32l0/src/bin/lora_cad.rs
index ae2393e5..7729b416 100644
--- a/examples/stm32l0/src/bin/lora_cad.rs
+++ b/examples/stm32l0/src/bin/lora_cad.rs
@@ -31,15 +31,7 @@ async fn main(_spawner: Spawner) {
spi_config.frequency = khz(200);
// SPI for sx1276
- let spi = spi::Spi::new(
- p.SPI1,
- p.PB3,
- p.PA7,
- p.PA6,
- p.DMA1_CH3,
- p.DMA1_CH2,
- spi_config,
- );
+ let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
diff --git a/examples/stm32l0/src/bin/lora_lorawan.rs b/examples/stm32l0/src/bin/lora_lorawan.rs
index 2202deea..620c9f4f 100644
--- a/examples/stm32l0/src/bin/lora_lorawan.rs
+++ b/examples/stm32l0/src/bin/lora_lorawan.rs
@@ -36,15 +36,7 @@ async fn main(_spawner: Spawner) {
spi_config.frequency = khz(200);
// SPI for sx1276
- let spi = spi::Spi::new(
- p.SPI1,
- p.PB3,
- p.PA7,
- p.PA6,
- p.DMA1_CH3,
- p.DMA1_CH2,
- spi_config,
- );
+ let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
diff --git a/examples/stm32l0/src/bin/lora_p2p_receive.rs b/examples/stm32l0/src/bin/lora_p2p_receive.rs
index 9b6b18b8..0f9f6095 100644
--- a/examples/stm32l0/src/bin/lora_p2p_receive.rs
+++ b/examples/stm32l0/src/bin/lora_p2p_receive.rs
@@ -31,15 +31,7 @@ async fn main(_spawner: Spawner) {
spi_config.frequency = khz(200);
// SPI for sx1276
- let spi = spi::Spi::new(
- p.SPI1,
- p.PB3,
- p.PA7,
- p.PA6,
- p.DMA1_CH3,
- p.DMA1_CH2,
- spi_config,
- );
+ let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
diff --git a/examples/stm32l0/src/bin/lora_p2p_send.rs b/examples/stm32l0/src/bin/lora_p2p_send.rs
index 90bae31e..c85c3c2b 100644
--- a/examples/stm32l0/src/bin/lora_p2p_send.rs
+++ b/examples/stm32l0/src/bin/lora_p2p_send.rs
@@ -31,15 +31,7 @@ async fn main(_spawner: Spawner) {
spi_config.frequency = khz(200);
// SPI for sx1276
- let spi = spi::Spi::new(
- p.SPI1,
- p.PB3,
- p.PA7,
- p.PA6,
- p.DMA1_CH3,
- p.DMA1_CH2,
- spi_config,
- );
+ let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
From d8420ed5a0cd96eef86c213a40c0bd84f4da0afe Mon Sep 17 00:00:00 2001
From: bofh <123368+bofh@users.noreply.github.com>
Date: Sun, 30 Jul 2023 19:34:27 +0200
Subject: [PATCH 8/9] Remove unused imports
---
tests/stm32/src/bin/spi.rs | 1 -
tests/stm32/src/bin/spi_dma.rs | 1 -
2 files changed, 2 deletions(-)
diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs
index 72a8c92e..7c2425fc 100644
--- a/tests/stm32/src/bin/spi.rs
+++ b/tests/stm32/src/bin/spi.rs
@@ -9,7 +9,6 @@ use defmt::assert_eq;
use embassy_executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::spi::{self, Spi};
-use embassy_stm32::time::Hertz;
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
diff --git a/tests/stm32/src/bin/spi_dma.rs b/tests/stm32/src/bin/spi_dma.rs
index 443aab57..e70c09f7 100644
--- a/tests/stm32/src/bin/spi_dma.rs
+++ b/tests/stm32/src/bin/spi_dma.rs
@@ -8,7 +8,6 @@ use common::*;
use defmt::assert_eq;
use embassy_executor::Spawner;
use embassy_stm32::spi::{self, Spi};
-use embassy_stm32::time::Hertz;
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
From d8f02e151b50f9d5156d5dd60911ea0f27ddedf0 Mon Sep 17 00:00:00 2001
From: bofh <123368+bofh@users.noreply.github.com>
Date: Mon, 31 Jul 2023 00:02:50 +0200
Subject: [PATCH 9/9] Set frequency in stm32 SPI examples
---
examples/stm32f3/src/bin/spi_dma.rs | 6 +++++-
examples/stm32f4/src/bin/spi.rs | 6 +++++-
examples/stm32f4/src/bin/spi_dma.rs | 6 +++++-
examples/stm32l0/src/bin/spi.rs | 6 +++++-
examples/stm32l1/src/bin/spi.rs | 6 +++++-
examples/stm32l4/src/bin/spi.rs | 6 +++++-
examples/stm32l4/src/bin/spi_blocking_async.rs | 6 +++++-
examples/stm32l4/src/bin/spi_dma.rs | 14 +++++---------
tests/stm32/src/bin/spi.rs | 11 ++++++-----
tests/stm32/src/bin/spi_dma.rs | 11 ++++++-----
10 files changed, 52 insertions(+), 26 deletions(-)
diff --git a/examples/stm32f3/src/bin/spi_dma.rs b/examples/stm32f3/src/bin/spi_dma.rs
index 6a39097d..a27c1d54 100644
--- a/examples/stm32f3/src/bin/spi_dma.rs
+++ b/examples/stm32f3/src/bin/spi_dma.rs
@@ -8,6 +8,7 @@ use core::str::from_utf8;
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::spi::{Config, Spi};
+use embassy_stm32::time::Hertz;
use heapless::String;
use {defmt_rtt as _, panic_probe as _};
@@ -16,7 +17,10 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
- let mut spi = Spi::new(p.SPI1, p.PB3, p.PB5, p.PB4, p.DMA1_CH3, p.DMA1_CH2, Config::default());
+ let mut spi_config = Config::default();
+ spi_config.frequency = Hertz(1_000_000);
+
+ let mut spi = Spi::new(p.SPI1, p.PB3, p.PB5, p.PB4, p.DMA1_CH3, p.DMA1_CH2, spi_config);
for n in 0u32.. {
let mut write: String<128> = String::new();
diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs
index b0c62b3f..0919e987 100644
--- a/examples/stm32f4/src/bin/spi.rs
+++ b/examples/stm32f4/src/bin/spi.rs
@@ -7,6 +7,7 @@ use defmt::*;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
+use embassy_stm32::time::Hertz;
use {defmt_rtt as _, panic_probe as _};
#[entry]
@@ -15,7 +16,10 @@ fn main() -> ! {
let p = embassy_stm32::init(Default::default());
- let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, Config::default());
+ let mut spi_config = Config::default();
+ spi_config.frequency = Hertz(1_000_000);
+
+ let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, spi_config);
let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh);
diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs
index 4edea93a..f291f7db 100644
--- a/examples/stm32f4/src/bin/spi_dma.rs
+++ b/examples/stm32f4/src/bin/spi_dma.rs
@@ -8,6 +8,7 @@ use core::str::from_utf8;
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::spi::{Config, Spi};
+use embassy_stm32::time::Hertz;
use heapless::String;
use {defmt_rtt as _, panic_probe as _};
@@ -16,7 +17,10 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
- let mut spi = Spi::new(p.SPI1, p.PB3, p.PB5, p.PB4, p.DMA2_CH3, p.DMA2_CH2, Config::default());
+ let mut spi_config = Config::default();
+ spi_config.frequency = Hertz(1_000_000);
+
+ let mut spi = Spi::new(p.SPI1, p.PB3, p.PB5, p.PB4, p.DMA2_CH3, p.DMA2_CH2, spi_config);
for n in 0u32.. {
let mut write: String<128> = String::new();
diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs
index 24ea9a68..583e3d12 100644
--- a/examples/stm32l0/src/bin/spi.rs
+++ b/examples/stm32l0/src/bin/spi.rs
@@ -7,6 +7,7 @@ use embassy_executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
+use embassy_stm32::time::Hertz;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@@ -14,7 +15,10 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World, folks!");
- let mut spi = Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, NoDma, NoDma, Config::default());
+ let mut spi_config = Config::default();
+ spi_config.frequency = Hertz(1_000_000);
+
+ let mut spi = Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, NoDma, NoDma, spi_config);
let mut cs = Output::new(p.PA15, Level::High, Speed::VeryHigh);
diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs
index 53523140..905b4d75 100644
--- a/examples/stm32l1/src/bin/spi.rs
+++ b/examples/stm32l1/src/bin/spi.rs
@@ -7,6 +7,7 @@ use embassy_executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
+use embassy_stm32::time::Hertz;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@@ -14,7 +15,10 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World, folks!");
- let mut spi = Spi::new(p.SPI1, p.PA5, p.PA7, p.PA6, NoDma, NoDma, Config::default());
+ let mut spi_config = Config::default();
+ spi_config.frequency = Hertz(1_000_000);
+
+ let mut spi = Spi::new(p.SPI1, p.PA5, p.PA7, p.PA6, NoDma, NoDma, spi_config);
let mut cs = Output::new(p.PA4, Level::High, Speed::VeryHigh);
diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs
index a3097fb4..54cf68f7 100644
--- a/examples/stm32l4/src/bin/spi.rs
+++ b/examples/stm32l4/src/bin/spi.rs
@@ -6,6 +6,7 @@ use defmt::*;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
+use embassy_stm32::time::Hertz;
use {defmt_rtt as _, panic_probe as _};
#[cortex_m_rt::entry]
@@ -14,7 +15,10 @@ fn main() -> ! {
let p = embassy_stm32::init(Default::default());
- let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, Config::default());
+ let mut spi_config = Config::default();
+ spi_config.frequency = Hertz(1_000_000);
+
+ let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, spi_config);
let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh);
diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs
index 45af8a9f..f1b80087 100644
--- a/examples/stm32l4/src/bin/spi_blocking_async.rs
+++ b/examples/stm32l4/src/bin/spi_blocking_async.rs
@@ -8,6 +8,7 @@ use embassy_executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::spi::{Config, Spi};
+use embassy_stm32::time::Hertz;
use embedded_hal_async::spi::SpiBus;
use {defmt_rtt as _, panic_probe as _};
@@ -16,7 +17,10 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
- let spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, Config::default());
+ let mut spi_config = Config::default();
+ spi_config.frequency = Hertz(1_000_000);
+
+ let spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, spi_config);
let mut spi = BlockingAsync::new(spi);
diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs
index 01265c49..ff9b5b43 100644
--- a/examples/stm32l4/src/bin/spi_dma.rs
+++ b/examples/stm32l4/src/bin/spi_dma.rs
@@ -6,6 +6,7 @@ use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::spi::{Config, Spi};
+use embassy_stm32::time::Hertz;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@@ -13,15 +14,10 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
- let mut spi = Spi::new(
- p.SPI3,
- p.PC10,
- p.PC12,
- p.PC11,
- p.DMA1_CH1,
- p.DMA1_CH2,
- Config::default(),
- );
+ let mut spi_config = Config::default();
+ spi_config.frequency = Hertz(1_000_000);
+
+ let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, p.DMA1_CH1, p.DMA1_CH2, spi_config);
// These are the pins for the Inventek eS-Wifi SPI Wifi Adapter.
diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs
index 7c2425fc..e51dd5bf 100644
--- a/tests/stm32/src/bin/spi.rs
+++ b/tests/stm32/src/bin/spi.rs
@@ -9,6 +9,7 @@ use defmt::assert_eq;
use embassy_executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::spi::{self, Spi};
+use embassy_stm32::time::Hertz;
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
@@ -34,14 +35,14 @@ async fn main(_spawner: Spawner) {
#[cfg(feature = "stm32c031c6")]
let (spi, sck, mosi, miso) = (p.SPI1, p.PA5, p.PA7, p.PA6);
+ let mut spi_config = spi::Config::default();
+ spi_config.frequency = Hertz(1_000_000);
+
let mut spi = Spi::new(
- spi,
- sck, // Arduino D13
+ spi, sck, // Arduino D13
mosi, // Arduino D11
miso, // Arduino D12
- NoDma,
- NoDma,
- spi::Config::default(),
+ NoDma, NoDma, spi_config,
);
let data: [u8; 9] = [0x00, 0xFF, 0xAA, 0x55, 0xC0, 0xFF, 0xEE, 0xC0, 0xDE];
diff --git a/tests/stm32/src/bin/spi_dma.rs b/tests/stm32/src/bin/spi_dma.rs
index e70c09f7..d45cbe45 100644
--- a/tests/stm32/src/bin/spi_dma.rs
+++ b/tests/stm32/src/bin/spi_dma.rs
@@ -8,6 +8,7 @@ use common::*;
use defmt::assert_eq;
use embassy_executor::Spawner;
use embassy_stm32::spi::{self, Spi};
+use embassy_stm32::time::Hertz;
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
@@ -33,14 +34,14 @@ async fn main(_spawner: Spawner) {
#[cfg(feature = "stm32c031c6")]
let (spi, sck, mosi, miso, tx_dma, rx_dma) = (p.SPI1, p.PA5, p.PA7, p.PA6, p.DMA1_CH1, p.DMA1_CH2);
+ let mut spi_config = spi::Config::default();
+ spi_config.frequency = Hertz(1_000_000);
+
let mut spi = Spi::new(
- spi,
- sck, // Arduino D13
+ spi, sck, // Arduino D13
mosi, // Arduino D11
miso, // Arduino D12
- tx_dma,
- rx_dma,
- spi::Config::default(),
+ tx_dma, rx_dma, spi_config,
);
let data: [u8; 9] = [0x00, 0xFF, 0xAA, 0x55, 0xC0, 0xFF, 0xEE, 0xC0, 0xDE];