diff options
| author | JuliDi <[email protected]> | 2023-06-28 16:40:50 +0200 |
|---|---|---|
| committer | JuliDi <[email protected]> | 2023-06-28 16:40:50 +0200 |
| commit | d5898c11ebef63fa0ec6dba8381484f4cfabd65c (patch) | |
| tree | 1af46aa50e45f279265961699aeed0b2f18ed2cc | |
| parent | daedfbbd8756e921cc6343ad531401d309966eaa (diff) | |
remove need for StaticCell in dac_dma example for stm32l4
| -rw-r--r-- | examples/stm32l4/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/dac_dma.rs | 29 |
2 files changed, 8 insertions, 23 deletions
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index d2d228282..3bb473ef5 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml | |||
| @@ -25,5 +25,3 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa | |||
| 25 | heapless = { version = "0.7.5", default-features = false } | 25 | heapless = { version = "0.7.5", default-features = false } |
| 26 | 26 | ||
| 27 | micromath = "2.0.0" | 27 | micromath = "2.0.0" |
| 28 | |||
| 29 | static_cell = "1.0.0" | ||
diff --git a/examples/stm32l4/src/bin/dac_dma.rs b/examples/stm32l4/src/bin/dac_dma.rs index 7c0df835b..c27cc03e1 100644 --- a/examples/stm32l4/src/bin/dac_dma.rs +++ b/examples/stm32l4/src/bin/dac_dma.rs | |||
| @@ -11,14 +11,13 @@ use embassy_stm32::rcc::low_level::RccPeripheral; | |||
| 11 | use embassy_stm32::time::Hertz; | 11 | use embassy_stm32::time::Hertz; |
| 12 | use embassy_stm32::timer::low_level::Basic16bitInstance; | 12 | use embassy_stm32::timer::low_level::Basic16bitInstance; |
| 13 | use micromath::F32Ext; | 13 | use micromath::F32Ext; |
| 14 | use static_cell::StaticCell; | ||
| 15 | use {defmt_rtt as _, panic_probe as _}; | 14 | use {defmt_rtt as _, panic_probe as _}; |
| 16 | 15 | ||
| 17 | pub type Dac1Type<'d> = | 16 | pub type Dac1Type = |
| 18 | embassy_stm32::dac::DacCh1<'d, embassy_stm32::peripherals::DAC1, embassy_stm32::peripherals::DMA1_CH3>; | 17 | embassy_stm32::dac::DacCh1<'static, embassy_stm32::peripherals::DAC1, embassy_stm32::peripherals::DMA1_CH3>; |
| 19 | 18 | ||
| 20 | pub type Dac2Type<'d> = | 19 | pub type Dac2Type = |
| 21 | embassy_stm32::dac::DacCh2<'d, embassy_stm32::peripherals::DAC1, embassy_stm32::peripherals::DMA1_CH4>; | 20 | embassy_stm32::dac::DacCh2<'static, embassy_stm32::peripherals::DAC1, embassy_stm32::peripherals::DMA1_CH4>; |
| 22 | 21 | ||
| 23 | #[embassy_executor::main] | 22 | #[embassy_executor::main] |
| 24 | async fn main(spawner: Spawner) { | 23 | async fn main(spawner: Spawner) { |
| @@ -30,24 +29,12 @@ async fn main(spawner: Spawner) { | |||
| 30 | // Obtain two independent channels (p.DAC1 can only be consumed once, though!) | 29 | // Obtain two independent channels (p.DAC1 can only be consumed once, though!) |
| 31 | let (dac_ch1, dac_ch2) = embassy_stm32::dac::Dac::new(p.DAC1, p.DMA1_CH3, p.DMA1_CH4, p.PA4, p.PA5).split(); | 30 | let (dac_ch1, dac_ch2) = embassy_stm32::dac::Dac::new(p.DAC1, p.DMA1_CH3, p.DMA1_CH4, p.PA4, p.PA5).split(); |
| 32 | 31 | ||
| 33 | let dac1 = { | 32 | spawner.spawn(dac_task1(dac_ch1)).ok(); |
| 34 | type T = impl Sized; | 33 | spawner.spawn(dac_task2(dac_ch2)).ok(); |
| 35 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 36 | STATIC_CELL.init(dac_ch1) | ||
| 37 | }; | ||
| 38 | |||
| 39 | let dac2 = { | ||
| 40 | type T = impl Sized; | ||
| 41 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 42 | STATIC_CELL.init(dac_ch2) | ||
| 43 | }; | ||
| 44 | |||
| 45 | spawner.spawn(dac_task1(dac1)).ok(); | ||
| 46 | spawner.spawn(dac_task2(dac2)).ok(); | ||
| 47 | } | 34 | } |
| 48 | 35 | ||
| 49 | #[embassy_executor::task] | 36 | #[embassy_executor::task] |
| 50 | async fn dac_task1(dac: &'static mut Dac1Type<'static>) { | 37 | async fn dac_task1(mut dac: Dac1Type) { |
| 51 | let data: &[u8; 256] = &calculate_array::<256>(); | 38 | let data: &[u8; 256] = &calculate_array::<256>(); |
| 52 | 39 | ||
| 53 | info!("TIM6 frequency is {}", TIM6::frequency()); | 40 | info!("TIM6 frequency is {}", TIM6::frequency()); |
| @@ -91,7 +78,7 @@ async fn dac_task1(dac: &'static mut Dac1Type<'static>) { | |||
| 91 | } | 78 | } |
| 92 | 79 | ||
| 93 | #[embassy_executor::task] | 80 | #[embassy_executor::task] |
| 94 | async fn dac_task2(dac: &'static mut Dac2Type<'static>) { | 81 | async fn dac_task2(mut dac: Dac2Type) { |
| 95 | let data: &[u8; 256] = &calculate_array::<256>(); | 82 | let data: &[u8; 256] = &calculate_array::<256>(); |
| 96 | 83 | ||
| 97 | info!("TIM7 frequency is {}", TIM7::frequency()); | 84 | info!("TIM7 frequency is {}", TIM7::frequency()); |
