diff options
| author | Bob McWhirter <[email protected]> | 2021-07-13 13:33:38 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-13 13:33:38 -0400 |
| commit | b6eb5dcf2f0f06527a7ed677f44cb0528c6b182e (patch) | |
| tree | a3851981c44ca0e9fd5e34c6b97935a142c3b832 /examples | |
| parent | 8f28d6b4b1e74b3b3b64fd3a28ce1ea9072b7cbb (diff) | |
| parent | 6e0e83cfd907c504c8d2ce05a7304b49565361ff (diff) | |
Merge pull request #282 from bobmcwhirter/dmamux_thales
BDMA + DMAMUX + H7 with major help from @thalesfragoso
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32l4/src/bin/usart.rs | 4 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/usart_dma.rs | 96 |
2 files changed, 96 insertions, 4 deletions
diff --git a/examples/stm32l4/src/bin/usart.rs b/examples/stm32l4/src/bin/usart.rs index 5b6d9eaa1..0b14eeb59 100644 --- a/examples/stm32l4/src/bin/usart.rs +++ b/examples/stm32l4/src/bin/usart.rs | |||
| @@ -82,10 +82,6 @@ fn main() -> ! { | |||
| 82 | w.syscfgen().set_bit(); | 82 | w.syscfgen().set_bit(); |
| 83 | w | 83 | w |
| 84 | }); | 84 | }); |
| 85 | //pp.RCC.apb1enr.modify(|_, w| { | ||
| 86 | //w.usart3en().enabled(); | ||
| 87 | //w | ||
| 88 | //}); | ||
| 89 | 85 | ||
| 90 | unsafe { embassy::time::set_clock(&ZeroClock) }; | 86 | unsafe { embassy::time::set_clock(&ZeroClock) }; |
| 91 | 87 | ||
diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs new file mode 100644 index 000000000..cc630e0df --- /dev/null +++ b/examples/stm32l4/src/bin/usart_dma.rs | |||
| @@ -0,0 +1,96 @@ | |||
| 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 embassy_stm32::usart::{Config, Uart}; | ||
| 17 | use example_common::*; | ||
| 18 | use heapless::String; | ||
| 19 | use stm32l4::stm32l4x5 as pac; | ||
| 20 | |||
| 21 | #[embassy::task] | ||
| 22 | async fn main_task() { | ||
| 23 | let mut p = embassy_stm32::init(Default::default()); | ||
| 24 | |||
| 25 | let config = Config::default(); | ||
| 26 | let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, config); | ||
| 27 | |||
| 28 | for n in 0u32.. { | ||
| 29 | let mut s: String<128> = String::new(); | ||
| 30 | core::write!(&mut s, "Hello DMA World {}!\r\n", n).unwrap(); | ||
| 31 | |||
| 32 | usart | ||
| 33 | .write_dma(&mut p.DMA1_3, s.as_bytes()) | ||
| 34 | .await | ||
| 35 | .unwrap(); | ||
| 36 | info!("wrote DMA"); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | struct ZeroClock; | ||
| 41 | |||
| 42 | impl Clock for ZeroClock { | ||
| 43 | fn now(&self) -> u64 { | ||
| 44 | 0 | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 49 | |||
| 50 | #[entry] | ||
| 51 | fn main() -> ! { | ||
| 52 | info!("Hello World!"); | ||
| 53 | |||
| 54 | let pp = pac::Peripherals::take().unwrap(); | ||
| 55 | |||
| 56 | pp.DBGMCU.cr.modify(|_, w| { | ||
| 57 | w.dbg_sleep().set_bit(); | ||
| 58 | w.dbg_standby().set_bit(); | ||
| 59 | w.dbg_stop().set_bit() | ||
| 60 | }); | ||
| 61 | |||
| 62 | pp.RCC.ahb1enr.modify(|_, w| { | ||
| 63 | unsafe { | ||
| 64 | w.bits( 0x07 ); | ||
| 65 | } | ||
| 66 | w | ||
| 67 | //w.dmamuxen().set_bit(); | ||
| 68 | //w.dma1en().set_bit(); | ||
| 69 | //w.dma2en().set_bit(); | ||
| 70 | //w | ||
| 71 | }); | ||
| 72 | |||
| 73 | pp.RCC.ahb2enr.modify(|_, w| { | ||
| 74 | w.gpioaen().set_bit(); | ||
| 75 | w.gpioben().set_bit(); | ||
| 76 | w.gpiocen().set_bit(); | ||
| 77 | w.gpioden().set_bit(); | ||
| 78 | w.gpioeen().set_bit(); | ||
| 79 | w.gpiofen().set_bit(); | ||
| 80 | w | ||
| 81 | }); | ||
| 82 | |||
| 83 | pp.RCC.apb2enr.modify(|_, w| { | ||
| 84 | w.syscfgen().set_bit(); | ||
| 85 | w | ||
| 86 | }); | ||
| 87 | |||
| 88 | |||
| 89 | unsafe { embassy::time::set_clock(&ZeroClock) }; | ||
| 90 | |||
| 91 | let executor = EXECUTOR.put(Executor::new()); | ||
| 92 | |||
| 93 | executor.run(|spawner| { | ||
| 94 | unwrap!(spawner.spawn(main_task())); | ||
| 95 | }) | ||
| 96 | } | ||
