aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2021-10-26 13:45:53 +0200
committerUlf Lilleengen <[email protected]>2021-10-26 13:45:53 +0200
commite55726964d8852a2b1fa0c3d677588f5abf518b0 (patch)
treea9317f5c9cdf415c3024e92f1d3900b6626e48a2 /examples
parent7729091b3959896fcf38727cd492c0ff13f02b68 (diff)
Fix clock setup for MSI and PLL to allow RNG opereation
Add RNG example using PLL as clock source.
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32l4/src/bin/rng.rs37
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 000000000..ee5f579f8
--- /dev/null
+++ b/examples/stm32l4/src/bin/rng.rs
@@ -0,0 +1,37 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[path = "../example_common.rs"]
6mod example_common;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy::traits::rng::Random;
10use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv};
11use embassy_stm32::rng::Rng;
12use embassy_stm32::{Config, Peripherals};
13use example_common::*;
14
15fn config() -> Config {
16 let mut config = Config::default();
17 config.rcc = config.rcc.clock_src(ClockSrc::PLL(
18 PLLSource::HSI16,
19 PLLClkDiv::Div2,
20 PLLSrcDiv::Div1,
21 PLLMul::Mul8,
22 Some(PLLClkDiv::Div2),
23 ));
24 config
25}
26
27#[embassy::main(config = "config()")]
28async fn main(_spawner: Spawner, p: Peripherals) {
29 info!("Hello World!");
30
31 let mut rng = Random::new(Rng::new(p.RNG));
32
33 loop {
34 info!("random {}", unwrap!(rng.next_u8(16).await));
35 Timer::after(Duration::from_secs(1)).await;
36 }
37}