diff options
| author | xoviat <[email protected]> | 2023-05-03 18:17:57 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-05-03 18:17:57 -0500 |
| commit | 02d6e0d14dec98c01a2b327b0050e80845922510 (patch) | |
| tree | 002ec296b3e5a15dcf39ed9005b0d666b1c268cf /examples | |
| parent | 374c92a4f0fda2932a0a86e5dcc3dc33651a48c7 (diff) | |
stm32/i2s: add module and example for f4
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f4/src/bin/i2s_dma.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/stm32f4/src/bin/i2s_dma.rs b/examples/stm32f4/src/bin/i2s_dma.rs new file mode 100644 index 000000000..e8d7b5f77 --- /dev/null +++ b/examples/stm32f4/src/bin/i2s_dma.rs | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use core::fmt::Write; | ||
| 6 | |||
| 7 | use defmt::*; | ||
| 8 | use embassy_executor::Spawner; | ||
| 9 | use embassy_stm32::i2s::{Config, I2S}; | ||
| 10 | use embassy_stm32::time::Hertz; | ||
| 11 | use heapless::String; | ||
| 12 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | |||
| 14 | #[embassy_executor::main] | ||
| 15 | async fn main(_spawner: Spawner) { | ||
| 16 | let p = embassy_stm32::init(Default::default()); | ||
| 17 | info!("Hello World!"); | ||
| 18 | |||
| 19 | let mut i2s = I2S::new( | ||
| 20 | p.SPI2, | ||
| 21 | p.PC3, // sd | ||
| 22 | p.PB12, // ws | ||
| 23 | p.PB10, // ck | ||
| 24 | p.PC6, // mck | ||
| 25 | p.DMA1_CH4, | ||
| 26 | p.DMA1_CH3, | ||
| 27 | Hertz(1_000_000), | ||
| 28 | Config::default(), | ||
| 29 | ); | ||
| 30 | |||
| 31 | for n in 0u32.. { | ||
| 32 | let mut write: String<128> = String::new(); | ||
| 33 | core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); | ||
| 34 | i2s.write(&mut write.as_bytes()).await.ok(); | ||
| 35 | } | ||
| 36 | } | ||
