diff options
| author | HybridChild <[email protected]> | 2025-11-13 14:36:31 +0100 |
|---|---|---|
| committer | HybridChild <[email protected]> | 2025-11-13 14:40:16 +0100 |
| commit | 2553ced205d49d2890e000069f5a170b75d267a9 (patch) | |
| tree | 14c0ecadef3d6b2bf5176f5f4eb1ead3bf79d6fc | |
| parent | 00ca12b20f330101cd47ce3947aa186be8f72dd5 (diff) | |
stm32: Move i2c_master test to examples
| -rw-r--r-- | examples/stm32f0/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/stm32f0/src/bin/i2c_master.rs (renamed from tests/stm32/src/bin/i2c_v2_master.rs) | 29 | ||||
| -rw-r--r-- | tests/stm32/Cargo.toml | 7 | ||||
| -rw-r--r-- | tests/stm32/build.rs | 1 | ||||
| -rw-r--r-- | tests/stm32/src/common.rs | 25 |
5 files changed, 16 insertions, 47 deletions
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml index a78873d21..177dd0ac2 100644 --- a/examples/stm32f0/Cargo.toml +++ b/examples/stm32f0/Cargo.toml | |||
| @@ -16,6 +16,7 @@ panic-probe = { version = "1.0.0", features = ["print-defmt"] } | |||
| 16 | embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } | 16 | embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } |
| 17 | embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } | 17 | embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } |
| 18 | embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 18 | embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 19 | embedded-hal-1 = { package = "embedded-hal", version = "1.0" } | ||
| 19 | static_cell = "2" | 20 | static_cell = "2" |
| 20 | portable-atomic = { version = "1.5", features = ["unsafe-assume-single-core"] } | 21 | portable-atomic = { version = "1.5", features = ["unsafe-assume-single-core"] } |
| 21 | 22 | ||
diff --git a/tests/stm32/src/bin/i2c_v2_master.rs b/examples/stm32f0/src/bin/i2c_master.rs index 34f9b48d3..2e61ecdf7 100644 --- a/tests/stm32/src/bin/i2c_v2_master.rs +++ b/examples/stm32f0/src/bin/i2c_master.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | // required-features: stm32f072rb | 3 | |
| 4 | // | ||
| 5 | // Hardware Setup for NUCLEO-F072RB: | 4 | // Hardware Setup for NUCLEO-F072RB: |
| 6 | // - I2C1 pins: PB8 (SCL), PB9 (SDA) on CN5 connector | 5 | // - I2C1 pins: PB8 (SCL), PB9 (SDA) on CN5 connector |
| 7 | // - Connect to I2C slave device (e.g., Digilent Analog Discovery I2C slave, or EEPROM) | 6 | // - Connect to I2C slave device (e.g., Digilent Analog Discovery I2C slave, or EEPROM) |
| @@ -16,25 +15,28 @@ | |||
| 16 | // - Connect and configure DIO pins for SCL and SDA | 15 | // - Connect and configure DIO pins for SCL and SDA |
| 17 | // - Frequency: 100kHz - [✓] Clock Stretching | 16 | // - Frequency: 100kHz - [✓] Clock Stretching |
| 18 | 17 | ||
| 19 | #[path = "../common.rs"] | 18 | use defmt::*; |
| 20 | mod common; | ||
| 21 | |||
| 22 | use common::*; | ||
| 23 | use embassy_executor::Spawner; | 19 | use embassy_executor::Spawner; |
| 24 | use embassy_stm32::i2c::{Config, I2c, Master}; | 20 | use embassy_stm32::i2c::{Config, I2c, Master}; |
| 25 | use embassy_stm32::mode::{Async, Blocking}; | 21 | use embassy_stm32::mode::{Async, Blocking}; |
| 26 | use embassy_stm32::time::Hertz; | 22 | use embassy_stm32::time::Hertz; |
| 23 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; | ||
| 27 | use embassy_time::Timer; | 24 | use embassy_time::Timer; |
| 28 | use embedded_hal_1::i2c::Operation; | 25 | use embedded_hal_1::i2c::Operation; |
| 26 | use {defmt_rtt as _, panic_probe as _}; | ||
| 27 | |||
| 28 | bind_interrupts!(struct Irqs { | ||
| 29 | I2C1 => i2c::EventInterruptHandler<peripherals::I2C1>, i2c::ErrorInterruptHandler<peripherals::I2C1>; | ||
| 30 | }); | ||
| 29 | 31 | ||
| 30 | #[embassy_executor::main] | 32 | #[embassy_executor::main] |
| 31 | async fn main(_spawner: Spawner) { | 33 | async fn main(_spawner: Spawner) { |
| 32 | let p = init(); | 34 | let p = embassy_stm32::init(Default::default()); |
| 33 | info!("Run stm32 I2C v2 Master Tests..."); | 35 | info!("Run stm32 I2C v2 Master Tests..."); |
| 34 | 36 | ||
| 35 | let mut i2c_peri = peri!(p, I2C); | 37 | let mut i2c_peri = p.I2C1; |
| 36 | let mut scl = peri!(p, I2C_SCL); | 38 | let mut scl = p.PB8; |
| 37 | let mut sda = peri!(p, I2C_SDA); | 39 | let mut sda = p.PB9; |
| 38 | 40 | ||
| 39 | let mut config = Config::default(); | 41 | let mut config = Config::default(); |
| 40 | config.frequency = Hertz(100_000); | 42 | config.frequency = Hertz(100_000); |
| @@ -101,11 +103,10 @@ async fn main(_spawner: Spawner) { | |||
| 101 | // ========== ASYNC TESTS (DMA) ========== | 103 | // ========== ASYNC TESTS (DMA) ========== |
| 102 | info!("========== ASYNC TESTS (DMA) =========="); | 104 | info!("========== ASYNC TESTS (DMA) =========="); |
| 103 | { | 105 | { |
| 104 | let tx_dma = peri!(p, I2C_TX_DMA); | 106 | let tx_dma = p.DMA1_CH2; |
| 105 | let rx_dma = peri!(p, I2C_RX_DMA); | 107 | let rx_dma = p.DMA1_CH3; |
| 106 | let irq = irqs!(I2C); | ||
| 107 | 108 | ||
| 108 | let mut i2c = I2c::new(i2c_peri, scl, sda, irq, tx_dma, rx_dma, config); | 109 | let mut i2c = I2c::new(i2c_peri, scl, sda, Irqs, tx_dma, rx_dma, config); |
| 109 | 110 | ||
| 110 | // Direct API tests (reusing same I2C instance) | 111 | // Direct API tests (reusing same I2C instance) |
| 111 | info!("=== Direct API Test 1: write() ==="); | 112 | info!("=== Direct API Test 1: write() ==="); |
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index 1912a772c..b92b47be2 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml | |||
| @@ -35,7 +35,6 @@ stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" | |||
| 35 | stm32wba52cg = ["embassy-stm32/stm32wba52cg", "spi-v345", "chrono", "rng", "hash"] | 35 | stm32wba52cg = ["embassy-stm32/stm32wba52cg", "spi-v345", "chrono", "rng", "hash"] |
| 36 | stm32wl55jc = ["embassy-stm32/stm32wl55jc-cm4", "not-gpdma", "rng", "chrono"] | 36 | stm32wl55jc = ["embassy-stm32/stm32wl55jc-cm4", "not-gpdma", "rng", "chrono"] |
| 37 | stm32f091rc = ["embassy-stm32/stm32f091rc", "cm0", "not-gpdma", "chrono"] | 37 | stm32f091rc = ["embassy-stm32/stm32f091rc", "cm0", "not-gpdma", "chrono"] |
| 38 | stm32f072rb = ["embassy-stm32/stm32f072rb", "cm0", "not-gpdma", "chrono"] | ||
| 39 | stm32h503rb = ["embassy-stm32/stm32h503rb", "spi-v345", "rng", "stop"] | 38 | stm32h503rb = ["embassy-stm32/stm32h503rb", "spi-v345", "rng", "stop"] |
| 40 | stm32h7s3l8 = ["embassy-stm32/stm32h7s3l8", "spi-v345", "rng", "cordic", "hash-v34"] # TODO: fdcan crashes, cryp dma hangs. | 39 | stm32h7s3l8 = ["embassy-stm32/stm32h7s3l8", "spi-v345", "rng", "cordic", "hash-v34"] # TODO: fdcan crashes, cryp dma hangs. |
| 41 | stm32u083rc = ["embassy-stm32/stm32u083rc", "cm0", "rng", "chrono"] | 40 | stm32u083rc = ["embassy-stm32/stm32u083rc", "cm0", "rng", "chrono"] |
| @@ -161,11 +160,6 @@ path = "src/bin/hash.rs" | |||
| 161 | required-features = [ "hash",] | 160 | required-features = [ "hash",] |
| 162 | 161 | ||
| 163 | [[bin]] | 162 | [[bin]] |
| 164 | name = "i2c_v2_master" | ||
| 165 | path = "src/bin/i2c_v2_master.rs" | ||
| 166 | required-features = [ "stm32f072rb",] | ||
| 167 | |||
| 168 | [[bin]] | ||
| 169 | name = "rng" | 163 | name = "rng" |
| 170 | path = "src/bin/rng.rs" | 164 | path = "src/bin/rng.rs" |
| 171 | required-features = [ "rng",] | 165 | required-features = [ "rng",] |
| @@ -291,7 +285,6 @@ build = [ | |||
| 291 | { target = "thumbv7em-none-eabi", features = ["stm32wl55jc"], artifact-dir = "out/tests/stm32wl55jc" }, | 285 | { target = "thumbv7em-none-eabi", features = ["stm32wl55jc"], artifact-dir = "out/tests/stm32wl55jc" }, |
| 292 | { target = "thumbv7em-none-eabi", features = ["stm32h7s3l8"], artifact-dir = "out/tests/stm32h7s3l8" }, | 286 | { target = "thumbv7em-none-eabi", features = ["stm32h7s3l8"], artifact-dir = "out/tests/stm32h7s3l8" }, |
| 293 | { target = "thumbv6m-none-eabi", features = ["stm32f091rc"], artifact-dir = "out/tests/stm32f091rc" }, | 287 | { target = "thumbv6m-none-eabi", features = ["stm32f091rc"], artifact-dir = "out/tests/stm32f091rc" }, |
| 294 | { target = "thumbv6m-none-eabi", features = ["stm32f072rb"], artifact-dir = "out/tests/stm32f072rb" }, | ||
| 295 | { target = "thumbv8m.main-none-eabihf", features = ["stm32h503rb"], artifact-dir = "out/tests/stm32h503rb" }, | 288 | { target = "thumbv8m.main-none-eabihf", features = ["stm32h503rb"], artifact-dir = "out/tests/stm32h503rb" }, |
| 296 | { target = "thumbv6m-none-eabi", features = ["stm32u083rc"], artifact-dir = "out/tests/stm32u083rc" } | 289 | { target = "thumbv6m-none-eabi", features = ["stm32u083rc"], artifact-dir = "out/tests/stm32u083rc" } |
| 297 | ] | 290 | ] |
diff --git a/tests/stm32/build.rs b/tests/stm32/build.rs index 34030c206..556d77a20 100644 --- a/tests/stm32/build.rs +++ b/tests/stm32/build.rs | |||
| @@ -15,7 +15,6 @@ fn main() -> Result<(), Box<dyn Error>> { | |||
| 15 | feature = "stm32c071rb", // 24 kb | 15 | feature = "stm32c071rb", // 24 kb |
| 16 | feature = "stm32l073rz", // 20 kb | 16 | feature = "stm32l073rz", // 20 kb |
| 17 | feature = "stm32h503rb", // 32 kb | 17 | feature = "stm32h503rb", // 32 kb |
| 18 | feature = "stm32f072rb", // 16 kb - I2C v2 test with async too large for RAM | ||
| 19 | // no VTOR, so interrupts can't work when running from RAM | 18 | // no VTOR, so interrupts can't work when running from RAM |
| 20 | feature = "stm32f091rc", | 19 | feature = "stm32f091rc", |
| 21 | )) { | 20 | )) { |
diff --git a/tests/stm32/src/common.rs b/tests/stm32/src/common.rs index de06cb267..096cce947 100644 --- a/tests/stm32/src/common.rs +++ b/tests/stm32/src/common.rs | |||
| @@ -60,8 +60,6 @@ teleprobe_meta::target!(b"nucleo-stm32wl55jc"); | |||
| 60 | teleprobe_meta::target!(b"nucleo-stm32wba52cg"); | 60 | teleprobe_meta::target!(b"nucleo-stm32wba52cg"); |
| 61 | #[cfg(feature = "stm32f091rc")] | 61 | #[cfg(feature = "stm32f091rc")] |
| 62 | teleprobe_meta::target!(b"nucleo-stm32f091rc"); | 62 | teleprobe_meta::target!(b"nucleo-stm32f091rc"); |
| 63 | #[cfg(feature = "stm32f072rb")] | ||
| 64 | teleprobe_meta::target!(b"nucleo-stm32f072rb"); | ||
| 65 | #[cfg(feature = "stm32h503rb")] | 63 | #[cfg(feature = "stm32h503rb")] |
| 66 | teleprobe_meta::target!(b"nucleo-stm32h503rb"); | 64 | teleprobe_meta::target!(b"nucleo-stm32h503rb"); |
| 67 | #[cfg(feature = "stm32h7s3l8")] | 65 | #[cfg(feature = "stm32h7s3l8")] |
| @@ -105,14 +103,6 @@ define_peris!( | |||
| 105 | SPI = SPI1, SPI_SCK = PA5, SPI_MOSI = PA7, SPI_MISO = PA6, SPI_TX_DMA = DMA1_CH3, SPI_RX_DMA = DMA1_CH2, | 103 | SPI = SPI1, SPI_SCK = PA5, SPI_MOSI = PA7, SPI_MISO = PA6, SPI_TX_DMA = DMA1_CH3, SPI_RX_DMA = DMA1_CH2, |
| 106 | @irq UART = {USART1 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::USART1>;}, | 104 | @irq UART = {USART1 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::USART1>;}, |
| 107 | ); | 105 | ); |
| 108 | #[cfg(feature = "stm32f072rb")] | ||
| 109 | define_peris!( | ||
| 110 | UART = USART1, UART_TX = PA9, UART_RX = PA10, UART_TX_DMA = DMA1_CH4, UART_RX_DMA = DMA1_CH5, | ||
| 111 | SPI = SPI1, SPI_SCK = PA5, SPI_MOSI = PA7, SPI_MISO = PA6, SPI_TX_DMA = DMA1_CH3, SPI_RX_DMA = DMA1_CH2, | ||
| 112 | I2C = I2C1, I2C_SCL = PB8, I2C_SDA = PB9, I2C_TX_DMA = DMA1_CH6, I2C_RX_DMA = DMA1_CH7, | ||
| 113 | @irq UART = {USART1 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::USART1>;}, | ||
| 114 | @irq I2C = {I2C1 => embassy_stm32::i2c::EventInterruptHandler<embassy_stm32::peripherals::I2C1>, embassy_stm32::i2c::ErrorInterruptHandler<embassy_stm32::peripherals::I2C1>;}, | ||
| 115 | ); | ||
| 116 | #[cfg(any(feature = "stm32f100rd", feature = "stm32f103c8", feature = "stm32f107vc"))] | 106 | #[cfg(any(feature = "stm32f100rd", feature = "stm32f103c8", feature = "stm32f107vc"))] |
| 117 | define_peris!( | 107 | define_peris!( |
| 118 | UART = USART1, UART_TX = PA9, UART_RX = PA10, UART_TX_DMA = DMA1_CH4, UART_RX_DMA = DMA1_CH5, | 108 | UART = USART1, UART_TX = PA9, UART_RX = PA10, UART_TX_DMA = DMA1_CH4, UART_RX_DMA = DMA1_CH5, |
| @@ -335,21 +325,6 @@ pub fn config() -> Config { | |||
| 335 | config.rcc.ahb_pre = AHBPrescaler::DIV1; | 325 | config.rcc.ahb_pre = AHBPrescaler::DIV1; |
| 336 | config.rcc.apb1_pre = APBPrescaler::DIV1; | 326 | config.rcc.apb1_pre = APBPrescaler::DIV1; |
| 337 | } | 327 | } |
| 338 | #[cfg(feature = "stm32f072rb")] | ||
| 339 | { | ||
| 340 | config.rcc.hse = Some(Hse { | ||
| 341 | freq: Hertz(8_000_000), | ||
| 342 | mode: HseMode::Bypass, | ||
| 343 | }); | ||
| 344 | config.rcc.pll = Some(Pll { | ||
| 345 | src: PllSource::HSE, | ||
| 346 | prediv: PllPreDiv::DIV1, | ||
| 347 | mul: PllMul::MUL6, | ||
| 348 | }); | ||
| 349 | config.rcc.sys = Sysclk::PLL1_P; | ||
| 350 | config.rcc.ahb_pre = AHBPrescaler::DIV1; | ||
| 351 | config.rcc.apb1_pre = APBPrescaler::DIV1; | ||
| 352 | } | ||
| 353 | #[cfg(feature = "stm32f103c8")] | 328 | #[cfg(feature = "stm32f103c8")] |
| 354 | { | 329 | { |
| 355 | config.rcc.hse = Some(Hse { | 330 | config.rcc.hse = Some(Hse { |
