diff options
author | Ulf Lilleengen <lulf@redhat.com> | 2021-10-26 13:45:53 +0200 |
---|---|---|
committer | Ulf Lilleengen <lulf@redhat.com> | 2021-10-26 13:45:53 +0200 |
commit | e55726964d8852a2b1fa0c3d677588f5abf518b0 (patch) | |
tree | a9317f5c9cdf415c3024e92f1d3900b6626e48a2 /examples/stm32l4 | |
parent | 7729091b3959896fcf38727cd492c0ff13f02b68 (diff) | |
download | embassy-e55726964d8852a2b1fa0c3d677588f5abf518b0.zip |
Fix clock setup for MSI and PLL to allow RNG opereation
Add RNG example using PLL as clock source.
Diffstat (limited to 'examples/stm32l4')
-rw-r--r-- | examples/stm32l4/src/bin/rng.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/stm32l4/src/bin/rng.rs b/examples/stm32l4/src/bin/rng.rs new file mode 100644 index 00000000..ee5f579f --- /dev/null +++ b/examples/stm32l4/src/bin/rng.rs @@ -0,0 +1,37 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[path = "../example_common.rs"] +mod example_common; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy::traits::rng::Random; +use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; +use embassy_stm32::rng::Rng; +use embassy_stm32::{Config, Peripherals}; +use example_common::*; + +fn config() -> Config { + let mut config = Config::default(); + config.rcc = config.rcc.clock_src(ClockSrc::PLL( + PLLSource::HSI16, + PLLClkDiv::Div2, + PLLSrcDiv::Div1, + PLLMul::Mul8, + Some(PLLClkDiv::Div2), + )); + config +} + +#[embassy::main(config = "config()")] +async fn main(_spawner: Spawner, p: Peripherals) { + info!("Hello World!"); + + let mut rng = Random::new(Rng::new(p.RNG)); + + loop { + info!("random {}", unwrap!(rng.next_u8(16).await)); + Timer::after(Duration::from_secs(1)).await; + } +} |