diff --git a/.cargo/config.toml b/.cargo/config.toml index 055846d07c67d56433cbe56dd3079a2d2a4d808a..a50fdf1a7952230fbf22384cc06ba60456172079 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -58,3 +58,6 @@ rustflags = [ "--cfg", 'LOS_PATH="../../stm32/LiteOS"', ] + +[build] +target="thumbv7m-none-eabi" \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..513cbeb9d40d194855d83ea90af0123f31f55eba --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.checkOnSave.allTargets": false +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 01449a66285194f098432b389111bb48f3723081..d8692d0ddce07498bd2858edffc327fa4856120e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,9 @@ windows-sys = { version = "0.36.1", features = [ "Win32_System_SystemServices", ] } +[[example]] +name="led" +crate-type=["staticlib"] [profile.dev] panic = "abort" diff --git a/examples/led.rs b/examples/led.rs new file mode 100644 index 0000000000000000000000000000000000000000..c6ed68c5a7ed7038004b9fc57062547e8f9eaf58 --- /dev/null +++ b/examples/led.rs @@ -0,0 +1,19 @@ +#![no_std] + +use stdlib::thread::{self}; + +extern "C" { + fn led_toggle(); +} +#[no_mangle] +extern "C" fn app_init() { + loop { + unsafe { led_toggle() }; + thread::sleep(1000); + } +} +#[cfg(not(test))] +#[panic_handler] +pub fn painc_handler(_info: &core::panic::PanicInfo<'_>) -> ! { + loop {} +} diff --git a/examples/test_condvar.rs b/examples/test_condvar.rs index ca45012460e0596bf343956838be7895663dd817..33a9a33ec20bfd411fc78b742ea2d81f041bb159 100644 --- a/examples/test_condvar.rs +++ b/examples/test_condvar.rs @@ -1,9 +1,18 @@ +#![cfg_attr(liteos, no_std)] + +extern crate alloc; +use alloc::string::ToString; + +#[no_mangle] +extern "C" fn app_init() { + main(); +} fn main() { use stdlib::thread::{self, *}; sleep(100); let a = Builder::new() - .name("asdf".to_owned()) + .name("asdf".to_string()) .stack_size(1024) .spawn(|| { thread::yield_now(); diff --git a/examples/test_mutex.rs b/examples/test_mutex.rs index 42dea28d80fc334599de92b662721589cdf0ae0c..608ac2803099a3368d67be90b7c5c400ff210b9e 100644 --- a/examples/test_mutex.rs +++ b/examples/test_mutex.rs @@ -1,3 +1,13 @@ +#![cfg_attr(liteos, no_std)] + +extern crate alloc; + +#[no_mangle] +extern "C" fn app_init() { + main(); +} + +#[cfg(not(liteos))] fn main() { use stdlib::sync::Mutex; let mut mt = Mutex::new(0); @@ -16,3 +26,6 @@ fn main() { let v = mt.into_inner(); assert_eq!(v, 45); } + +#[cfg(liteos)] +fn main() {} diff --git a/src/no_std/error.rs b/src/no_std/error.rs index 66727739e5452a7a51bd499d24b8aa6de7274176..13ea387883428774ac8e3281203b3224cf7e5ed2 100644 --- a/src/no_std/error.rs +++ b/src/no_std/error.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#[cfg(all(test,not(target_os="none")))] mod tests; use alloc::borrow::Cow; diff --git a/src/no_std/io/error.rs b/src/no_std/io/error.rs index 6006dd90b1f67540917b73dccef8b0695440c395..297671b59849824baeea64cd80d10f7e8ccd9025 100644 --- a/src/no_std/io/error.rs +++ b/src/no_std/io/error.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#[cfg(all(test,not(target_os="none")))] mod tests; use core::{ fmt::{Debug, Display}, diff --git a/src/no_std/thread.rs b/src/no_std/thread.rs index 201880e768485680d1248e1fd13b27e85df32750..a06fcd9e995a24da91f9c32982a5ab27e6203b71 100644 --- a/src/no_std/thread.rs +++ b/src/no_std/thread.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#[cfg(all(test,not(target_os="none")))] mod tests; use crate::io::Result; use alloc::{boxed::Box, string::String, sync::Arc};