From 0d80be617c2cccc69216eeb286bd6f6e330b98e4 Mon Sep 17 00:00:00 2001 From: wcampbell Date: Tue, 8 Aug 2023 22:02:55 -0400 Subject: [PATCH] Change ensure_no_std to just build and thumbv7em-none-eabihf --- .github/workflows/main.yml | 3 ++- ensure_no_std/Cargo.toml | 3 ++- ensure_no_std/src/bin/main.rs | 40 +++++++++++++++++++++-------------- src/impls/primitive.rs | 2 ++ src/impls/slice.rs | 4 ++-- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ffb741f9..10ee0756 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -112,7 +112,8 @@ jobs: with: toolchain: nightly override: true - - run: cd ensure_no_std && cargo run --release + target: thumbv7em-none-eabihf + - run: cd ensure_no_std && cargo build --release --target thumbv7em-none-eabihf ensure_wasm: name: Ensure wasm diff --git a/ensure_no_std/Cargo.toml b/ensure_no_std/Cargo.toml index 5b9f659a..f3799d4a 100644 --- a/ensure_no_std/Cargo.toml +++ b/ensure_no_std/Cargo.toml @@ -19,6 +19,7 @@ default = ["alloc"] alloc = [] [dependencies] -wee_alloc = "0.4" +cortex-m-rt = "0.7.3" deku = { path = "../", default-features = false, features = ["alloc"] } +embedded-alloc = "0.5.0" diff --git a/ensure_no_std/src/bin/main.rs b/ensure_no_std/src/bin/main.rs index a64da7c8..954ddf17 100644 --- a/ensure_no_std/src/bin/main.rs +++ b/ensure_no_std/src/bin/main.rs @@ -1,25 +1,16 @@ -//! Based on https://github.com/rustwasm/wee_alloc/tree/master/example -//! Run with `cargo +nightly run --release` - +//! cargo build --target thumbv7em-none-eabihf #![no_std] #![no_main] -#![feature(core_intrinsics, alloc_error_handler)] extern crate alloc; -extern crate wee_alloc; -#[no_mangle] -pub extern "C" fn _start() -> ! { - loop {} -} +use core::panic::PanicInfo; -#[panic_handler] -fn panic(_info: &core::panic::PanicInfo) -> ! { - loop {} -} +use cortex_m_rt::entry; +use embedded_alloc::Heap; #[global_allocator] -static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; +static HEAP: Heap = Heap::empty(); use alloc::{format, vec, vec::Vec}; use deku::prelude::*; @@ -35,8 +26,18 @@ struct DekuTest { data: Vec, } -#[no_mangle] -pub extern "C" fn main() -> () { +#[entry] +fn main() -> ! { + // Initialize the allocator BEFORE you use it + { + use core::mem::MaybeUninit; + const HEAP_SIZE: usize = 1024; + static mut HEAP_MEM: [MaybeUninit; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE]; + unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) } + } + + // now the allocator is ready types like Box, Vec can be used. + let test_data: Vec = vec![0b10101_101, 0x02, 0xBE, 0xEF]; // Test reading @@ -54,4 +55,11 @@ pub extern "C" fn main() -> () { // Test writing let val = val.to_bytes().unwrap(); assert_eq!(test_data, val); + + loop { /* .. */ } +} + +#[panic_handler] +fn panic(_: &PanicInfo) -> ! { + loop {} } diff --git a/src/impls/primitive.rs b/src/impls/primitive.rs index 64927b32..dced374d 100644 --- a/src/impls/primitive.rs +++ b/src/impls/primitive.rs @@ -1,5 +1,7 @@ #[cfg(feature = "alloc")] use alloc::format; +#[cfg(feature = "alloc")] +use alloc::string::ToString; use core::convert::TryInto; use acid_io::Read; diff --git a/src/impls/slice.rs b/src/impls/slice.rs index 4587afc8..c31631c2 100644 --- a/src/impls/slice.rs +++ b/src/impls/slice.rs @@ -1,12 +1,12 @@ //! Implementations of DekuRead and DekuWrite for [T; N] where 0 < N <= 32 -use bitvec::prelude::*; pub use deku_derive::*; -use crate::{DekuError, DekuRead, DekuWrite}; #[cfg(feature = "const_generics")] mod const_generics_impl { + use bitvec::prelude::*; + use crate::{DekuError, DekuRead, DekuWrite}; use core::mem::MaybeUninit; use std::io::Read;