Skip to content

Commit f6902b4

Browse files
committed
Added example using rand crate to ensure no_std compatibility
Signed-off-by: Daniel Egger <[email protected]>
1 parent 04ef312 commit f6902b4

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

cortex-m-rt/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ cortex-m = "0.5.4"
1919
panic-abort = "0.3.0"
2020
panic-semihosting = "0.4.0"
2121

22+
[dev-dependencies.rand]
23+
default-features = false
24+
version = "0.5.5"
25+
2226
[target.'cfg(not(target_os = "none"))'.dev-dependencies]
2327
compiletest_rs = "0.3.14"
2428

cortex-m-rt/ci/script.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ main() {
2020
minimal
2121
override-exception
2222
pre_init
23+
rand
2324
state
2425
unsafe-default-handler
25-
unsafe-hard-fault
2626
unsafe-entry
2727
unsafe-exception
28+
unsafe-hard-fault
2829
)
2930
local fail_examples=(
3031
data_overflow

cortex-m-rt/examples/rand.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//! Use rand crate to ensure it's configured for no_std compatbility
2+
3+
#![deny(warnings)]
4+
#![no_main]
5+
#![no_std]
6+
7+
extern crate cortex_m_rt as rt;
8+
use rt::entry;
9+
10+
extern crate panic_semihosting;
11+
12+
extern crate rand;
13+
use rand::Rng;
14+
use rand::SeedableRng;
15+
16+
// the program entry point
17+
#[entry]
18+
fn main() -> ! {
19+
let seed: [u8; 32] = [0; 32];
20+
let mut rng = rand::ChaChaRng::from_seed(seed);
21+
let _ = rng.gen::<u32>();
22+
23+
loop {}
24+
}

0 commit comments

Comments
 (0)