diff options
| author | Bob McWhirter <[email protected]> | 2021-07-21 16:45:43 -0400 |
|---|---|---|
| committer | Bob McWhirter <[email protected]> | 2021-07-23 13:22:39 -0400 |
| commit | b07325b47600283113ffb8aa99c50080ca092abb (patch) | |
| tree | d5cf728dc187dbcac456035d2089df68f4525f77 /examples/stm32f4 | |
| parent | 8ab82191b76290a69ae068ed99da0e81d07cba12 (diff) | |
Enable DMA for SPIv1 on F4's etc.
Diffstat (limited to 'examples/stm32f4')
| -rw-r--r-- | examples/stm32f4/.cargo/config.toml | 3 | ||||
| -rw-r--r-- | examples/stm32f4/memory.x | 4 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/spi.rs | 3 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/spi_dma.rs | 85 |
4 files changed, 92 insertions, 3 deletions
diff --git a/examples/stm32f4/.cargo/config.toml b/examples/stm32f4/.cargo/config.toml index 8704a9ba5..f7173a194 100644 --- a/examples/stm32f4/.cargo/config.toml +++ b/examples/stm32f4/.cargo/config.toml | |||
| @@ -3,7 +3,8 @@ build-std = ["core"] | |||
| 3 | 3 | ||
| 4 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | 4 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] |
| 5 | # replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` | 5 | # replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` |
| 6 | runner = "probe-run --chip STM32F429ZITx" | 6 | #runner = "probe-run --chip STM32F429ZITx" |
| 7 | runner = "probe-run --chip STM32F401RE" | ||
| 7 | 8 | ||
| 8 | rustflags = [ | 9 | rustflags = [ |
| 9 | # LLD (shipped with the Rust toolchain) is used as the default linker | 10 | # LLD (shipped with the Rust toolchain) is used as the default linker |
diff --git a/examples/stm32f4/memory.x b/examples/stm32f4/memory.x index f21e32572..bcd2bbcd4 100644 --- a/examples/stm32f4/memory.x +++ b/examples/stm32f4/memory.x | |||
| @@ -2,6 +2,6 @@ MEMORY | |||
| 2 | { | 2 | { |
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ |
| 4 | /* These values correspond to the STM32F429ZI */ | 4 | /* These values correspond to the STM32F429ZI */ |
| 5 | FLASH : ORIGIN = 0x08000000, LENGTH = 2048K | 5 | FLASH : ORIGIN = 0x08000000, LENGTH = 512K |
| 6 | RAM : ORIGIN = 0x20000000, LENGTH = 192K | 6 | RAM : ORIGIN = 0x20000000, LENGTH = 96K |
| 7 | } | 7 | } |
diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs index 88fc84bc0..604283877 100644 --- a/examples/stm32f4/src/bin/spi.rs +++ b/examples/stm32f4/src/bin/spi.rs | |||
| @@ -18,6 +18,7 @@ use embassy_stm32::dbgmcu::Dbgmcu; | |||
| 18 | use embassy_stm32::spi::{Config, Spi}; | 18 | use embassy_stm32::spi::{Config, Spi}; |
| 19 | use embassy_stm32::time::Hertz; | 19 | use embassy_stm32::time::Hertz; |
| 20 | use embedded_hal::blocking::spi::Transfer; | 20 | use embedded_hal::blocking::spi::Transfer; |
| 21 | use embassy_stm32::dma::NoDma; | ||
| 21 | 22 | ||
| 22 | #[entry] | 23 | #[entry] |
| 23 | fn main() -> ! { | 24 | fn main() -> ! { |
| @@ -34,6 +35,8 @@ fn main() -> ! { | |||
| 34 | p.PC10, | 35 | p.PC10, |
| 35 | p.PC12, | 36 | p.PC12, |
| 36 | p.PC11, | 37 | p.PC11, |
| 38 | NoDma, | ||
| 39 | NoDma, | ||
| 37 | Hertz(1_000_000), | 40 | Hertz(1_000_000), |
| 38 | Config::default(), | 41 | Config::default(), |
| 39 | ); | 42 | ); |
diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs new file mode 100644 index 000000000..db6b69c85 --- /dev/null +++ b/examples/stm32f4/src/bin/spi_dma.rs | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(trait_alias)] | ||
| 4 | #![feature(min_type_alias_impl_trait)] | ||
| 5 | #![feature(impl_trait_in_bindings)] | ||
| 6 | #![feature(type_alias_impl_trait)] | ||
| 7 | #![allow(incomplete_features)] | ||
| 8 | |||
| 9 | #[path = "../example_common.rs"] | ||
| 10 | mod example_common; | ||
| 11 | use core::fmt::Write; | ||
| 12 | use cortex_m_rt::entry; | ||
| 13 | use embassy::executor::Executor; | ||
| 14 | use embassy::time::Clock; | ||
| 15 | use embassy::util::Forever; | ||
| 16 | use example_common::*; | ||
| 17 | use embassy_traits::spi::FullDuplex; | ||
| 18 | use heapless::String; | ||
| 19 | use embassy_stm32::spi::{Spi, Config}; | ||
| 20 | use embassy_stm32::pac; | ||
| 21 | use embassy_stm32::time::Hertz; | ||
| 22 | use core::str::from_utf8; | ||
| 23 | |||
| 24 | #[embassy::task] | ||
| 25 | async fn main_task() { | ||
| 26 | let p = embassy_stm32::init(Default::default()); | ||
| 27 | |||
| 28 | let mut spi = Spi::new( | ||
| 29 | p.SPI1, | ||
| 30 | p.PB3, | ||
| 31 | p.PA7, | ||
| 32 | p.PA6, | ||
| 33 | p.DMA2_CH3, | ||
| 34 | p.DMA2_CH2, | ||
| 35 | Hertz(1_000_000), | ||
| 36 | Config::default(), | ||
| 37 | ); | ||
| 38 | |||
| 39 | for n in 0u32.. { | ||
| 40 | let mut write: String<128> = String::new(); | ||
| 41 | let mut read = [0;128]; | ||
| 42 | core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); | ||
| 43 | spi.read_write(&mut read[0..write.len()], write.as_bytes()).await.ok(); | ||
| 44 | info!("read via spi+dma: {}", from_utf8(&read).unwrap()); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | struct ZeroClock; | ||
| 49 | |||
| 50 | impl Clock for ZeroClock { | ||
| 51 | fn now(&self) -> u64 { | ||
| 52 | 0 | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 57 | |||
| 58 | #[entry] | ||
| 59 | fn main() -> ! { | ||
| 60 | info!("Hello World!"); | ||
| 61 | unsafe { | ||
| 62 | pac::DBGMCU.cr().modify(|w| { | ||
| 63 | w.set_dbg_sleep(true); | ||
| 64 | w.set_dbg_standby(true); | ||
| 65 | w.set_dbg_stop(true); | ||
| 66 | }); | ||
| 67 | |||
| 68 | pac::RCC.ahb1enr().modify(|w| { | ||
| 69 | w.set_gpioaen(true); | ||
| 70 | w.set_gpioben(true); | ||
| 71 | w.set_gpiocen(true); | ||
| 72 | w.set_gpioden(true); | ||
| 73 | w.set_gpioeen(true); | ||
| 74 | w.set_gpiofen(true); | ||
| 75 | }); | ||
| 76 | } | ||
| 77 | |||
| 78 | unsafe { embassy::time::set_clock(&ZeroClock) }; | ||
| 79 | |||
| 80 | let executor = EXECUTOR.put(Executor::new()); | ||
| 81 | |||
| 82 | executor.run(|spawner| { | ||
| 83 | unwrap!(spawner.spawn(main_task())); | ||
| 84 | }) | ||
| 85 | } | ||
