Skip to content

Commit 3396f53

Browse files
committed
test no_std in CI
1 parent acefa1b commit 3396f53

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

.github/workflows/rust.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,21 @@ jobs:
6363
with:
6464
command: clippy
6565
args: -- -D warnings
66+
67+
Embedded:
68+
runs-on: ubuntu-latest
69+
steps:
70+
- name: Checkout
71+
uses: actions/checkout@v2
72+
- name: Checkout Toolchain
73+
uses: actions-rs/toolchain@v1
74+
with:
75+
profile: minimal
76+
toolchain: nightly
77+
override: true
78+
components: rust-src
79+
target: thumbv7m-none-eabi
80+
- name: Build
81+
env:
82+
RUSTFLAGS: "-C link-arg=-Tlink.x"
83+
run: cd embedded && cargo build --target thumbv7m-none-eabi

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
**/target
22
*.o
33
/Cargo.lock
4+
5+
/embedded/Cargo.lock
6+
/embedded/.cargo

embedded/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
authors = ["Riccardo Casatta <[email protected]>"]
3+
edition = "2018"
4+
readme = "README.md"
5+
name = "embedded"
6+
version = "0.1.0"
7+
8+
[dependencies]
9+
cortex-m = "0.6.0"
10+
cortex-m-rt = "0.6.10"
11+
cortex-m-semihosting = "0.3.3"
12+
panic-halt = "0.2.0"
13+
alloc-cortex-m = "0.4.1"
14+
bech32 = { path="../", default-features = false }
15+
16+
[[bin]]
17+
name = "embedded"
18+
test = false
19+
bench = false
20+
21+
[profile.release]
22+
codegen-units = 1 # better optimizations
23+
debug = true # symbols are nice and they don't increase the size on Flash
24+
lto = true # better optimizations

embedded/memory.x

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MEMORY
2+
{
3+
4+
FLASH : ORIGIN = 0x00000000, LENGTH = 256K
5+
RAM : ORIGIN = 0x20000000, LENGTH = 64K
6+
}

embedded/src/main.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#![feature(alloc_error_handler)]
2+
#![no_main]
3+
#![no_std]
4+
5+
extern crate alloc;
6+
use panic_halt as _;
7+
8+
use self::alloc::string::ToString;
9+
use self::alloc::vec;
10+
use self::alloc::vec::Vec;
11+
use core::alloc::Layout;
12+
13+
use alloc_cortex_m::CortexMHeap;
14+
use bech32::{self, FromBase32, ToBase32, Variant};
15+
use cortex_m::asm;
16+
use cortex_m_rt::entry;
17+
use cortex_m_semihosting::{debug, hprintln};
18+
19+
#[global_allocator]
20+
static ALLOCATOR: CortexMHeap = CortexMHeap::empty();
21+
22+
const HEAP_SIZE: usize = 1024; // in bytes
23+
24+
#[entry]
25+
fn main() -> ! {
26+
// Initialize the allocator BEFORE you use it
27+
unsafe { ALLOCATOR.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE) }
28+
29+
let encoded = bech32::encode(
30+
"bech32",
31+
vec![0x00, 0x01, 0x02].to_base32(),
32+
Variant::Bech32,
33+
)
34+
.unwrap();
35+
assert_eq!(encoded, "bech321qqqsyrhqy2a".to_string());
36+
37+
hprintln!("{}", encoded).unwrap();
38+
39+
let (hrp, data, variant) = bech32::decode(&encoded).unwrap();
40+
assert_eq!(hrp, "bech32");
41+
assert_eq!(
42+
Vec::<u8>::from_base32(&data).unwrap(),
43+
vec![0x00, 0x01, 0x02]
44+
);
45+
assert_eq!(variant, Variant::Bech32);
46+
47+
debug::exit(debug::EXIT_SUCCESS);
48+
49+
loop {}
50+
}
51+
52+
// define what happens in an Out Of Memory (OOM) condition
53+
#[alloc_error_handler]
54+
fn alloc_error(_layout: Layout) -> ! {
55+
asm::bkpt();
56+
57+
loop {}
58+
}

0 commit comments

Comments
 (0)