From aa9baa791b9d8b2b2e6ffb4608f2ab211009bc54 Mon Sep 17 00:00:00 2001 From: shuaihu Date: Thu, 7 Jul 2022 01:53:58 +0000 Subject: [PATCH 1/3] =?UTF-8?q?liteos=20=E4=B8=8B=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=9B=86=E6=88=90=E6=B5=8B=E8=AF=95=EF=BC=8C?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E6=B3=A8=E9=87=8A=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cargo/config.toml | 3 +++ .vscode/settings.json | 3 +++ Cargo.toml | 3 +++ examples/led.rs | 19 +++++++++++++++++++ examples/test_condvar.rs | 11 ++++++++++- examples/test_mutex.rs | 13 +++++++++++++ src/no_std/error.rs | 2 +- src/no_std/io/error.rs | 2 +- src/no_std/thread.rs | 2 +- 9 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 examples/led.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index 055846d..a50fdf1 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 0000000..513cbeb --- /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 01449a6..d8692d0 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 0000000..c6ed68c --- /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 ca45012..33a9a33 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 42dea28..608ac28 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 6672773..f3eb5e6 100644 --- a/src/no_std/error.rs +++ b/src/no_std/error.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#[cfg(all(test,not(liteos)))] mod tests; use alloc::borrow::Cow; diff --git a/src/no_std/io/error.rs b/src/no_std/io/error.rs index 6006dd9..67d50f6 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(liteos)))] mod tests; use core::{ fmt::{Debug, Display}, diff --git a/src/no_std/thread.rs b/src/no_std/thread.rs index 201880e..23f6f58 100644 --- a/src/no_std/thread.rs +++ b/src/no_std/thread.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#[cfg(all(test,not(liteos)))] mod tests; use crate::io::Result; use alloc::{boxed::Box, string::String, sync::Arc}; -- Gitee From 225e71781531c7eaec20021ab9a88455475f0ace Mon Sep 17 00:00:00 2001 From: shuaihu Date: Thu, 7 Jul 2022 01:59:18 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E5=B5=8C=E5=85=A5=E5=BC=8F=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E4=B8=8D=E6=94=AF=E6=8C=81=E9=9B=86=E6=88=90=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/no_std/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/no_std/error.rs b/src/no_std/error.rs index f3eb5e6..13ea387 100644 --- a/src/no_std/error.rs +++ b/src/no_std/error.rs @@ -1,4 +1,4 @@ -#[cfg(all(test,not(liteos)))] +#[cfg(all(test,not(target_os="none")))] mod tests; use alloc::borrow::Cow; -- Gitee From e4a01f2a1bdfdaa3c829760cb0078902ac7c467d Mon Sep 17 00:00:00 2001 From: shuaihu Date: Thu, 7 Jul 2022 01:59:47 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E5=B5=8C=E5=85=A5=E5=BC=8F=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E4=B8=8D=E6=94=AF=E6=8C=81=E9=9B=86=E6=88=90=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/no_std/io/error.rs | 2 +- src/no_std/thread.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/no_std/io/error.rs b/src/no_std/io/error.rs index 67d50f6..297671b 100644 --- a/src/no_std/io/error.rs +++ b/src/no_std/io/error.rs @@ -1,4 +1,4 @@ -#[cfg(all(test,not(liteos)))] +#[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 23f6f58..a06fcd9 100644 --- a/src/no_std/thread.rs +++ b/src/no_std/thread.rs @@ -1,4 +1,4 @@ -#[cfg(all(test,not(liteos)))] +#[cfg(all(test,not(target_os="none")))] mod tests; use crate::io::Result; use alloc::{boxed::Box, string::String, sync::Arc}; -- Gitee