From d81395fab3c4e336650b0481790ecdab7d7aa13f Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 14 Dec 2023 16:01:51 +0100 Subject: Update embedded-hal to 1.0.0-rc.3 --- examples/stm32f4/src/bin/button.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs index b13e64531..aa1eed46f 100644 --- a/examples/stm32f4/src/bin/button.rs +++ b/examples/stm32f4/src/bin/button.rs @@ -13,7 +13,7 @@ fn main() -> ! { let p = embassy_stm32::init(Default::default()); - let button = Input::new(p.PC13, Pull::Down); + let mut button = Input::new(p.PC13, Pull::Down); let mut led1 = Output::new(p.PB0, Level::High, Speed::Low); let _led2 = Output::new(p.PB7, Level::High, Speed::Low); let mut led3 = Output::new(p.PB14, Level::High, Speed::Low); -- cgit From a165d73eedfd7e02fe5360e9d844882e0d0df113 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Fri, 15 Dec 2023 14:10:11 +0800 Subject: add ws2812 example for stm32f4 with PWM and DMA --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 135 +++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 examples/stm32f4/src/bin/ws2812_pwm_dma.rs (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs new file mode 100644 index 000000000..79493dced --- /dev/null +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -0,0 +1,135 @@ +// Configure TIM3 in PWM mode, and start DMA Transfer(s) to send color data into ws2812. +// We assume the DIN pin of ws2812 connect to GPIO PB4, and ws2812 is properly powered. +// +// This demo is a combination of HAL, PAC, and manually invoke `dma::Transfer` +// +// Warning: +// DO NOT stare at ws2812 directy (especially after each MCU Reset), its (max) brightness could easily make your eyes feel burn. + +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use embassy_executor::Spawner; + +use embassy_stm32::{ + gpio::OutputType, + pac, + time::khz, + timer::{ + simple_pwm::{PwmPin, SimplePwm}, + Channel, CountingMode, + }, +}; +use embassy_time::Timer; + +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let mut device_config = embassy_stm32::Config::default(); + + // set SYSCLK/HCLK/PCLK2 to 20 MHz, thus each tick is 0.05 us, + // and ws2812 timings are integer multiples of 0.05 us + { + use embassy_stm32::rcc::*; + use embassy_stm32::time::*; + device_config.enable_debug_during_sleep = true; + device_config.rcc.hse = Some(Hse { + freq: mhz(12), + mode: HseMode::Oscillator, + }); + device_config.rcc.sys = Sysclk::PLL1_P; + device_config.rcc.pll_src = PllSource::HSE; + device_config.rcc.pll = Some(Pll { + prediv: PllPreDiv::DIV6, + mul: PllMul::MUL80, + divp: Some(PllPDiv::DIV8), + divq: None, + divr: None, + }); + } + + let mut dp = embassy_stm32::init(device_config); + + let mut ws2812_pwm = SimplePwm::new( + dp.TIM3, + Some(PwmPin::new_ch1(dp.PB4, OutputType::PushPull)), + None, + None, + None, + khz(800), // data rate of ws2812 + CountingMode::EdgeAlignedUp, + ); + + // PAC level hacking, + // enable auto-reload preload, and enable timer-update-event trigger DMA + { + pac::TIM3.cr1().modify(|v| v.set_arpe(true)); + pac::TIM3.dier().modify(|v| v.set_ude(true)); + } + + // construct ws2812 non-return-to-zero (NRZ) code bit by bit + + let max_duty = ws2812_pwm.get_max_duty(); + let n0 = 8 * max_duty / 25; // ws2812 Bit 0 high level timing + let n1 = 2 * n0; // ws2812 Bit 1 high level timing + + let turn_off = [ + n0, n0, n0, n0, n0, n0, n0, n0, // Green + n0, n0, n0, n0, n0, n0, n0, n0, // Red + n0, n0, n0, n0, n0, n0, n0, n0, // Blue + 0, // keep PWM output low after a transfer + ]; + + let dim_white = [ + n0, n0, n0, n0, n0, n0, n1, n0, // Green + n0, n0, n0, n0, n0, n0, n1, n0, // Red + n0, n0, n0, n0, n0, n0, n1, n0, // Blue + 0, // keep PWM output low after a transfer + ]; + + let color_list = [&turn_off, &dim_white]; + + // make sure PWM output keep low on first start + ws2812_pwm.set_duty(Channel::Ch1, 0); + + { + use embassy_stm32::dma::{Burst, FifoThreshold, Transfer, TransferOptions}; + + // configure FIFO and MBURST of DMA, to minimize DMA occupation on AHB/APB + let mut dma_transfer_option = TransferOptions::default(); + dma_transfer_option.fifo_threshold = Some(FifoThreshold::Full); + dma_transfer_option.mburst = Burst::Incr8; + + let mut color_list_index = 0; + + loop { + // start PWM output + ws2812_pwm.enable(Channel::Ch1); + + unsafe { + Transfer::new_write( + // with &mut, we can easily reuse same DMA channel multiple times + &mut dp.DMA1_CH2, + 5, + color_list[color_list_index], + pac::TIM3.ccr(0).as_ptr() as *mut _, + dma_transfer_option, + ) + .await; + // ws2812 need at least 50 us low level input to confirm the input data and change it's state + Timer::after_micros(50).await; + } + + // stop PWM output for saving some energy + ws2812_pwm.disable(Channel::Ch1); + + // wait another half second, so that we can see color change + Timer::after_millis(500).await; + + // flip the index bit so that next round DMA transfer the other color data + color_list_index ^= 1; + } + } +} -- cgit From 77e372e842c64b95e94fff93a711112514588841 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Fri, 15 Dec 2023 14:15:45 +0800 Subject: cargo fmt --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index 79493dced..0c3444a47 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -11,18 +11,12 @@ #![feature(type_alias_impl_trait)] use embassy_executor::Spawner; - -use embassy_stm32::{ - gpio::OutputType, - pac, - time::khz, - timer::{ - simple_pwm::{PwmPin, SimplePwm}, - Channel, CountingMode, - }, -}; +use embassy_stm32::gpio::OutputType; +use embassy_stm32::pac; +use embassy_stm32::time::khz; +use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; +use embassy_stm32::timer::{Channel, CountingMode}; use embassy_time::Timer; - use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -- cgit From ea1e1973eb88a3a57e7f4e2ad97d32e5fcd8b8d1 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Sat, 16 Dec 2023 02:15:56 +0800 Subject: unify channel assign --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index 0c3444a47..52cc665c7 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -85,8 +85,10 @@ async fn main(_spawner: Spawner) { let color_list = [&turn_off, &dim_white]; + let pwm_channel = Channel::Ch1; + // make sure PWM output keep low on first start - ws2812_pwm.set_duty(Channel::Ch1, 0); + ws2812_pwm.set_duty(pwm_channel, 0); { use embassy_stm32::dma::{Burst, FifoThreshold, Transfer, TransferOptions}; @@ -100,7 +102,7 @@ async fn main(_spawner: Spawner) { loop { // start PWM output - ws2812_pwm.enable(Channel::Ch1); + ws2812_pwm.enable(pwm_channel); unsafe { Transfer::new_write( @@ -108,7 +110,7 @@ async fn main(_spawner: Spawner) { &mut dp.DMA1_CH2, 5, color_list[color_list_index], - pac::TIM3.ccr(0).as_ptr() as *mut _, + pac::TIM3.ccr(pwm_channel.raw()).as_ptr() as *mut _, dma_transfer_option, ) .await; @@ -117,7 +119,7 @@ async fn main(_spawner: Spawner) { } // stop PWM output for saving some energy - ws2812_pwm.disable(Channel::Ch1); + ws2812_pwm.disable(pwm_channel); // wait another half second, so that we can see color change Timer::after_millis(500).await; -- cgit From 0a890cfbe7fc10bc40f2e97bc4fac17630e9864f Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Sun, 17 Dec 2023 23:47:00 +0800 Subject: stm32f4 ws2812 example with spi ... ... and more doc on TIM&DMA version, also remove useless TIM APRE settings, and use for loop instead of manually flip the index bit, and replace `embassy_time::Timer` with `embassy_time::Ticker`, for more constant time interval. --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 76 +++++++++++++----------- examples/stm32f4/src/bin/ws2812_spi.rs | 95 ++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 35 deletions(-) create mode 100644 examples/stm32f4/src/bin/ws2812_spi.rs (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index 52cc665c7..dccd639ac 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -1,7 +1,16 @@ // Configure TIM3 in PWM mode, and start DMA Transfer(s) to send color data into ws2812. // We assume the DIN pin of ws2812 connect to GPIO PB4, and ws2812 is properly powered. // -// This demo is a combination of HAL, PAC, and manually invoke `dma::Transfer` +// The idea is that the data rate of ws2812 is 800 kHz, and it use different duty ratio to represent bit 0 and bit 1. +// Thus we can set TIM overflow at 800 kHz, and let TIM Update Event trigger a DMA transfer, then let DMA change CCR value, +// such that pwm duty ratio meet the bit representation of ws2812. +// +// You may want to modify TIM CCR with Cortex core directly, +// but according to my test, Cortex core will need to run far more than 100 MHz to catch up with TIM. +// Thus we need to use a DMA. +// +// This demo is a combination of HAL, PAC, and manually invoke `dma::Transfer`. +// If you need a simpler way to control ws2812, you may want to take a look at `ws2812_spi.rs` file, which make use of SPI. // // Warning: // DO NOT stare at ws2812 directy (especially after each MCU Reset), its (max) brightness could easily make your eyes feel burn. @@ -16,7 +25,7 @@ use embassy_stm32::pac; use embassy_stm32::time::khz; use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::timer::{Channel, CountingMode}; -use embassy_time::Timer; +use embassy_time::{Duration, Ticker, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] @@ -33,7 +42,6 @@ async fn main(_spawner: Spawner) { freq: mhz(12), mode: HseMode::Oscillator, }); - device_config.rcc.sys = Sysclk::PLL1_P; device_config.rcc.pll_src = PllSource::HSE; device_config.rcc.pll = Some(Pll { prediv: PllPreDiv::DIV6, @@ -42,6 +50,7 @@ async fn main(_spawner: Spawner) { divq: None, divr: None, }); + device_config.rcc.sys = Sysclk::PLL1_P; } let mut dp = embassy_stm32::init(device_config); @@ -56,14 +65,11 @@ async fn main(_spawner: Spawner) { CountingMode::EdgeAlignedUp, ); - // PAC level hacking, - // enable auto-reload preload, and enable timer-update-event trigger DMA - { - pac::TIM3.cr1().modify(|v| v.set_arpe(true)); - pac::TIM3.dier().modify(|v| v.set_ude(true)); - } + // PAC level hacking, enable timer-update-event trigger DMA + pac::TIM3.dier().modify(|v| v.set_ude(true)); // construct ws2812 non-return-to-zero (NRZ) code bit by bit + // ws2812 only need 24 bits for each LED, but we add one bit more to keep PWM output low let max_duty = ws2812_pwm.get_max_duty(); let n0 = 8 * max_duty / 25; // ws2812 Bit 0 high level timing @@ -83,7 +89,7 @@ async fn main(_spawner: Spawner) { 0, // keep PWM output low after a transfer ]; - let color_list = [&turn_off, &dim_white]; + let color_list = &[&turn_off, &dim_white]; let pwm_channel = Channel::Ch1; @@ -98,34 +104,34 @@ async fn main(_spawner: Spawner) { dma_transfer_option.fifo_threshold = Some(FifoThreshold::Full); dma_transfer_option.mburst = Burst::Incr8; - let mut color_list_index = 0; + // flip color at 2 Hz + let mut ticker = Ticker::every(Duration::from_micros(500)); loop { - // start PWM output - ws2812_pwm.enable(pwm_channel); - - unsafe { - Transfer::new_write( - // with &mut, we can easily reuse same DMA channel multiple times - &mut dp.DMA1_CH2, - 5, - color_list[color_list_index], - pac::TIM3.ccr(pwm_channel.raw()).as_ptr() as *mut _, - dma_transfer_option, - ) - .await; - // ws2812 need at least 50 us low level input to confirm the input data and change it's state - Timer::after_micros(50).await; + for &color in color_list { + // start PWM output + ws2812_pwm.enable(pwm_channel); + + unsafe { + Transfer::new_write( + // with &mut, we can easily reuse same DMA channel multiple times + &mut dp.DMA1_CH2, + 5, + color, + pac::TIM3.ccr(pwm_channel.raw()).as_ptr() as *mut _, + dma_transfer_option, + ) + .await; + // ws2812 need at least 50 us low level input to confirm the input data and change it's state + Timer::after_micros(50).await; + } + + // stop PWM output for saving some energy + ws2812_pwm.disable(pwm_channel); + + // wait until ticker tick + ticker.next().await; } - - // stop PWM output for saving some energy - ws2812_pwm.disable(pwm_channel); - - // wait another half second, so that we can see color change - Timer::after_millis(500).await; - - // flip the index bit so that next round DMA transfer the other color data - color_list_index ^= 1; } } } diff --git a/examples/stm32f4/src/bin/ws2812_spi.rs b/examples/stm32f4/src/bin/ws2812_spi.rs new file mode 100644 index 000000000..e0d28af7f --- /dev/null +++ b/examples/stm32f4/src/bin/ws2812_spi.rs @@ -0,0 +1,95 @@ +// Mimic PWM with SPI, to control ws2812 +// We assume the DIN pin of ws2812 connect to GPIO PB5, and ws2812 is properly powered. +// +// The idea is that the data rate of ws2812 is 800 kHz, and it use different duty ratio to represent bit 0 and bit 1. +// Thus we can adjust SPI to send each *round* of data at 800 kHz, and in each *round*, we can adjust each *bit* to mimic 2 different PWM waveform. +// such that the output waveform meet the bit representation of ws2812. +// +// If you want to save SPI for other purpose, you may want to take a look at `ws2812_tim_dma.rs` file, which make use of TIM and DMA. +// +// Warning: +// DO NOT stare at ws2812 directy (especially after each MCU Reset), its (max) brightness could easily make your eyes feel burn. + +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use embassy_stm32::time::khz; +use embassy_stm32::{dma, spi}; +use embassy_time::{Duration, Ticker, Timer}; +use {defmt_rtt as _, panic_probe as _}; + +// we use 16 bit data frame format of SPI, to let timing as accurate as possible. +// thanks to loose tolerance of ws2812 timing, you can also use 8 bit data frame format, thus you need want to adjust the bit representation. +const N0: u16 = 0b1111100000000000u16; // ws2812 Bit 0 high level timing +const N1: u16 = 0b1111111111000000u16; // ws2812 Bit 1 high level timing + +// ws2812 only need 24 bits for each LED, but we add one bit more to keep SPI output low + +static TURN_OFF: [u16; 25] = [ + N0, N0, N0, N0, N0, N0, N0, N0, // Green + N0, N0, N0, N0, N0, N0, N0, N0, // Red + N0, N0, N0, N0, N0, N0, N0, N0, // Blue + 0, // keep SPI output low after last bit +]; + +static DIM_WHITE: [u16; 25] = [ + N0, N0, N0, N0, N0, N0, N1, N0, // Green + N0, N0, N0, N0, N0, N0, N1, N0, // Red + N0, N0, N0, N0, N0, N0, N1, N0, // Blue + 0, // keep SPI output low after last bit +]; + +static COLOR_LIST: &[&[u16]] = &[&TURN_OFF, &DIM_WHITE]; + +#[embassy_executor::main] +async fn main(_spawner: embassy_executor::Spawner) { + let mut device_config = embassy_stm32::Config::default(); + + // Since we use 16 bit SPI, and we need each round 800 kHz, + // thus SPI output speed should be 800 kHz * 16 = 12.8 MHz, and APB clock should be 2 * 12.8 MHz = 25.6 MHz. + // + // As for my setup, with 12 MHz HSE, I got 25.5 MHz SYSCLK, which is slightly slower, but it's ok for ws2812. + { + use embassy_stm32::rcc::{Hse, HseMode, Pll, PllMul, PllPDiv, PllPreDiv, PllSource, Sysclk}; + use embassy_stm32::time::mhz; + device_config.enable_debug_during_sleep = true; + device_config.rcc.hse = Some(Hse { + freq: mhz(12), + mode: HseMode::Oscillator, + }); + device_config.rcc.pll_src = PllSource::HSE; + device_config.rcc.pll = Some(Pll { + prediv: PllPreDiv::DIV6, + mul: PllMul::MUL102, + divp: Some(PllPDiv::DIV8), + divq: None, + divr: None, + }); + device_config.rcc.sys = Sysclk::PLL1_P; + } + + let dp = embassy_stm32::init(device_config); + + // Set SPI output speed. + // It's ok to blindly set frequency to 12800 kHz, the hal crate will take care of the SPI CR1 BR field. + // And in my case, the real bit rate will be 25.5 MHz / 2 = 12_750 kHz + let mut spi_config = spi::Config::default(); + spi_config.frequency = khz(12_800); + + // Since we only output waveform, then the Rx and Sck it is not considered + let mut ws2812_spi = spi::Spi::new_txonly_nosck(dp.SPI1, dp.PB5, dp.DMA2_CH2, dma::NoDma, spi_config); + + // flip color at 2 Hz + let mut ticker = Ticker::every(Duration::from_millis(500)); + + loop { + for &color in COLOR_LIST { + ws2812_spi.write(color).await.unwrap(); + // ws2812 need at least 50 us low level input to confirm the input data and change it's state + Timer::after_micros(50).await; + // wait until ticker tick + ticker.next().await; + } + } +} -- cgit From 1934c2abc81f0dd981fad625ec2712964d0a1a91 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Mon, 18 Dec 2023 00:06:32 +0800 Subject: match up with stm32f429zi feature flag stm32f429 has less DMA channel than stm32f411 --- examples/stm32f4/src/bin/ws2812_spi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/ws2812_spi.rs b/examples/stm32f4/src/bin/ws2812_spi.rs index e0d28af7f..170f0b59b 100644 --- a/examples/stm32f4/src/bin/ws2812_spi.rs +++ b/examples/stm32f4/src/bin/ws2812_spi.rs @@ -78,7 +78,7 @@ async fn main(_spawner: embassy_executor::Spawner) { spi_config.frequency = khz(12_800); // Since we only output waveform, then the Rx and Sck it is not considered - let mut ws2812_spi = spi::Spi::new_txonly_nosck(dp.SPI1, dp.PB5, dp.DMA2_CH2, dma::NoDma, spi_config); + let mut ws2812_spi = spi::Spi::new_txonly_nosck(dp.SPI1, dp.PB5, dp.DMA2_CH3, dma::NoDma, spi_config); // flip color at 2 Hz let mut ticker = Ticker::every(Duration::from_millis(500)); -- cgit From 05b8818de01866fa988a8f65a395690f02176b34 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Mon, 18 Dec 2023 01:02:58 +0800 Subject: typo fix --- examples/stm32f4/src/bin/ws2812_spi.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/ws2812_spi.rs b/examples/stm32f4/src/bin/ws2812_spi.rs index 170f0b59b..eca657900 100644 --- a/examples/stm32f4/src/bin/ws2812_spi.rs +++ b/examples/stm32f4/src/bin/ws2812_spi.rs @@ -5,7 +5,7 @@ // Thus we can adjust SPI to send each *round* of data at 800 kHz, and in each *round*, we can adjust each *bit* to mimic 2 different PWM waveform. // such that the output waveform meet the bit representation of ws2812. // -// If you want to save SPI for other purpose, you may want to take a look at `ws2812_tim_dma.rs` file, which make use of TIM and DMA. +// If you want to save SPI for other purpose, you may want to take a look at `ws2812_pwm_dma.rs` file, which make use of TIM and DMA. // // Warning: // DO NOT stare at ws2812 directy (especially after each MCU Reset), its (max) brightness could easily make your eyes feel burn. @@ -20,11 +20,12 @@ use embassy_time::{Duration, Ticker, Timer}; use {defmt_rtt as _, panic_probe as _}; // we use 16 bit data frame format of SPI, to let timing as accurate as possible. -// thanks to loose tolerance of ws2812 timing, you can also use 8 bit data frame format, thus you need want to adjust the bit representation. +// thanks to loose tolerance of ws2812 timing, you can also use 8 bit data frame format, thus you will need to adjust the bit representation. const N0: u16 = 0b1111100000000000u16; // ws2812 Bit 0 high level timing const N1: u16 = 0b1111111111000000u16; // ws2812 Bit 1 high level timing -// ws2812 only need 24 bits for each LED, but we add one bit more to keep SPI output low +// ws2812 only need 24 bits for each LED, +// but we add one bit more to keep SPI output low at the end static TURN_OFF: [u16; 25] = [ N0, N0, N0, N0, N0, N0, N0, N0, // Green @@ -77,7 +78,7 @@ async fn main(_spawner: embassy_executor::Spawner) { let mut spi_config = spi::Config::default(); spi_config.frequency = khz(12_800); - // Since we only output waveform, then the Rx and Sck it is not considered + // Since we only output waveform, then the Rx and Sck and RxDma it is not considered let mut ws2812_spi = spi::Spi::new_txonly_nosck(dp.SPI1, dp.PB5, dp.DMA2_CH3, dma::NoDma, spi_config); // flip color at 2 Hz -- cgit From 80c9d04bbd83367340a4f3a1e991df825a0b6029 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 17 Dec 2023 22:09:14 +0100 Subject: stm32: add some docs. --- examples/stm32f4/src/bin/flash.rs | 6 +++--- examples/stm32f4/src/bin/flash_async.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/flash.rs b/examples/stm32f4/src/bin/flash.rs index 93c54e943..56a35ddee 100644 --- a/examples/stm32f4/src/bin/flash.rs +++ b/examples/stm32f4/src/bin/flash.rs @@ -31,7 +31,7 @@ fn test_flash(f: &mut Flash<'_, Blocking>, offset: u32, size: u32) { info!("Reading..."); let mut buf = [0u8; 32]; - unwrap!(f.read(offset, &mut buf)); + unwrap!(f.blocking_read(offset, &mut buf)); info!("Read: {=[u8]:x}", buf); info!("Erasing..."); @@ -39,7 +39,7 @@ fn test_flash(f: &mut Flash<'_, Blocking>, offset: u32, size: u32) { info!("Reading..."); let mut buf = [0u8; 32]; - unwrap!(f.read(offset, &mut buf)); + unwrap!(f.blocking_read(offset, &mut buf)); info!("Read after erase: {=[u8]:x}", buf); info!("Writing..."); @@ -53,7 +53,7 @@ fn test_flash(f: &mut Flash<'_, Blocking>, offset: u32, size: u32) { info!("Reading..."); let mut buf = [0u8; 32]; - unwrap!(f.read(offset, &mut buf)); + unwrap!(f.blocking_read(offset, &mut buf)); info!("Read: {=[u8]:x}", buf); assert_eq!( &buf[..], diff --git a/examples/stm32f4/src/bin/flash_async.rs b/examples/stm32f4/src/bin/flash_async.rs index f0a65a725..1624d842e 100644 --- a/examples/stm32f4/src/bin/flash_async.rs +++ b/examples/stm32f4/src/bin/flash_async.rs @@ -48,7 +48,7 @@ async fn test_flash<'a>(f: &mut Flash<'a>, offset: u32, size: u32) { info!("Reading..."); let mut buf = [0u8; 32]; - unwrap!(f.read(offset, &mut buf)); + unwrap!(f.blocking_read(offset, &mut buf)); info!("Read: {=[u8]:x}", buf); info!("Erasing..."); @@ -56,7 +56,7 @@ async fn test_flash<'a>(f: &mut Flash<'a>, offset: u32, size: u32) { info!("Reading..."); let mut buf = [0u8; 32]; - unwrap!(f.read(offset, &mut buf)); + unwrap!(f.blocking_read(offset, &mut buf)); info!("Read after erase: {=[u8]:x}", buf); info!("Writing..."); @@ -73,7 +73,7 @@ async fn test_flash<'a>(f: &mut Flash<'a>, offset: u32, size: u32) { info!("Reading..."); let mut buf = [0u8; 32]; - unwrap!(f.read(offset, &mut buf)); + unwrap!(f.blocking_read(offset, &mut buf)); info!("Read: {=[u8]:x}", buf); assert_eq!( &buf[..], -- cgit From 189b15c426a3a9ef7d4024ba7e5de6a255f88ee7 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 19 Dec 2023 17:35:38 +0100 Subject: stm32/timer: docs. --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index 52cc665c7..39f5d3421 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -110,7 +110,7 @@ async fn main(_spawner: Spawner) { &mut dp.DMA1_CH2, 5, color_list[color_list_index], - pac::TIM3.ccr(pwm_channel.raw()).as_ptr() as *mut _, + pac::TIM3.ccr(pwm_channel.index()).as_ptr() as *mut _, dma_transfer_option, ) .await; -- cgit From 0acf7b09c3bc9176d00479d601356d8df2537a9b Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 21 Dec 2023 08:50:54 +0100 Subject: chore: replace make_static! macro usage with non-macro version --- examples/stm32f4/src/bin/eth.rs | 13 ++++++++----- examples/stm32f4/src/bin/usb_ethernet.rs | 31 ++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 16 deletions(-) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/eth.rs b/examples/stm32f4/src/bin/eth.rs index 088d83c06..17a14aac4 100644 --- a/examples/stm32f4/src/bin/eth.rs +++ b/examples/stm32f4/src/bin/eth.rs @@ -14,7 +14,7 @@ use embassy_stm32::time::Hertz; use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; use embassy_time::Timer; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -63,8 +63,9 @@ async fn main(spawner: Spawner) -> ! { let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::<16, 16>::new()), + PACKETS.init(PacketQueue::<16, 16>::new()), p.ETH, Irqs, p.PA1, @@ -88,11 +89,13 @@ async fn main(spawner: Spawner) -> ! { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs index 6bf5b1cba..57ee35e97 100644 --- a/examples/stm32f4/src/bin/usb_ethernet.rs +++ b/examples/stm32f4/src/bin/usb_ethernet.rs @@ -14,7 +14,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; use embassy_usb::{Builder, UsbDevice}; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; type UsbDriver = Driver<'static, embassy_stm32::peripherals::USB_OTG_FS>; @@ -68,7 +68,8 @@ async fn main(spawner: Spawner) { let p = embassy_stm32::init(config); // Create the driver, from the HAL. - let ep_out_buffer = &mut make_static!([0; 256])[..]; + static OUTPUT_BUFFER: StaticCell<[u8; 256]> = StaticCell::new(); + let ep_out_buffer = &mut OUTPUT_BUFFER.init([0; 256])[..]; let mut config = embassy_stm32::usb_otg::Config::default(); config.vbus_detection = true; let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer, config); @@ -88,14 +89,18 @@ async fn main(spawner: Spawner) { config.device_protocol = 0x01; // Create embassy-usb DeviceBuilder using the driver and config. + static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); let mut builder = Builder::new( driver, config, - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], + &mut DEVICE_DESC.init([0; 256])[..], + &mut CONFIG_DESC.init([0; 256])[..], + &mut BOS_DESC.init([0; 256])[..], &mut [], // no msos descriptors - &mut make_static!([0; 128])[..], + &mut CONTROL_BUF.init([0; 128])[..], ); // Our MAC addr. @@ -104,14 +109,16 @@ async fn main(spawner: Spawner) { let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; // Create classes on the builder. - let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); + static STATE: StaticCell = StaticCell::new(); + let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64); // Build the builder. let usb = builder.build(); unwrap!(spawner.spawn(usb_task(usb))); - let (runner, device) = class.into_embassy_net_device::(make_static!(NetState::new()), our_mac_addr); + static NET_STATE: StaticCell> = StaticCell::new(); + let (runner, device) = class.into_embassy_net_device::(NET_STATE.init(NetState::new()), our_mac_addr); unwrap!(spawner.spawn(usb_ncm_task(runner))); let config = embassy_net::Config::dhcpv4(Default::default()); @@ -128,11 +135,13 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); -- cgit From 8b36a32ed5d834b23e970d5b723dd7df1f1c94a2 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 21 Dec 2023 14:57:49 +0100 Subject: ci: use beta, add secondary nightly ci. --- examples/stm32f4/src/bin/adc.rs | 1 - examples/stm32f4/src/bin/blinky.rs | 1 - examples/stm32f4/src/bin/button.rs | 1 - examples/stm32f4/src/bin/button_exti.rs | 1 - examples/stm32f4/src/bin/can.rs | 1 - examples/stm32f4/src/bin/dac.rs | 1 - examples/stm32f4/src/bin/eth.rs | 1 - examples/stm32f4/src/bin/flash.rs | 1 - examples/stm32f4/src/bin/flash_async.rs | 1 - examples/stm32f4/src/bin/hello.rs | 1 - examples/stm32f4/src/bin/i2c.rs | 1 - examples/stm32f4/src/bin/i2c_async.rs | 1 - examples/stm32f4/src/bin/i2c_comparison.rs | 1 - examples/stm32f4/src/bin/i2s_dma.rs | 1 - examples/stm32f4/src/bin/mco.rs | 1 - examples/stm32f4/src/bin/multiprio.rs | 1 - examples/stm32f4/src/bin/pwm.rs | 1 - examples/stm32f4/src/bin/pwm_complementary.rs | 1 - examples/stm32f4/src/bin/rtc.rs | 1 - examples/stm32f4/src/bin/sdmmc.rs | 1 - examples/stm32f4/src/bin/spi.rs | 1 - examples/stm32f4/src/bin/spi_dma.rs | 1 - examples/stm32f4/src/bin/usart.rs | 1 - examples/stm32f4/src/bin/usart_buffered.rs | 1 - examples/stm32f4/src/bin/usart_dma.rs | 1 - examples/stm32f4/src/bin/usb_ethernet.rs | 1 - examples/stm32f4/src/bin/usb_raw.rs | 1 - examples/stm32f4/src/bin/usb_serial.rs | 1 - examples/stm32f4/src/bin/wdt.rs | 1 - examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 1 - 30 files changed, 30 deletions(-) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs index f19328727..699c29c05 100644 --- a/examples/stm32f4/src/bin/adc.rs +++ b/examples/stm32f4/src/bin/adc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m::prelude::_embedded_hal_blocking_delay_DelayUs; use defmt::*; diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs index 4bfc5a50d..31cce8225 100644 --- a/examples/stm32f4/src/bin/blinky.rs +++ b/examples/stm32f4/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs index aa1eed46f..ad30a56a2 100644 --- a/examples/stm32f4/src/bin/button.rs +++ b/examples/stm32f4/src/bin/button.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32f4/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs index dfe587d41..67751187d 100644 --- a/examples/stm32f4/src/bin/button_exti.rs +++ b/examples/stm32f4/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/can.rs b/examples/stm32f4/src/bin/can.rs index 20ce4edce..d074b4265 100644 --- a/examples/stm32f4/src/bin/can.rs +++ b/examples/stm32f4/src/bin/can.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/dac.rs b/examples/stm32f4/src/bin/dac.rs index 8f14d6078..9c7754c4f 100644 --- a/examples/stm32f4/src/bin/dac.rs +++ b/examples/stm32f4/src/bin/dac.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/eth.rs b/examples/stm32f4/src/bin/eth.rs index 17a14aac4..7f5c8fdb1 100644 --- a/examples/stm32f4/src/bin/eth.rs +++ b/examples/stm32f4/src/bin/eth.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/flash.rs b/examples/stm32f4/src/bin/flash.rs index 56a35ddee..1e8cabab4 100644 --- a/examples/stm32f4/src/bin/flash.rs +++ b/examples/stm32f4/src/bin/flash.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/flash_async.rs b/examples/stm32f4/src/bin/flash_async.rs index 1624d842e..493a536f3 100644 --- a/examples/stm32f4/src/bin/flash_async.rs +++ b/examples/stm32f4/src/bin/flash_async.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/hello.rs b/examples/stm32f4/src/bin/hello.rs index a2a287110..3c295612c 100644 --- a/examples/stm32f4/src/bin/hello.rs +++ b/examples/stm32f4/src/bin/hello.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/i2c.rs b/examples/stm32f4/src/bin/i2c.rs index 4f4adde28..4b5da774d 100644 --- a/examples/stm32f4/src/bin/i2c.rs +++ b/examples/stm32f4/src/bin/i2c.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/i2c_async.rs b/examples/stm32f4/src/bin/i2c_async.rs index 9f59e4d41..90d11d4b4 100644 --- a/examples/stm32f4/src/bin/i2c_async.rs +++ b/examples/stm32f4/src/bin/i2c_async.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] // Example originally designed for stm32f411ceu6 reading an A1454 hall effect sensor on I2C1 // DMA peripherals changed to compile for stm32f429zi, for the CI. diff --git a/examples/stm32f4/src/bin/i2c_comparison.rs b/examples/stm32f4/src/bin/i2c_comparison.rs index 6d23c0ed8..30cfbdf57 100644 --- a/examples/stm32f4/src/bin/i2c_comparison.rs +++ b/examples/stm32f4/src/bin/i2c_comparison.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] // Example originally designed for stm32f411ceu6 with three A1454 hall effect sensors, connected to I2C1, 2 and 3 // on the pins referenced in the peripheral definitions. diff --git a/examples/stm32f4/src/bin/i2s_dma.rs b/examples/stm32f4/src/bin/i2s_dma.rs index e8d7b5f77..97a04b2aa 100644 --- a/examples/stm32f4/src/bin/i2s_dma.rs +++ b/examples/stm32f4/src/bin/i2s_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; diff --git a/examples/stm32f4/src/bin/mco.rs b/examples/stm32f4/src/bin/mco.rs index 3315e7652..eb7bb6261 100644 --- a/examples/stm32f4/src/bin/mco.rs +++ b/examples/stm32f4/src/bin/mco.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index 74f3bb1c5..328447210 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs @@ -55,7 +55,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs index 8e41d0e78..8844a9f0e 100644 --- a/examples/stm32f4/src/bin/pwm.rs +++ b/examples/stm32f4/src/bin/pwm.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/pwm_complementary.rs b/examples/stm32f4/src/bin/pwm_complementary.rs index d925f26d9..161f43c48 100644 --- a/examples/stm32f4/src/bin/pwm_complementary.rs +++ b/examples/stm32f4/src/bin/pwm_complementary.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/rtc.rs b/examples/stm32f4/src/bin/rtc.rs index 44b4303c0..abab07b6b 100644 --- a/examples/stm32f4/src/bin/rtc.rs +++ b/examples/stm32f4/src/bin/rtc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use chrono::{NaiveDate, NaiveDateTime}; use defmt::*; diff --git a/examples/stm32f4/src/bin/sdmmc.rs b/examples/stm32f4/src/bin/sdmmc.rs index 91747b2d5..66e4e527c 100644 --- a/examples/stm32f4/src/bin/sdmmc.rs +++ b/examples/stm32f4/src/bin/sdmmc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs index 0919e9874..dc9141c62 100644 --- a/examples/stm32f4/src/bin/spi.rs +++ b/examples/stm32f4/src/bin/spi.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs index f291f7dba..7249c831a 100644 --- a/examples/stm32f4/src/bin/spi_dma.rs +++ b/examples/stm32f4/src/bin/spi_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; use core::str::from_utf8; diff --git a/examples/stm32f4/src/bin/usart.rs b/examples/stm32f4/src/bin/usart.rs index 45e94715f..40d9d70f1 100644 --- a/examples/stm32f4/src/bin/usart.rs +++ b/examples/stm32f4/src/bin/usart.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32f4/src/bin/usart_buffered.rs b/examples/stm32f4/src/bin/usart_buffered.rs index 71abc2893..c99807f11 100644 --- a/examples/stm32f4/src/bin/usart_buffered.rs +++ b/examples/stm32f4/src/bin/usart_buffered.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/usart_dma.rs b/examples/stm32f4/src/bin/usart_dma.rs index dca25a78c..dd6de599c 100644 --- a/examples/stm32f4/src/bin/usart_dma.rs +++ b/examples/stm32f4/src/bin/usart_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs index 57ee35e97..a196259a8 100644 --- a/examples/stm32f4/src/bin/usb_ethernet.rs +++ b/examples/stm32f4/src/bin/usb_ethernet.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/usb_raw.rs b/examples/stm32f4/src/bin/usb_raw.rs index 719b22bb9..afff55187 100644 --- a/examples/stm32f4/src/bin/usb_raw.rs +++ b/examples/stm32f4/src/bin/usb_raw.rs @@ -48,7 +48,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/usb_serial.rs b/examples/stm32f4/src/bin/usb_serial.rs index e2ccc9142..58d994a61 100644 --- a/examples/stm32f4/src/bin/usb_serial.rs +++ b/examples/stm32f4/src/bin/usb_serial.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{panic, *}; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/wdt.rs b/examples/stm32f4/src/bin/wdt.rs index 0443b61c5..ea27ebce0 100644 --- a/examples/stm32f4/src/bin/wdt.rs +++ b/examples/stm32f4/src/bin/wdt.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index 39f5d3421..9835c07e4 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -8,7 +8,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_stm32::gpio::OutputType; -- cgit From 53fc344e4d46388cc742c139a263c1cdf0c16589 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Fri, 22 Dec 2023 01:24:31 +0800 Subject: fix timing, turn TIM UDE on only necessary, clean DMA FEIF after each Transfer --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index dc397eff1..c4181d024 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -64,9 +64,6 @@ async fn main(_spawner: Spawner) { CountingMode::EdgeAlignedUp, ); - // PAC level hacking, enable timer-update-event trigger DMA - pac::TIM3.dier().modify(|v| v.set_ude(true)); - // construct ws2812 non-return-to-zero (NRZ) code bit by bit // ws2812 only need 24 bits for each LED, but we add one bit more to keep PWM output low @@ -104,13 +101,16 @@ async fn main(_spawner: Spawner) { dma_transfer_option.mburst = Burst::Incr8; // flip color at 2 Hz - let mut ticker = Ticker::every(Duration::from_micros(500)); + let mut ticker = Ticker::every(Duration::from_millis(500)); loop { for &color in color_list { // start PWM output ws2812_pwm.enable(pwm_channel); + // PAC level hacking, enable timer-update-event trigger DMA + pac::TIM3.dier().modify(|v| v.set_ude(true)); + unsafe { Transfer::new_write( // with &mut, we can easily reuse same DMA channel multiple times @@ -121,6 +121,14 @@ async fn main(_spawner: Spawner) { dma_transfer_option, ) .await; + + // Turn off timer-update-event trigger DMA as soon as possible. + // Then clean the FIFO Error Flag if set. + pac::TIM3.dier().modify(|v| v.set_ude(false)); + if pac::DMA1.isr(0).read().feif(2) { + pac::DMA1.ifcr(0).write(|v| v.set_feif(2, true)); + } + // ws2812 need at least 50 us low level input to confirm the input data and change it's state Timer::after_micros(50).await; } -- cgit From 2f75ffb2333904e1370a845ead88442c45b5ba5d Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Fri, 22 Dec 2023 01:31:25 +0800 Subject: remove unused feature attribute --- examples/stm32f4/src/bin/ws2812_spi.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/ws2812_spi.rs b/examples/stm32f4/src/bin/ws2812_spi.rs index eca657900..a280a3b77 100644 --- a/examples/stm32f4/src/bin/ws2812_spi.rs +++ b/examples/stm32f4/src/bin/ws2812_spi.rs @@ -12,7 +12,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_stm32::time::khz; use embassy_stm32::{dma, spi}; -- cgit From dcd4e6384e3fab32809d01738ecd84011b4f0cc7 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Sat, 23 Dec 2023 19:45:56 +0800 Subject: enable output compare preload for TIM keep output waveform integrity --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index c4181d024..cdce36f2e 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -21,6 +21,7 @@ use embassy_executor::Spawner; use embassy_stm32::gpio::OutputType; use embassy_stm32::pac; +use embassy_stm32::pac::timer::vals::Ocpe; use embassy_stm32::time::khz; use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::timer::{Channel, CountingMode}; @@ -89,6 +90,12 @@ async fn main(_spawner: Spawner) { let pwm_channel = Channel::Ch1; + // PAC level hacking, enable output compare preload + // keep output waveform integrity + pac::TIM3 + .ccmr_output(pwm_channel.index()) + .modify(|v| v.set_ocpe(0, Ocpe::ENABLED)); + // make sure PWM output keep low on first start ws2812_pwm.set_duty(pwm_channel, 0); -- cgit From d90a97aa4c5977e3d071fb4ed94656e6666d965c Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Mon, 25 Dec 2023 21:29:17 +0800 Subject: update metapac after stm32-data PR323 and refactor a few code with cargo clippy --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/stm32f4/src') diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index cdce36f2e..4458b643f 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -21,7 +21,6 @@ use embassy_executor::Spawner; use embassy_stm32::gpio::OutputType; use embassy_stm32::pac; -use embassy_stm32::pac::timer::vals::Ocpe; use embassy_stm32::time::khz; use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::timer::{Channel, CountingMode}; @@ -94,7 +93,7 @@ async fn main(_spawner: Spawner) { // keep output waveform integrity pac::TIM3 .ccmr_output(pwm_channel.index()) - .modify(|v| v.set_ocpe(0, Ocpe::ENABLED)); + .modify(|v| v.set_ocpe(0, true)); // make sure PWM output keep low on first start ws2812_pwm.set_duty(pwm_channel, 0); -- cgit