This directory contains a series of example user applications and components that demonstrate Rust programming capabilities in RT-Thread. These examples showcase how to use the Rust programming language for system programming in the RT-Thread real-time operating system.
example_usrapp/
├── SConscript # SCons build script
├── fs/ # File system operation examples
├── loadlib/ # Dynamic library loading examples
├── mutex/ # Mutex synchronization examples
├── param/ # Parameter handling examples
├── queue/ # Message queue examples
├── semaphore/ # Semaphore synchronization examples
└── thread/ # Thread management examples
RT_USING_RUST), and enable examples compilation (RT_USING_RUST_EXAMPLES) and application examples compilation (RT_RUST_BUILD_APPLICATIONS).Execute in the RT-Thread project root directory:
scons -j$(nproc)
The build system will automatically:
After RT-Thread system startup, you can run various examples through the command line:
# View all available examples
help
# Run thread example
rust_thread_demo
# Run file system example
rust_file_demo
# Other examples similarly...
All example applications depend on the following core components:
rt-rust: RT-Thread Rust binding librarymacro_main: Main function macro supportThe fs example also depends on the logging component:
em_component_log: Logging componentexample_usrapp/Cargo.toml configuration filesrc/lib.rs#[macro_main_use] macro to define entry point#![no_std]
use macro_main::macro_main_use;
use rt_rust::param::Param;
use rt_rust::println;
#[macro_main_use(
name = "your_demo_name",
component = "Whether it's a component example",
app = "Whether it's a user application example",
cmd = true,
desc = "Your demo description."
)]
fn main(_param: Param) {
println!("Hello from your demo!");
// Your example code...
}
println! for basic debug output