diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-08-04 21:32:39 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-08-04 21:32:39 +0200 |
| commit | cfa1f61154193da9a12420cb9cf300b2f3d736b2 (patch) | |
| tree | 3ef781c75da9e94483e6cbdf994bf12b2dd89bb6 /examples/stm32h7 | |
| parent | cee111c8650ad15d47a1495a33370f5ec12f83ed (diff) | |
| parent | 9726f77ce13e4c31fbe9aaa7e259aa9c31b60c63 (diff) | |
Merge pull request #344 from bobmcwhirter/remove_builders
Remove builders from Config(s) and examples.
Diffstat (limited to 'examples/stm32h7')
| -rw-r--r-- | examples/stm32h7/src/bin/dac.rs | 7 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/eth.rs | 31 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/spi.rs | 6 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/spi_dma.rs | 7 | ||||
| -rw-r--r-- | examples/stm32h7/src/example_common.rs | 11 |
5 files changed, 24 insertions, 38 deletions
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs index fcbb0c236..8816f63c2 100644 --- a/examples/stm32h7/src/bin/dac.rs +++ b/examples/stm32h7/src/bin/dac.rs | |||
| @@ -12,17 +12,12 @@ use example_common::*; | |||
| 12 | 12 | ||
| 13 | use cortex_m_rt::entry; | 13 | use cortex_m_rt::entry; |
| 14 | use embassy_stm32::dac::{Channel, Dac, Value}; | 14 | use embassy_stm32::dac::{Channel, Dac, Value}; |
| 15 | use embassy_stm32::rcc; | ||
| 16 | use embassy_stm32::time::U32Ext; | ||
| 17 | use embassy_stm32::Config; | ||
| 18 | 15 | ||
| 19 | #[entry] | 16 | #[entry] |
| 20 | fn main() -> ! { | 17 | fn main() -> ! { |
| 21 | info!("Hello World, dude!"); | 18 | info!("Hello World, dude!"); |
| 22 | 19 | ||
| 23 | let p = embassy_stm32::init( | 20 | let p = embassy_stm32::init(config()); |
| 24 | Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())), | ||
| 25 | ); | ||
| 26 | 21 | ||
| 27 | unsafe { | 22 | unsafe { |
| 28 | Dbgmcu::enable_all(); | 23 | Dbgmcu::enable_all(); |
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 0c544a879..6c4ba6eb9 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -4,7 +4,9 @@ | |||
| 4 | #![feature(trait_alias)] | 4 | #![feature(trait_alias)] |
| 5 | #![feature(type_alias_impl_trait)] | 5 | #![feature(type_alias_impl_trait)] |
| 6 | 6 | ||
| 7 | use core::sync::atomic::{AtomicUsize, Ordering}; | 7 | #[path = "../example_common.rs"] |
| 8 | mod example_common; | ||
| 9 | use example_common::config; | ||
| 8 | 10 | ||
| 9 | use cortex_m_rt::entry; | 11 | use cortex_m_rt::entry; |
| 10 | use defmt::{info, unwrap}; | 12 | use defmt::{info, unwrap}; |
| @@ -18,25 +20,15 @@ use embassy_net::{ | |||
| 18 | Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket, | 20 | Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket, |
| 19 | }; | 21 | }; |
| 20 | use embassy_stm32::clock::{Alarm, Clock}; | 22 | use embassy_stm32::clock::{Alarm, Clock}; |
| 23 | use embassy_stm32::dbgmcu::Dbgmcu; | ||
| 21 | use embassy_stm32::eth::lan8742a::LAN8742A; | 24 | use embassy_stm32::eth::lan8742a::LAN8742A; |
| 22 | use embassy_stm32::eth::{Ethernet, State}; | 25 | use embassy_stm32::eth::{Ethernet, State}; |
| 23 | use embassy_stm32::rcc::{Config as RccConfig, Rcc}; | ||
| 24 | use embassy_stm32::rng::Random; | 26 | use embassy_stm32::rng::Random; |
| 25 | use embassy_stm32::time::Hertz; | 27 | use embassy_stm32::{interrupt, peripherals}; |
| 26 | use embassy_stm32::{interrupt, peripherals, Config}; | ||
| 27 | use heapless::Vec; | 28 | use heapless::Vec; |
| 28 | use panic_probe as _; | 29 | use panic_probe as _; |
| 29 | use peripherals::{RNG, TIM2}; | 30 | use peripherals::{RNG, TIM2}; |
| 30 | 31 | ||
| 31 | defmt::timestamp! {"{=u64}", { | ||
| 32 | static COUNT: AtomicUsize = AtomicUsize::new(0); | ||
| 33 | // NOTE(no-CAS) `timestamps` runs with interrupts disabled | ||
| 34 | let n = COUNT.load(Ordering::Relaxed); | ||
| 35 | COUNT.store(n + 1, Ordering::Relaxed); | ||
| 36 | n as u64 | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | #[embassy::task] | 32 | #[embassy::task] |
| 41 | async fn main_task( | 33 | async fn main_task( |
| 42 | device: &'static mut Ethernet<'static, LAN8742A, 4, 4>, | 34 | device: &'static mut Ethernet<'static, LAN8742A, 4, 4>, |
| @@ -106,17 +98,12 @@ fn main() -> ! { | |||
| 106 | info!("Hello World!"); | 98 | info!("Hello World!"); |
| 107 | 99 | ||
| 108 | info!("Setup RCC..."); | 100 | info!("Setup RCC..."); |
| 109 | let mut rcc_config = RccConfig::default(); | ||
| 110 | rcc_config.sys_ck = Some(Hertz(400_000_000)); | ||
| 111 | rcc_config.pll1.q_ck = Some(Hertz(100_000_000)); | ||
| 112 | let config = Config::default().rcc(rcc_config); | ||
| 113 | 101 | ||
| 114 | let mut p = embassy_stm32::init(config); | 102 | unsafe { |
| 115 | 103 | Dbgmcu::enable_all(); | |
| 116 | // Constrain and Freeze clock | 104 | } |
| 117 | 105 | ||
| 118 | let mut rcc = Rcc::new(&mut p.RCC, RccConfig::default()); | 106 | let p = embassy_stm32::init(config()); |
| 119 | rcc.enable_debug_wfe(&mut p.DBGMCU, true); | ||
| 120 | 107 | ||
| 121 | let rtc_int = interrupt_take!(TIM2); | 108 | let rtc_int = interrupt_take!(TIM2); |
| 122 | let rtc = TIMER_RTC.put(Clock::new(p.TIM2, rtc_int)); | 109 | let rtc = TIMER_RTC.put(Clock::new(p.TIM2, rtc_int)); |
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs index 026960a14..5175538df 100644 --- a/examples/stm32h7/src/bin/spi.rs +++ b/examples/stm32h7/src/bin/spi.rs | |||
| @@ -12,9 +12,7 @@ use embassy::executor::Executor; | |||
| 12 | use embassy::time::Clock; | 12 | use embassy::time::Clock; |
| 13 | use embassy::util::Forever; | 13 | use embassy::util::Forever; |
| 14 | use embassy_stm32::dma::NoDma; | 14 | use embassy_stm32::dma::NoDma; |
| 15 | use embassy_stm32::rcc; | ||
| 16 | use embassy_stm32::spi; | 15 | use embassy_stm32::spi; |
| 17 | use embassy_stm32::Config; | ||
| 18 | use embedded_hal::blocking::spi::Transfer; | 16 | use embedded_hal::blocking::spi::Transfer; |
| 19 | use example_common::*; | 17 | use example_common::*; |
| 20 | 18 | ||
| @@ -58,9 +56,7 @@ fn main() -> ! { | |||
| 58 | Dbgmcu::enable_all(); | 56 | Dbgmcu::enable_all(); |
| 59 | } | 57 | } |
| 60 | 58 | ||
| 61 | let p = embassy_stm32::init( | 59 | let p = embassy_stm32::init(config()); |
| 62 | Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())), | ||
| 63 | ); | ||
| 64 | 60 | ||
| 65 | let spi = spi::Spi::new( | 61 | let spi = spi::Spi::new( |
| 66 | p.SPI3, | 62 | p.SPI3, |
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs index 7750ad192..3b9043bc2 100644 --- a/examples/stm32h7/src/bin/spi_dma.rs +++ b/examples/stm32h7/src/bin/spi_dma.rs | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #[path = "../example_common.rs"] | 7 | #[path = "../example_common.rs"] |
| 8 | mod example_common; | 8 | mod example_common; |
| 9 | |||
| 9 | use core::fmt::Write; | 10 | use core::fmt::Write; |
| 10 | use embassy::executor::Executor; | 11 | use embassy::executor::Executor; |
| 11 | use embassy::time::Clock; | 12 | use embassy::time::Clock; |
| @@ -18,9 +19,7 @@ use core::str::from_utf8; | |||
| 18 | use cortex_m_rt::entry; | 19 | use cortex_m_rt::entry; |
| 19 | use embassy_stm32::dbgmcu::Dbgmcu; | 20 | use embassy_stm32::dbgmcu::Dbgmcu; |
| 20 | use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; | 21 | use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; |
| 21 | use embassy_stm32::rcc; | ||
| 22 | use embassy_stm32::spi; | 22 | use embassy_stm32::spi; |
| 23 | use embassy_stm32::Config; | ||
| 24 | use heapless::String; | 23 | use heapless::String; |
| 25 | 24 | ||
| 26 | #[embassy::task] | 25 | #[embassy::task] |
| @@ -53,9 +52,7 @@ fn main() -> ! { | |||
| 53 | Dbgmcu::enable_all(); | 52 | Dbgmcu::enable_all(); |
| 54 | } | 53 | } |
| 55 | 54 | ||
| 56 | let p = embassy_stm32::init( | 55 | let p = embassy_stm32::init(config()); |
| 57 | Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())), | ||
| 58 | ); | ||
| 59 | 56 | ||
| 60 | let spi = spi::Spi::new( | 57 | let spi = spi::Spi::new( |
| 61 | p.SPI3, | 58 | p.SPI3, |
diff --git a/examples/stm32h7/src/example_common.rs b/examples/stm32h7/src/example_common.rs index 54d633837..2e26730fa 100644 --- a/examples/stm32h7/src/example_common.rs +++ b/examples/stm32h7/src/example_common.rs | |||
| @@ -6,6 +6,8 @@ use panic_probe as _; | |||
| 6 | pub use defmt::*; | 6 | pub use defmt::*; |
| 7 | 7 | ||
| 8 | use core::sync::atomic::{AtomicUsize, Ordering}; | 8 | use core::sync::atomic::{AtomicUsize, Ordering}; |
| 9 | use embassy_stm32::time::U32Ext; | ||
| 10 | use embassy_stm32::Config; | ||
| 9 | 11 | ||
| 10 | defmt::timestamp! {"{=u64}", { | 12 | defmt::timestamp! {"{=u64}", { |
| 11 | static COUNT: AtomicUsize = AtomicUsize::new(0); | 13 | static COUNT: AtomicUsize = AtomicUsize::new(0); |
| @@ -15,3 +17,12 @@ defmt::timestamp! {"{=u64}", { | |||
| 15 | n as u64 | 17 | n as u64 |
| 16 | } | 18 | } |
| 17 | } | 19 | } |
| 20 | |||
| 21 | #[allow(unused)] | ||
| 22 | pub fn config() -> Config { | ||
| 23 | let mut config = Config::default(); | ||
| 24 | config.rcc.sys_ck = Some(400.mhz().into()); | ||
| 25 | config.rcc.pll1.q_ck = Some(100.mhz().into()); | ||
| 26 | config.rcc.enable_dma1 = true; | ||
| 27 | config | ||
| 28 | } | ||
