From e55726964d8852a2b1fa0c3d677588f5abf518b0 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 26 Oct 2021 13:45:53 +0200 Subject: Fix clock setup for MSI and PLL to allow RNG opereation Add RNG example using PLL as clock source. --- examples/stm32l4/src/bin/rng.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 examples/stm32l4/src/bin/rng.rs (limited to 'examples') diff --git a/examples/stm32l4/src/bin/rng.rs b/examples/stm32l4/src/bin/rng.rs new file mode 100644 index 000000000..ee5f579f8 --- /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; + } +} -- cgit