diff --git a/Cargo.lock b/Cargo.lock
index d8f32d356..e91d8d2ba 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -129,9 +129,9 @@ dependencies = [
[[package]]
name = "anyhow"
-version = "1.0.87"
+version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8"
+checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6"
[[package]]
name = "arrayvec"
@@ -360,9 +360,9 @@ dependencies = [
[[package]]
name = "cc"
-version = "1.1.18"
+version = "1.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476"
+checksum = "2d74707dde2ba56f86ae90effb3b43ddd369504387e718014de010cec7959800"
dependencies = [
"shlex",
]
@@ -3538,9 +3538,9 @@ version = "0.1.1"
[[package]]
name = "redox_syscall"
-version = "0.5.3"
+version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4"
+checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853"
dependencies = [
"bitflags 2.6.0",
]
@@ -3780,6 +3780,7 @@ dependencies = [
"embassy-rp",
"riot-rs-debug",
"riot-rs-embassy-common",
+ "riot-rs-random",
"riot-rs-utils",
"static_cell",
]
@@ -3818,6 +3819,7 @@ dependencies = [
"embassy-stm32",
"portable-atomic",
"riot-rs-embassy-common",
+ "riot-rs-random",
"static_cell",
]
@@ -3940,9 +3942,9 @@ dependencies = [
[[package]]
name = "rustix"
-version = "0.38.36"
+version = "0.38.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36"
+checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811"
dependencies = [
"bitflags 2.6.0",
"errno",
@@ -3959,11 +3961,10 @@ checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
[[package]]
name = "ruzstd"
-version = "0.7.1"
+version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1c8b8f3d26bd9f945e5cbae77f7cdfbf37af9a66956f1115eb4516e45df519f4"
+checksum = "99c3938e133aac070997ddc684d4b393777d293ba170f2988c8fd5ea2ad4ce21"
dependencies = [
- "byteorder",
"twox-hash",
]
@@ -3981,10 +3982,11 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "scroll-ring"
-version = "0.1.1"
+version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5eda0dff67036ba3b032aa68eb47ceb9b53b6e848445f53d10bf93e033b17df2"
+checksum = "827595b27476e68bcbb86dfe8e11f364e4d4efd01cb5f01d845950456006f6ec"
dependencies = [
+ "portable-atomic",
"ringbuf",
"try-lock",
]
diff --git a/Cargo.toml b/Cargo.toml
index 2b1b9e127..392f3db1e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -48,7 +48,7 @@ cortex-m-semihosting = { version = "0.5" }
critical-section = { version = "1.1.2" }
# Disabling default features may reduce the code size by not providing atomics
# for types larger than the pointer width, which we do not use.
-portable-atomic = { version = "1.6.0", default-features = false, features = [
+portable-atomic = { version = "1.7.0", default-features = false, features = [
"require-cas",
] }
@@ -92,7 +92,7 @@ document-features = "0.2.8"
heapless = { version = "0.8.0", default-features = false }
konst = { version = "0.3.8", default-features = false }
ld-memory = { version = "0.2.9" }
-once_cell = { version = "1.19.0", default-features = false, features = [
+once_cell = { version = "=1.19.0", default-features = false, features = [
"critical-section",
] }
paste = { version = "1.0" }
diff --git a/book/src/support_matrix.html b/book/src/support_matrix.html
index f04c8f108..2b2cbf2b9 100644
--- a/book/src/support_matrix.html
+++ b/book/src/support_matrix.html
@@ -4,7 +4,7 @@
Chip |
Testing Board |
- Functionality |
+ Functionality |
|
@@ -15,6 +15,7 @@
User USB |
Wi-Fi |
Ethernet over USB |
+ Hardware Random Number Generator |
@@ -27,6 +28,7 @@
❌ |
☑️ |
❌ |
+ ❌ |
nRF52xxx |
@@ -37,6 +39,7 @@
✅ |
– |
✅ |
+ ✅ |
nRF53xx |
@@ -47,6 +50,7 @@
✅ |
– |
✅ |
+ ✅ |
RP2040 |
@@ -57,6 +61,7 @@
✅ |
– |
✅ |
+ ✅ |
RP2040 |
@@ -67,6 +72,7 @@
✅ |
✅ |
✅ |
+ ✅ |
STM32F401RETX |
@@ -77,6 +83,7 @@
– |
– |
– |
+ – |
STM32F755ZITX |
@@ -87,6 +94,7 @@
✅ |
– |
❌ |
+ ✅ |
STM32W55RGVX |
@@ -97,6 +105,7 @@
✅ |
– |
✅ |
+ ✅ |
diff --git a/doc/support_matrix.yml b/doc/support_matrix.yml
index 11fa0f101..c6acc641e 100644
--- a/doc/support_matrix.yml
+++ b/doc/support_matrix.yml
@@ -35,6 +35,9 @@ functionalities:
- name: ethernet_over_usb
title: Ethernet over USB
description:
+ - name: hwrng
+ title: Hardware Random Number Generator
+ description:
# Encodes support status for each chip.
chips:
@@ -43,6 +46,7 @@ chips:
support:
gpio: supported
debug_output: supported
+ hwrng: supported
logging: supported
wifi: not_available
@@ -51,6 +55,7 @@ chips:
support:
gpio: supported
debug_output: supported
+ hwrng: supported
logging: supported
wifi: not_available
@@ -59,6 +64,7 @@ chips:
support:
gpio: supported
debug_output: supported
+ hwrng: supported
logging: supported
wifi: not_available
@@ -67,6 +73,7 @@ chips:
support:
gpio: supported
debug_output: supported
+ hwrng: not_currently_supported
logging: supported
wifi: not_available
@@ -75,6 +82,7 @@ chips:
support:
gpio: supported
debug_output: supported
+ hwrng: not_available
logging: supported
wifi: not_available
@@ -83,6 +91,7 @@ chips:
support:
gpio: supported
debug_output: supported
+ hwrng: supported
logging: supported
wifi: not_available
@@ -91,6 +100,7 @@ chips:
support:
gpio: supported
debug_output: supported
+ hwrng: supported
logging: supported
wifi: not_available
diff --git a/examples/coap/laze.yml b/examples/coap/laze.yml
index 819ba1772..c90a51c28 100644
--- a/examples/coap/laze.yml
+++ b/examples/coap/laze.yml
@@ -8,3 +8,6 @@ apps:
- ?release
- network
- random
+ conflicts:
+ # see https://github.com/future-proof-iot/RIOT-rs/issues/418
+ - thumbv6m-none-eabi
diff --git a/laze-project.yml b/laze-project.yml
index 5535bd8fe..e32bb8b77 100644
--- a/laze-project.yml
+++ b/laze-project.yml
@@ -602,6 +602,9 @@ modules:
# doesn't have an entry in the cfg(feature = "hwrng") part of init_task
- nrf51
- nrf52
+ - rp
+ - stm32h755zitx
+ - stm32wb55rgvx
env:
global:
FEATURES:
diff --git a/src/riot-rs-boards/st-nucleo-h755zi-q/Cargo.toml b/src/riot-rs-boards/st-nucleo-h755zi-q/Cargo.toml
index 2188a27b0..3a8dedf20 100644
--- a/src/riot-rs-boards/st-nucleo-h755zi-q/Cargo.toml
+++ b/src/riot-rs-boards/st-nucleo-h755zi-q/Cargo.toml
@@ -12,5 +12,8 @@ embassy-stm32 = { workspace = true, features = [
] }
riot-rs-debug = { workspace = true, features = ["rtt-target"] }
riot-rs-rt.workspace = true
-riot-rs-stm32 = { workspace = true, features = ["stm32-usb-synopsis"] }
+riot-rs-stm32 = { workspace = true, features = [
+ "stm32-hash-rng",
+ "stm32-usb-synopsis",
+] }
stm32 = { path = "../../riot-rs-chips/stm32" }
diff --git a/src/riot-rs-boards/st-nucleo-wb55/Cargo.toml b/src/riot-rs-boards/st-nucleo-wb55/Cargo.toml
index a16747c25..6fa2ae22d 100644
--- a/src/riot-rs-boards/st-nucleo-wb55/Cargo.toml
+++ b/src/riot-rs-boards/st-nucleo-wb55/Cargo.toml
@@ -9,5 +9,5 @@ edition = "2021"
[dependencies]
embassy-stm32 = { workspace = true, features = ["stm32wb55rg"] }
riot-rs-debug = { workspace = true, features = ["rtt-target"] }
-riot-rs-stm32 = { workspace = true, features = ["stm32-usb"] }
+riot-rs-stm32 = { workspace = true, features = ["stm32-rng", "stm32-usb"] }
riot-rs-rt.workspace = true
diff --git a/src/riot-rs-embassy/Cargo.toml b/src/riot-rs-embassy/Cargo.toml
index acafe3421..f8e07d403 100644
--- a/src/riot-rs-embassy/Cargo.toml
+++ b/src/riot-rs-embassy/Cargo.toml
@@ -77,7 +77,7 @@ usb = [
net = ["dep:embassy-net", "time"]
usb-ethernet = ["usb", "net"]
## Use a hardware RNG to seed into the riot-rs-random system-wide RNG
-hwrng = ["riot-rs-nrf/hwrng"]
+hwrng = ["riot-rs-nrf/hwrng", "riot-rs-rp/hwrng", "riot-rs-stm32/hwrng"]
wifi = []
wifi-cyw43 = ["riot-rs-rp/wifi-cyw43", "net", "wifi"]
diff --git a/src/riot-rs-rp/Cargo.toml b/src/riot-rs-rp/Cargo.toml
index 62fab0635..dc24f8e0b 100644
--- a/src/riot-rs-rp/Cargo.toml
+++ b/src/riot-rs-rp/Cargo.toml
@@ -19,6 +19,7 @@ embassy-rp = { workspace = true, default-features = false, features = [
] }
riot-rs-debug = { workspace = true }
riot-rs-embassy-common = { workspace = true }
+riot-rs-random = { workspace = true, optional = true }
riot-rs-utils = { workspace = true }
static_cell = { workspace = true, optional = true }
@@ -40,6 +41,9 @@ embassy-rp = { workspace = true, default-features = false, features = [
## Enables GPIO interrupt support.
external-interrupts = ["riot-rs-embassy-common/external-interrupts"]
+## Enables seeding the random number generator from hardware.
+hwrng = ["dep:riot-rs-random"]
+
## Enables USB support.
usb = []
diff --git a/src/riot-rs-rp/src/hwrng.rs b/src/riot-rs-rp/src/hwrng.rs
new file mode 100644
index 000000000..835ad34a5
--- /dev/null
+++ b/src/riot-rs-rp/src/hwrng.rs
@@ -0,0 +1,3 @@
+pub fn construct_rng(_peripherals: &mut crate::OptionalPeripherals) {
+ riot_rs_random::construct_rng(embassy_rp::clocks::RoscRng);
+}
diff --git a/src/riot-rs-rp/src/lib.rs b/src/riot-rs-rp/src/lib.rs
index 2db7dd4fd..97f7385ea 100644
--- a/src/riot-rs-rp/src/lib.rs
+++ b/src/riot-rs-rp/src/lib.rs
@@ -16,6 +16,9 @@ mod wifi;
#[cfg(feature = "wifi-cyw43")]
pub mod cyw43;
+#[cfg(feature = "hwrng")]
+pub mod hwrng;
+
#[cfg(feature = "usb")]
pub mod usb;
diff --git a/src/riot-rs-stm32/Cargo.toml b/src/riot-rs-stm32/Cargo.toml
index 4d06d9e88..cc7d65099 100644
--- a/src/riot-rs-stm32/Cargo.toml
+++ b/src/riot-rs-stm32/Cargo.toml
@@ -15,8 +15,9 @@ embassy-executor = { workspace = true, default-features = false, features = [
"arch-cortex-m",
] }
embassy-stm32 = { workspace = true, default-features = false }
-riot-rs-embassy-common = { workspace = true }
portable-atomic = { workspace = true }
+riot-rs-embassy-common = { workspace = true }
+riot-rs-random = { workspace = true, optional = true }
static_cell = { workspace = true }
[target.'cfg(context = "stm32")'.dependencies]
@@ -33,6 +34,13 @@ external-interrupts = [
"riot-rs-embassy-common/external-interrupts",
]
+## Enables seeding the random number generator from hardware.
+hwrng = ["dep:riot-rs-random"]
+# These are chosen automatically by riot-rs-boards and select the correct stm32
+# rng peripheral support.
+stm32-hash-rng = []
+stm32-rng = []
+
## Enables USB support.
usb = []
# These are chosen automatically by riot-rs-boards and select the correct stm32
diff --git a/src/riot-rs-stm32/src/hwrng.rs b/src/riot-rs-stm32/src/hwrng.rs
new file mode 100644
index 000000000..10a99fdc9
--- /dev/null
+++ b/src/riot-rs-stm32/src/hwrng.rs
@@ -0,0 +1,36 @@
+use embassy_stm32::rng::Rng;
+use embassy_stm32::{bind_interrupts, peripherals, rng};
+
+#[cfg(not(any(feature = "stm32-hash-rng", feature = "stm32-rng")))]
+compile_error!("no stm32 rng feature enabled");
+
+#[cfg(feature = "stm32-hash-rng")]
+bind_interrupts!(struct Irqs {
+ HASH_RNG => rng::InterruptHandler;
+});
+
+#[cfg(feature = "stm32-rng")]
+bind_interrupts!(struct Irqs {
+ RNG => rng::InterruptHandler;
+});
+
+pub fn construct_rng(peripherals: &mut crate::OptionalPeripherals) {
+ cfg_if::cfg_if! {
+ // The union of all contexts that wind up in a construct_rng should be synchronized
+ // with laze-project.yml's hwrng module.
+ if #[cfg(any(context = "stm32"))] {
+ let rng = Rng::new(
+ peripherals
+ .RNG
+ // We don't even have to take it out, just use it to seed the RNG
+ .as_mut()
+ .expect("RNG has not been previously used"),
+ Irqs,
+ );
+
+ riot_rs_random::construct_rng(rng);
+ } else if #[cfg(context = "riot-rs")] {
+ compile_error!("hardware RNG is not supported on this architecture");
+ }
+ }
+}
diff --git a/src/riot-rs-stm32/src/lib.rs b/src/riot-rs-stm32/src/lib.rs
index 1d49c001e..38fdf9e97 100644
--- a/src/riot-rs-stm32/src/lib.rs
+++ b/src/riot-rs-stm32/src/lib.rs
@@ -18,6 +18,9 @@ pub use embassy_stm32::{interrupt, peripherals, OptionalPeripherals, Peripherals
#[cfg(feature = "executor-interrupt")]
pub(crate) use embassy_executor::InterruptExecutor as Executor;
+#[cfg(feature = "hwrng")]
+pub mod hwrng;
+
#[cfg(feature = "usb")]
cfg_if::cfg_if! {
if #[cfg(feature = "stm32-usb")] {