aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-10-16 04:54:48 +0200
committerDario Nieuwenhuis <[email protected]>2023-10-16 05:35:29 +0200
commitaff77d2b65952368ea464f1b6950896afa093677 (patch)
tree4ff245fbb7695669cb5a6bd4e948d613ddd17098 /tests
parenta7c6999670dd477914b0b83e2dc32ae2bf4701be (diff)
stm32/rng: add test.
Diffstat (limited to 'tests')
-rw-r--r--tests/stm32/Cargo.toml42
-rw-r--r--tests/stm32/src/bin/rng.rs50
2 files changed, 74 insertions, 18 deletions
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml
index fd18cd77c..9adff596d 100644
--- a/tests/stm32/Cargo.toml
+++ b/tests/stm32/Cargo.toml
@@ -6,26 +6,27 @@ license = "MIT OR Apache-2.0"
6autobins = false 6autobins = false
7 7
8[features] 8[features]
9stm32f103c8 = ["embassy-stm32/stm32f103c8", "not-gpdma"] # Blue Pill 9stm32f103c8 = ["embassy-stm32/stm32f103c8", "not-gpdma"]
10stm32f429zi = ["embassy-stm32/stm32f429zi", "chrono", "eth", "stop", "can", "not-gpdma", "dac-adc-pin"] # Nucleo "sdmmc" 10stm32f429zi = ["embassy-stm32/stm32f429zi", "chrono", "eth", "stop", "can", "not-gpdma", "dac-adc-pin", "rng"]
11stm32g071rb = ["embassy-stm32/stm32g071rb", "not-gpdma", "dac-adc-pin"] # Nucleo 11stm32g071rb = ["embassy-stm32/stm32g071rb", "not-gpdma", "dac-adc-pin"]
12stm32c031c6 = ["embassy-stm32/stm32c031c6", "not-gpdma"] # Nucleo 12stm32c031c6 = ["embassy-stm32/stm32c031c6", "not-gpdma"]
13stm32g491re = ["embassy-stm32/stm32g491re", "chrono", "not-gpdma"] # Nucleo 13stm32g491re = ["embassy-stm32/stm32g491re", "chrono", "not-gpdma", "rng"]
14stm32h755zi = ["embassy-stm32/stm32h755zi-cm7", "chrono", "not-gpdma", "eth", "dac-adc-pin"] # Nucleo 14stm32h755zi = ["embassy-stm32/stm32h755zi-cm7", "chrono", "not-gpdma", "eth", "dac-adc-pin", "rng"]
15stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" ] # Nucleo 15stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng"]
16stm32h563zi = ["embassy-stm32/stm32h563zi", "chrono", "eth"] # Nucleo 16stm32h563zi = ["embassy-stm32/stm32h563zi", "chrono", "eth", "rng"]
17stm32u585ai = ["embassy-stm32/stm32u585ai", "chrono"] # IoT board 17stm32u585ai = ["embassy-stm32/stm32u585ai", "chrono", "rng"]
18stm32l073rz = ["embassy-stm32/stm32l073rz", "not-gpdma"] # Nucleo 18stm32l073rz = ["embassy-stm32/stm32l073rz", "not-gpdma", "rng"]
19stm32l152re = ["embassy-stm32/stm32l152re", "chrono", "not-gpdma"] # Nucleo 19stm32l152re = ["embassy-stm32/stm32l152re", "chrono", "not-gpdma"]
20stm32l4a6zg = ["embassy-stm32/stm32l4a6zg", "chrono", "not-gpdma"] # Nucleo 20stm32l4a6zg = ["embassy-stm32/stm32l4a6zg", "chrono", "not-gpdma", "rng"]
21stm32l4r5zi = ["embassy-stm32/stm32l4r5zi", "chrono", "not-gpdma"] # Nucleo 21stm32l4r5zi = ["embassy-stm32/stm32l4r5zi", "chrono", "not-gpdma", "rng"]
22stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma"] # Nucleo 22stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng"]
23stm32f767zi = ["embassy-stm32/stm32f767zi", "chrono", "not-gpdma", "eth"] # Nucleo 23stm32f767zi = ["embassy-stm32/stm32f767zi", "chrono", "not-gpdma", "eth", "rng"]
24stm32f207zg = ["embassy-stm32/stm32f207zg", "chrono", "not-gpdma", "eth"] # Nucleo 24stm32f207zg = ["embassy-stm32/stm32f207zg", "chrono", "not-gpdma", "eth", "rng"]
25stm32f303ze = ["embassy-stm32/stm32f303ze", "chrono", "not-gpdma"] # Nucleo 25stm32f303ze = ["embassy-stm32/stm32f303ze", "chrono", "not-gpdma"]
26stm32l496zg = ["embassy-stm32/stm32l496zg", "not-gpdma"] # Nucleo 26stm32l496zg = ["embassy-stm32/stm32l496zg", "not-gpdma", "rng"]
27 27
28eth = [] 28eth = []
29rng = []
29sdmmc = [] 30sdmmc = []
30stop = ["embassy-stm32/low-power"] 31stop = ["embassy-stm32/low-power"]
31chrono = ["embassy-stm32/chrono", "dep:chrono"] 32chrono = ["embassy-stm32/chrono", "dep:chrono"]
@@ -87,6 +88,11 @@ path = "src/bin/gpio.rs"
87required-features = [] 88required-features = []
88 89
89[[bin]] 90[[bin]]
91name = "rng"
92path = "src/bin/rng.rs"
93required-features = [ "rng",]
94
95[[bin]]
90name = "rtc" 96name = "rtc"
91path = "src/bin/rtc.rs" 97path = "src/bin/rtc.rs"
92required-features = [ "chrono",] 98required-features = [ "chrono",]
diff --git a/tests/stm32/src/bin/rng.rs b/tests/stm32/src/bin/rng.rs
new file mode 100644
index 000000000..65da737d0
--- /dev/null
+++ b/tests/stm32/src/bin/rng.rs
@@ -0,0 +1,50 @@
1// required-features: rng
2#![no_std]
3#![no_main]
4#![feature(type_alias_impl_trait)]
5
6#[path = "../common.rs"]
7mod common;
8use common::*;
9use embassy_executor::Spawner;
10use embassy_stm32::rng::Rng;
11use embassy_stm32::{bind_interrupts, peripherals, rng};
12use {defmt_rtt as _, panic_probe as _};
13
14#[cfg(any(feature = "stm32l4a6zg", feature = "stm32h755zi", feature = "stm32f429zi"))]
15bind_interrupts!(struct Irqs {
16 HASH_RNG => rng::InterruptHandler<peripherals::RNG>;
17});
18#[cfg(any(feature = "stm32l073rz"))]
19bind_interrupts!(struct Irqs {
20 RNG_LPUART1 => rng::InterruptHandler<peripherals::RNG>;
21});
22#[cfg(not(any(
23 feature = "stm32l4a6zg",
24 feature = "stm32l073rz",
25 feature = "stm32h755zi",
26 feature = "stm32f429zi"
27)))]
28bind_interrupts!(struct Irqs {
29 RNG => rng::InterruptHandler<peripherals::RNG>;
30});
31
32#[embassy_executor::main]
33async fn main(_spawner: Spawner) {
34 let p: embassy_stm32::Peripherals = embassy_stm32::init(config());
35
36 let mut rng = Rng::new(p.RNG, Irqs);
37
38 let mut buf1 = [0u8; 16];
39 unwrap!(rng.async_fill_bytes(&mut buf1).await);
40 info!("random bytes: {:02x}", buf1);
41
42 let mut buf2 = [0u8; 16];
43 unwrap!(rng.async_fill_bytes(&mut buf2).await);
44 info!("random bytes: {:02x}", buf2);
45
46 defmt::assert!(buf1 != buf2);
47
48 info!("Test OK");
49 cortex_m::asm::bkpt();
50}