This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,7 @@ Cargo.lock | |
fuzz/hfuzz_target | ||
fuzz/hfuzz_workspace | ||
|
||
#embedded | ||
embedded/.cargo | ||
|
||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
authors = ["Riccardo Casatta <riccardo@casatta.it>"] | ||
edition = "2018" | ||
readme = "README.md" | ||
name = "embedded" | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
cortex-m = "0.6.0" | ||
cortex-m-rt = "0.6.10" | ||
cortex-m-semihosting = "0.3.3" | ||
panic-halt = "0.2.0" | ||
alloc-cortex-m = "0.4.1" | ||
bitcoin_hashes = { path="../", default-features = false } | ||
|
||
[[bin]] | ||
name = "embedded" | ||
test = false | ||
bench = false | ||
|
||
[profile.release] | ||
codegen-units = 1 # better optimizations | ||
debug = true # symbols are nice and they don't increase the size on Flash | ||
lto = true # better optimizations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
MEMORY | ||
{ | ||
FLASH : ORIGIN = 0x00000000, LENGTH = 256K | ||
RAM : ORIGIN = 0x20000000, LENGTH = 64K | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#![feature(alloc_error_handler)] | ||
#![no_std] | ||
#![no_main] | ||
|
||
#[macro_use] | ||
extern crate bitcoin_hashes; | ||
|
||
extern crate alloc; | ||
|
||
use alloc_cortex_m::CortexMHeap; | ||
use bitcoin_hashes::{sha256, Hash, HashEngine}; | ||
use core::alloc::Layout; | ||
use core::str::FromStr; | ||
use cortex_m::asm; | ||
use cortex_m_rt::entry; | ||
use cortex_m_semihosting::{debug, hprintln}; | ||
use panic_halt as _; | ||
|
||
hash_newtype!(TestType, sha256::Hash, 32, doc = "test"); | ||
|
||
// this is the allocator the application will use | ||
#[global_allocator] | ||
static ALLOCATOR: CortexMHeap = CortexMHeap::empty(); | ||
|
||
const HEAP_SIZE: usize = 1024; // in bytes | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
unsafe { ALLOCATOR.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE) } | ||
|
||
let mut engine = TestType::engine(); | ||
engine.input(b"abc"); | ||
let hash = TestType::from_engine(engine); | ||
|
||
let hash_check = | ||
TestType::from_str("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") | ||
.unwrap(); | ||
hprintln!("hash:{} hash_check:{}", hash, hash_check).unwrap(); | ||
if hash == hash_check { | ||
debug::exit(debug::EXIT_SUCCESS); | ||
} else { | ||
debug::exit(debug::EXIT_FAILURE); | ||
} | ||
|
||
loop {} | ||
} | ||
|
||
// define what happens in an Out Of Memory (OOM) condition | ||
#[alloc_error_handler] | ||
fn alloc_error(_layout: Layout) -> ! { | ||
asm::bkpt(); | ||
|
||
loop {} | ||
} |