diff options
| author | Raul Alimbekov <[email protected]> | 2025-12-16 09:05:22 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-16 09:05:22 +0300 |
| commit | c9a04b4b732b7a3b696eb8223664c1a7942b1875 (patch) | |
| tree | 6dbe5c02e66eed8d8762f13f95afd24f8db2b38c /examples/stm32f7 | |
| parent | cde24a3ef1117653ba5ed4184102b33f745782fb (diff) | |
| parent | 5ae6e060ec1c90561719aabdc29d5b6e7b8b0a82 (diff) | |
Merge branch 'main' into main
Diffstat (limited to 'examples/stm32f7')
| -rw-r--r-- | examples/stm32f7/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/adc.rs | 6 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/button_exti.rs | 10 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/can.rs | 2 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/cryp.rs | 4 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/eth.rs | 14 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/hash.rs | 2 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/pwm.rs | 61 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/pwm_ringbuffer.rs | 153 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/qspi.rs | 2 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/sdmmc.rs | 15 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/usb_serial.rs | 4 |
12 files changed, 250 insertions, 25 deletions
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index 5d7763334..565277394 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "embassy-stm32f7-examples" | 3 | name = "embassy-stm32f7-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
diff --git a/examples/stm32f7/src/bin/adc.rs b/examples/stm32f7/src/bin/adc.rs index 6689e3b5d..0f226d34e 100644 --- a/examples/stm32f7/src/bin/adc.rs +++ b/examples/stm32f7/src/bin/adc.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::adc::Adc; | 6 | use embassy_stm32::adc::{Adc, SampleTime}; |
| 7 | use embassy_time::Timer; | 7 | use embassy_time::Timer; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| @@ -16,7 +16,7 @@ async fn main(_spawner: Spawner) { | |||
| 16 | let mut pin = p.PA3; | 16 | let mut pin = p.PA3; |
| 17 | 17 | ||
| 18 | let mut vrefint = adc.enable_vrefint(); | 18 | let mut vrefint = adc.enable_vrefint(); |
| 19 | let vrefint_sample = adc.blocking_read(&mut vrefint); | 19 | let vrefint_sample = adc.blocking_read(&mut vrefint, SampleTime::CYCLES112); |
| 20 | let convert_to_millivolts = |sample| { | 20 | let convert_to_millivolts = |sample| { |
| 21 | // From http://www.st.com/resource/en/datasheet/DM00273119.pdf | 21 | // From http://www.st.com/resource/en/datasheet/DM00273119.pdf |
| 22 | // 6.3.27 Reference voltage | 22 | // 6.3.27 Reference voltage |
| @@ -26,7 +26,7 @@ async fn main(_spawner: Spawner) { | |||
| 26 | }; | 26 | }; |
| 27 | 27 | ||
| 28 | loop { | 28 | loop { |
| 29 | let v = adc.blocking_read(&mut pin); | 29 | let v = adc.blocking_read(&mut pin, SampleTime::CYCLES112); |
| 30 | info!("--> {} - {} mV", v, convert_to_millivolts(v)); | 30 | info!("--> {} - {} mV", v, convert_to_millivolts(v)); |
| 31 | Timer::after_millis(100).await; | 31 | Timer::after_millis(100).await; |
| 32 | } | 32 | } |
diff --git a/examples/stm32f7/src/bin/button_exti.rs b/examples/stm32f7/src/bin/button_exti.rs index 2a546dac5..e7e1549a8 100644 --- a/examples/stm32f7/src/bin/button_exti.rs +++ b/examples/stm32f7/src/bin/button_exti.rs | |||
| @@ -3,16 +3,22 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::{self, ExtiInput}; |
| 7 | use embassy_stm32::gpio::Pull; | 7 | use embassy_stm32::gpio::Pull; |
| 8 | use embassy_stm32::{bind_interrupts, interrupt}; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 10 | ||
| 11 | bind_interrupts!( | ||
| 12 | pub struct Irqs{ | ||
| 13 | EXTI15_10 => exti::InterruptHandler<interrupt::typelevel::EXTI15_10>; | ||
| 14 | }); | ||
| 15 | |||
| 10 | #[embassy_executor::main] | 16 | #[embassy_executor::main] |
| 11 | async fn main(_spawner: Spawner) { | 17 | async fn main(_spawner: Spawner) { |
| 12 | let p = embassy_stm32::init(Default::default()); | 18 | let p = embassy_stm32::init(Default::default()); |
| 13 | info!("Hello World!"); | 19 | info!("Hello World!"); |
| 14 | 20 | ||
| 15 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); | 21 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down, Irqs); |
| 16 | 22 | ||
| 17 | info!("Press the USER button..."); | 23 | info!("Press the USER button..."); |
| 18 | 24 | ||
diff --git a/examples/stm32f7/src/bin/can.rs b/examples/stm32f7/src/bin/can.rs index 9a91ac814..2f3f6db84 100644 --- a/examples/stm32f7/src/bin/can.rs +++ b/examples/stm32f7/src/bin/can.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::num::{NonZeroU16, NonZeroU8}; | 4 | use core::num::{NonZeroU8, NonZeroU16}; |
| 5 | 5 | ||
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
diff --git a/examples/stm32f7/src/bin/cryp.rs b/examples/stm32f7/src/bin/cryp.rs index a31e9b4f2..9ccef0b82 100644 --- a/examples/stm32f7/src/bin/cryp.rs +++ b/examples/stm32f7/src/bin/cryp.rs | |||
| @@ -1,13 +1,13 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use aes_gcm::Aes128Gcm; | ||
| 4 | use aes_gcm::aead::heapless::Vec; | 5 | use aes_gcm::aead::heapless::Vec; |
| 5 | use aes_gcm::aead::{AeadInPlace, KeyInit}; | 6 | use aes_gcm::aead::{AeadInPlace, KeyInit}; |
| 6 | use aes_gcm::Aes128Gcm; | ||
| 7 | use defmt::info; | 7 | use defmt::info; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::cryp::{self, *}; | 9 | use embassy_stm32::cryp::{self, *}; |
| 10 | use embassy_stm32::{bind_interrupts, peripherals, Config}; | 10 | use embassy_stm32::{Config, bind_interrupts, peripherals}; |
| 11 | use embassy_time::Instant; | 11 | use embassy_time::Instant; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index b13b7bdda..8613376b8 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs | |||
| @@ -5,11 +5,11 @@ use defmt::*; | |||
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_net::tcp::TcpSocket; | 6 | use embassy_net::tcp::TcpSocket; |
| 7 | use embassy_net::{Ipv4Address, StackResources}; | 7 | use embassy_net::{Ipv4Address, StackResources}; |
| 8 | use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; | 8 | use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue, Sma}; |
| 9 | use embassy_stm32::peripherals::ETH; | 9 | use embassy_stm32::peripherals::{ETH, ETH_SMA}; |
| 10 | use embassy_stm32::rng::Rng; | 10 | use embassy_stm32::rng::Rng; |
| 11 | use embassy_stm32::time::Hertz; | 11 | use embassy_stm32::time::Hertz; |
| 12 | use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; | 12 | use embassy_stm32::{Config, bind_interrupts, eth, peripherals, rng}; |
| 13 | use embassy_time::Timer; | 13 | use embassy_time::Timer; |
| 14 | use embedded_io_async::Write; | 14 | use embedded_io_async::Write; |
| 15 | use static_cell::StaticCell; | 15 | use static_cell::StaticCell; |
| @@ -20,7 +20,7 @@ bind_interrupts!(struct Irqs { | |||
| 20 | HASH_RNG => rng::InterruptHandler<peripherals::RNG>; | 20 | HASH_RNG => rng::InterruptHandler<peripherals::RNG>; |
| 21 | }); | 21 | }); |
| 22 | 22 | ||
| 23 | type Device = Ethernet<'static, ETH, GenericPhy>; | 23 | type Device = Ethernet<'static, ETH, GenericPhy<Sma<'static, ETH_SMA>>>; |
| 24 | 24 | ||
| 25 | #[embassy_executor::task] | 25 | #[embassy_executor::task] |
| 26 | async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { | 26 | async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { |
| @@ -67,16 +67,16 @@ async fn main(spawner: Spawner) -> ! { | |||
| 67 | p.ETH, | 67 | p.ETH, |
| 68 | Irqs, | 68 | Irqs, |
| 69 | p.PA1, | 69 | p.PA1, |
| 70 | p.PA2, | ||
| 71 | p.PC1, | ||
| 72 | p.PA7, | 70 | p.PA7, |
| 73 | p.PC4, | 71 | p.PC4, |
| 74 | p.PC5, | 72 | p.PC5, |
| 75 | p.PG13, | 73 | p.PG13, |
| 76 | p.PB13, | 74 | p.PB13, |
| 77 | p.PG11, | 75 | p.PG11, |
| 78 | GenericPhy::new_auto(), | ||
| 79 | mac_addr, | 76 | mac_addr, |
| 77 | p.ETH_SMA, | ||
| 78 | p.PA2, | ||
| 79 | p.PC1, | ||
| 80 | ); | 80 | ); |
| 81 | 81 | ||
| 82 | let config = embassy_net::Config::dhcpv4(Default::default()); | 82 | let config = embassy_net::Config::dhcpv4(Default::default()); |
diff --git a/examples/stm32f7/src/bin/hash.rs b/examples/stm32f7/src/bin/hash.rs index c2d1a7158..4fd465df6 100644 --- a/examples/stm32f7/src/bin/hash.rs +++ b/examples/stm32f7/src/bin/hash.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::info; | 4 | use defmt::info; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::hash::*; | 6 | use embassy_stm32::hash::*; |
| 7 | use embassy_stm32::{bind_interrupts, hash, peripherals, Config}; | 7 | use embassy_stm32::{Config, bind_interrupts, hash, peripherals}; |
| 8 | use embassy_time::Instant; | 8 | use embassy_time::Instant; |
| 9 | use hmac::{Hmac, Mac}; | 9 | use hmac::{Hmac, Mac}; |
| 10 | use sha2::{Digest, Sha256}; | 10 | use sha2::{Digest, Sha256}; |
diff --git a/examples/stm32f7/src/bin/pwm.rs b/examples/stm32f7/src/bin/pwm.rs new file mode 100644 index 000000000..b071eb597 --- /dev/null +++ b/examples/stm32f7/src/bin/pwm.rs | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_stm32::Config; | ||
| 7 | use embassy_stm32::gpio::OutputType; | ||
| 8 | use embassy_stm32::time::{Hertz, mhz}; | ||
| 9 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | ||
| 10 | use embassy_time::Timer; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | // If you are trying this and your USB device doesn't connect, the most | ||
| 14 | // common issues are the RCC config and vbus_detection | ||
| 15 | // | ||
| 16 | // See https://embassy.dev/book/#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure | ||
| 17 | // for more information. | ||
| 18 | #[embassy_executor::main] | ||
| 19 | async fn main(_spawner: Spawner) { | ||
| 20 | info!("Hello World!"); | ||
| 21 | |||
| 22 | let mut config = Config::default(); | ||
| 23 | { | ||
| 24 | use embassy_stm32::rcc::*; | ||
| 25 | config.rcc.hse = Some(Hse { | ||
| 26 | freq: Hertz(8_000_000), | ||
| 27 | mode: HseMode::Bypass, | ||
| 28 | }); | ||
| 29 | config.rcc.pll_src = PllSource::HSE; | ||
| 30 | config.rcc.pll = Some(Pll { | ||
| 31 | prediv: PllPreDiv::DIV4, | ||
| 32 | mul: PllMul::MUL200, | ||
| 33 | divp: Some(PllPDiv::DIV2), // 8mhz / 4 * 200 / 2 = 200Mhz | ||
| 34 | divq: Some(PllQDiv::DIV4), // 8mhz / 4 * 200 / 4 = 100Mhz | ||
| 35 | divr: None, | ||
| 36 | }); | ||
| 37 | config.rcc.ahb_pre = AHBPrescaler::DIV1; | ||
| 38 | config.rcc.apb1_pre = APBPrescaler::DIV4; | ||
| 39 | config.rcc.apb2_pre = APBPrescaler::DIV2; | ||
| 40 | config.rcc.sys = Sysclk::PLL1_P; | ||
| 41 | } | ||
| 42 | let p = embassy_stm32::init(config); | ||
| 43 | let ch1_pin = PwmPin::new(p.PE9, OutputType::PushPull); | ||
| 44 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, mhz(1), Default::default()); | ||
| 45 | let mut ch1 = pwm.ch1(); | ||
| 46 | ch1.enable(); | ||
| 47 | |||
| 48 | info!("PWM initialized"); | ||
| 49 | info!("PWM max duty {}", ch1.max_duty_cycle()); | ||
| 50 | |||
| 51 | loop { | ||
| 52 | ch1.set_duty_cycle_fully_off(); | ||
| 53 | Timer::after_millis(300).await; | ||
| 54 | ch1.set_duty_cycle_fraction(1, 4); | ||
| 55 | Timer::after_millis(300).await; | ||
| 56 | ch1.set_duty_cycle_fraction(1, 2); | ||
| 57 | Timer::after_millis(300).await; | ||
| 58 | ch1.set_duty_cycle(ch1.max_duty_cycle() - 1); | ||
| 59 | Timer::after_millis(300).await; | ||
| 60 | } | ||
| 61 | } | ||
diff --git a/examples/stm32f7/src/bin/pwm_ringbuffer.rs b/examples/stm32f7/src/bin/pwm_ringbuffer.rs new file mode 100644 index 000000000..4d191ac13 --- /dev/null +++ b/examples/stm32f7/src/bin/pwm_ringbuffer.rs | |||
| @@ -0,0 +1,153 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_stm32::Config; | ||
| 7 | use embassy_stm32::gpio::OutputType; | ||
| 8 | use embassy_stm32::time::mhz; | ||
| 9 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | ||
| 10 | use embassy_time::Timer; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | // If you are trying this and your USB device doesn't connect, the most | ||
| 14 | // common issues are the RCC config and vbus_detection | ||
| 15 | // | ||
| 16 | // See https://embassy.dev/book/#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure | ||
| 17 | // for more information. | ||
| 18 | #[embassy_executor::main] | ||
| 19 | async fn main(_spawner: Spawner) { | ||
| 20 | info!("PWM Ring Buffer Example"); | ||
| 21 | |||
| 22 | let mut config = Config::default(); | ||
| 23 | { | ||
| 24 | use embassy_stm32::rcc::*; | ||
| 25 | use embassy_stm32::time::Hertz; | ||
| 26 | config.rcc.hse = Some(Hse { | ||
| 27 | freq: Hertz(8_000_000), | ||
| 28 | mode: HseMode::Bypass, | ||
| 29 | }); | ||
| 30 | config.rcc.pll_src = PllSource::HSE; | ||
| 31 | config.rcc.pll = Some(Pll { | ||
| 32 | prediv: PllPreDiv::DIV4, | ||
| 33 | mul: PllMul::MUL200, | ||
| 34 | divp: Some(PllPDiv::DIV2), // 8mhz / 4 * 200 / 2 = 200Mhz | ||
| 35 | divq: Some(PllQDiv::DIV4), // 8mhz / 4 * 200 / 4 = 100Mhz | ||
| 36 | divr: None, | ||
| 37 | }); | ||
| 38 | config.rcc.ahb_pre = AHBPrescaler::DIV1; | ||
| 39 | config.rcc.apb1_pre = APBPrescaler::DIV4; | ||
| 40 | config.rcc.apb2_pre = APBPrescaler::DIV2; | ||
| 41 | config.rcc.sys = Sysclk::PLL1_P; | ||
| 42 | } | ||
| 43 | let p = embassy_stm32::init(config); | ||
| 44 | |||
| 45 | // Initialize PWM on TIM1 | ||
| 46 | let ch1_pin = PwmPin::new(p.PE9, OutputType::PushPull); | ||
| 47 | let ch2_pin = PwmPin::new(p.PE11, OutputType::PushPull); | ||
| 48 | let mut pwm = SimplePwm::new( | ||
| 49 | p.TIM1, | ||
| 50 | Some(ch1_pin), | ||
| 51 | Some(ch2_pin), | ||
| 52 | None, | ||
| 53 | None, | ||
| 54 | mhz(1), | ||
| 55 | Default::default(), | ||
| 56 | ); | ||
| 57 | |||
| 58 | // Use channel 1 for static PWM at 50% | ||
| 59 | let mut ch1 = pwm.ch1(); | ||
| 60 | ch1.enable(); | ||
| 61 | ch1.set_duty_cycle_fraction(1, 2); | ||
| 62 | info!("Channel 1 (PE9/D6): Static 50% duty cycle"); | ||
| 63 | |||
| 64 | // Get max duty from channel 1 before converting channel 2 | ||
| 65 | let max_duty = ch1.max_duty_cycle(); | ||
| 66 | info!("PWM max duty: {}", max_duty); | ||
| 67 | |||
| 68 | // Create a DMA ring buffer for channel 2 | ||
| 69 | const BUFFER_SIZE: usize = 128; | ||
| 70 | static mut DMA_BUFFER: [u16; BUFFER_SIZE] = [0u16; BUFFER_SIZE]; | ||
| 71 | let dma_buffer = unsafe { &mut *core::ptr::addr_of_mut!(DMA_BUFFER) }; | ||
| 72 | |||
| 73 | // Pre-fill buffer with initial sine wave using lookup table approach | ||
| 74 | for i in 0..BUFFER_SIZE { | ||
| 75 | // Simple sine approximation using triangle wave | ||
| 76 | let phase = (i * 256) / BUFFER_SIZE; | ||
| 77 | let sine_approx = if phase < 128 { | ||
| 78 | phase as u16 * 2 | ||
| 79 | } else { | ||
| 80 | (255 - phase) as u16 * 2 | ||
| 81 | }; | ||
| 82 | dma_buffer[i] = (sine_approx as u32 * max_duty as u32 / 256) as u16; | ||
| 83 | } | ||
| 84 | |||
| 85 | // Convert channel 2 to ring-buffered PWM | ||
| 86 | let mut ring_pwm = pwm.ch1().into_ring_buffered_channel(p.DMA2_CH5, dma_buffer); | ||
| 87 | |||
| 88 | info!("Ring buffer capacity: {}", ring_pwm.capacity()); | ||
| 89 | |||
| 90 | // Pre-write some initial data to the buffer before starting | ||
| 91 | info!("Pre-writing initial waveform data..."); | ||
| 92 | |||
| 93 | ring_pwm.write(&[0; BUFFER_SIZE]).unwrap(); | ||
| 94 | |||
| 95 | // Enable the PWM channel output | ||
| 96 | ring_pwm.enable(); | ||
| 97 | |||
| 98 | // Start the DMA ring buffer | ||
| 99 | ring_pwm.start(); | ||
| 100 | info!("Channel 2 (PE11/D5): Ring buffered sine wave started"); | ||
| 101 | |||
| 102 | // Give DMA time to start consuming | ||
| 103 | Timer::after_millis(10).await; | ||
| 104 | |||
| 105 | // Continuously update the waveform | ||
| 106 | let mut phase: f32 = 0.0; | ||
| 107 | let mut amplitude: f32 = 1.0; | ||
| 108 | let mut amplitude_direction = -0.05; | ||
| 109 | |||
| 110 | loop { | ||
| 111 | // Generate new waveform data with varying amplitude | ||
| 112 | let mut new_data = [0u16; 32]; | ||
| 113 | for i in 0..new_data.len() { | ||
| 114 | // Triangle wave approximation for sine | ||
| 115 | let pos = ((i as u32 + phase as u32) * 4) % 256; | ||
| 116 | let sine_approx = if pos < 128 { | ||
| 117 | pos as u16 * 2 | ||
| 118 | } else { | ||
| 119 | (255 - pos) as u16 * 2 | ||
| 120 | }; | ||
| 121 | let scaled = (sine_approx as u32 * (amplitude * 256.0) as u32) / (256 * 256); | ||
| 122 | new_data[i] = ((scaled * max_duty as u32) / 256) as u16; | ||
| 123 | } | ||
| 124 | |||
| 125 | // Write new data to the ring buffer | ||
| 126 | match ring_pwm.write_exact(&new_data).await { | ||
| 127 | Ok(_remaining) => {} | ||
| 128 | Err(e) => { | ||
| 129 | info!("Write error: {:?}", e); | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | // Update phase for animation effect | ||
| 134 | phase += 2.0; | ||
| 135 | if phase >= 64.0 { | ||
| 136 | phase = 0.0; | ||
| 137 | } | ||
| 138 | |||
| 139 | // Vary amplitude for breathing effect | ||
| 140 | amplitude += amplitude_direction; | ||
| 141 | if amplitude <= 0.2 || amplitude >= 1.0 { | ||
| 142 | amplitude_direction = -amplitude_direction; | ||
| 143 | } | ||
| 144 | |||
| 145 | // Log buffer status periodically | ||
| 146 | if (phase as u32) % 10 == 0 { | ||
| 147 | match ring_pwm.len() { | ||
| 148 | Ok(len) => info!("Ring buffer fill: {}/{}", len, ring_pwm.capacity()), | ||
| 149 | Err(_) => info!("Error reading buffer length"), | ||
| 150 | } | ||
| 151 | } | ||
| 152 | } | ||
| 153 | } | ||
diff --git a/examples/stm32f7/src/bin/qspi.rs b/examples/stm32f7/src/bin/qspi.rs index 80652b865..e8ef3ad81 100644 --- a/examples/stm32f7/src/bin/qspi.rs +++ b/examples/stm32f7/src/bin/qspi.rs | |||
| @@ -4,11 +4,11 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::Config as StmCfg; | ||
| 7 | use embassy_stm32::mode::Async; | 8 | use embassy_stm32::mode::Async; |
| 8 | use embassy_stm32::qspi::enums::{AddressSize, ChipSelectHighTime, FIFOThresholdLevel, MemorySize, *}; | 9 | use embassy_stm32::qspi::enums::{AddressSize, ChipSelectHighTime, FIFOThresholdLevel, MemorySize, *}; |
| 9 | use embassy_stm32::qspi::{Config as QspiCfg, Instance, Qspi, TransferConfig}; | 10 | use embassy_stm32::qspi::{Config as QspiCfg, Instance, Qspi, TransferConfig}; |
| 10 | use embassy_stm32::time::mhz; | 11 | use embassy_stm32::time::mhz; |
| 11 | use embassy_stm32::Config as StmCfg; | ||
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | const MEMORY_PAGE_SIZE: usize = 256; | 14 | const MEMORY_PAGE_SIZE: usize = 256; |
diff --git a/examples/stm32f7/src/bin/sdmmc.rs b/examples/stm32f7/src/bin/sdmmc.rs index 787bef25e..e5d261d89 100644 --- a/examples/stm32f7/src/bin/sdmmc.rs +++ b/examples/stm32f7/src/bin/sdmmc.rs | |||
| @@ -4,8 +4,9 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::sdmmc::Sdmmc; | 6 | use embassy_stm32::sdmmc::Sdmmc; |
| 7 | use embassy_stm32::time::{mhz, Hertz}; | 7 | use embassy_stm32::sdmmc::sd::{CmdBlock, StorageDevice}; |
| 8 | use embassy_stm32::{bind_interrupts, peripherals, sdmmc, Config}; | 8 | use embassy_stm32::time::{Hertz, mhz}; |
| 9 | use embassy_stm32::{Config, bind_interrupts, peripherals, sdmmc}; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 11 | ||
| 11 | bind_interrupts!(struct Irqs { | 12 | bind_interrupts!(struct Irqs { |
| @@ -54,9 +55,13 @@ async fn main(_spawner: Spawner) { | |||
| 54 | // Should print 400kHz for initialization | 55 | // Should print 400kHz for initialization |
| 55 | info!("Configured clock: {}", sdmmc.clock().0); | 56 | info!("Configured clock: {}", sdmmc.clock().0); |
| 56 | 57 | ||
| 57 | unwrap!(sdmmc.init_sd_card(mhz(25)).await); | 58 | let mut cmd_block = CmdBlock::new(); |
| 58 | 59 | ||
| 59 | let card = unwrap!(sdmmc.card()); | 60 | let storage = StorageDevice::new_sd_card(&mut sdmmc, &mut cmd_block, mhz(25)) |
| 61 | .await | ||
| 62 | .unwrap(); | ||
| 60 | 63 | ||
| 61 | info!("Card: {:#?}", Debug2Format(card)); | 64 | let card = storage.card(); |
| 65 | |||
| 66 | info!("Card: {:#?}", Debug2Format(&card)); | ||
| 62 | } | 67 | } |
diff --git a/examples/stm32f7/src/bin/usb_serial.rs b/examples/stm32f7/src/bin/usb_serial.rs index 349012888..9a30b2c20 100644 --- a/examples/stm32f7/src/bin/usb_serial.rs +++ b/examples/stm32f7/src/bin/usb_serial.rs | |||
| @@ -6,10 +6,10 @@ use embassy_executor::Spawner; | |||
| 6 | use embassy_futures::join::join; | 6 | use embassy_futures::join::join; |
| 7 | use embassy_stm32::time::Hertz; | 7 | use embassy_stm32::time::Hertz; |
| 8 | use embassy_stm32::usb::{Driver, Instance}; | 8 | use embassy_stm32::usb::{Driver, Instance}; |
| 9 | use embassy_stm32::{bind_interrupts, peripherals, usb, Config}; | 9 | use embassy_stm32::{Config, bind_interrupts, peripherals, usb}; |
| 10 | use embassy_usb::Builder; | ||
| 10 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | 11 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; |
| 11 | use embassy_usb::driver::EndpointError; | 12 | use embassy_usb::driver::EndpointError; |
| 12 | use embassy_usb::Builder; | ||
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| 15 | bind_interrupts!(struct Irqs { | 15 | bind_interrupts!(struct Irqs { |
