diff options
| author | Bob McWhirter <[email protected]> | 2021-07-16 14:40:25 -0400 |
|---|---|---|
| committer | Bob McWhirter <[email protected]> | 2021-07-16 14:41:20 -0400 |
| commit | 0119ea809dba3a0b002174f615650a5a8fd9c22e (patch) | |
| tree | 153099c2262417d6bb994e71de4dba6e449a46bd /examples | |
| parent | 1254e99be12b8a2520b46936a016480d5f689dd7 (diff) | |
Get DMA on H7 working, add usart_dma example for H7.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32h7/src/bin/usart_dma.rs | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs new file mode 100644 index 000000000..fd5da8b35 --- /dev/null +++ b/examples/stm32h7/src/bin/usart_dma.rs | |||
| @@ -0,0 +1,100 @@ | |||
| 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 embassy::executor::Executor; | ||
| 13 | use embassy::time::Clock; | ||
| 14 | use embassy::util::Forever; | ||
| 15 | use embassy_stm32::dma::NoDma; | ||
| 16 | use embassy_stm32::usart::{Config, Uart}; | ||
| 17 | use example_common::*; | ||
| 18 | use embassy_traits::uart::Write as _Write; | ||
| 19 | |||
| 20 | use hal::prelude::*; | ||
| 21 | use stm32h7xx_hal as hal; | ||
| 22 | |||
| 23 | use cortex_m_rt::entry; | ||
| 24 | use stm32h7::stm32h743 as pac; | ||
| 25 | use heapless::String; | ||
| 26 | |||
| 27 | #[embassy::task] | ||
| 28 | async fn main_task() { | ||
| 29 | let p = embassy_stm32::init(Default::default()); | ||
| 30 | |||
| 31 | let config = Config::default(); | ||
| 32 | let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, p.DMA1_0, NoDma, config); | ||
| 33 | |||
| 34 | for n in 0u32.. { | ||
| 35 | let mut s: String<128> = String::new(); | ||
| 36 | core::write!(&mut s, "Hello DMA World {}!\r\n", n).unwrap(); | ||
| 37 | |||
| 38 | usart.write(s.as_bytes()).await.ok(); | ||
| 39 | |||
| 40 | info!("wrote DMA"); | ||
| 41 | } | ||
| 42 | |||
| 43 | } | ||
| 44 | |||
| 45 | struct ZeroClock; | ||
| 46 | |||
| 47 | impl Clock for ZeroClock { | ||
| 48 | fn now(&self) -> u64 { | ||
| 49 | 0 | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 54 | |||
| 55 | #[entry] | ||
| 56 | fn main() -> ! { | ||
| 57 | info!("Hello World!"); | ||
| 58 | |||
| 59 | let pp = pac::Peripherals::take().unwrap(); | ||
| 60 | |||
| 61 | let pwrcfg = pp.PWR.constrain().freeze(); | ||
| 62 | |||
| 63 | let rcc = pp.RCC.constrain(); | ||
| 64 | |||
| 65 | rcc.sys_ck(96.mhz()) | ||
| 66 | .pclk1(48.mhz()) | ||
| 67 | .pclk2(48.mhz()) | ||
| 68 | .pclk3(48.mhz()) | ||
| 69 | .pclk4(48.mhz()) | ||
| 70 | .pll1_q_ck(48.mhz()) | ||
| 71 | .freeze(pwrcfg, &pp.SYSCFG); | ||
| 72 | |||
| 73 | let pp = unsafe { pac::Peripherals::steal() }; | ||
| 74 | |||
| 75 | pp.DBGMCU.cr.modify(|_, w| { | ||
| 76 | w.dbgsleep_d1().set_bit(); | ||
| 77 | w.dbgstby_d1().set_bit(); | ||
| 78 | w.dbgstop_d1().set_bit(); | ||
| 79 | w.d1dbgcken().set_bit(); | ||
| 80 | w | ||
| 81 | }); | ||
| 82 | |||
| 83 | pp.RCC.ahb4enr.modify(|_, w| { | ||
| 84 | w.gpioaen().set_bit(); | ||
| 85 | w.gpioben().set_bit(); | ||
| 86 | w.gpiocen().set_bit(); | ||
| 87 | w.gpioden().set_bit(); | ||
| 88 | w.gpioeen().set_bit(); | ||
| 89 | w.gpiofen().set_bit(); | ||
| 90 | w | ||
| 91 | }); | ||
| 92 | |||
| 93 | unsafe { embassy::time::set_clock(&ZeroClock) }; | ||
| 94 | |||
| 95 | let executor = EXECUTOR.put(Executor::new()); | ||
| 96 | |||
| 97 | executor.run(|spawner| { | ||
| 98 | unwrap!(spawner.spawn(main_task())); | ||
| 99 | }) | ||
| 100 | } | ||
