aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32l4/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-10-26 11:59:14 +0000
committerGitHub <[email protected]>2021-10-26 11:59:14 +0000
commit01e5376b2531ccd97ee760ef1dd7c3ec5d82ccfb (patch)
tree452b6c0b0d1a6d940651e4d5ca4c1be925a14687 /examples/stm32l4/src
parentf8bd9d2b1c801236a11261c5fc0a7239ded644e4 (diff)
parente55726964d8852a2b1fa0c3d677588f5abf518b0 (diff)
Merge #456
456: Fix L4 clock setup for MSI and PLL to allow RNG operation r=Dirbaio a=lulf Example is tested on STM32L475VG. Co-authored-by: Ulf Lilleengen <[email protected]>
Diffstat (limited to 'examples/stm32l4/src')
-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}