mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-08 20:05:29 +08:00
Some checks failed
ToolsCI / Tools (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
Weekly CI Scheduler / Trigger and Monitor CIs (push) Has been cancelled
Weekly CI Scheduler / Create Discussion Report (push) Has been cancelled
3.5 KiB
3.5 KiB
RT-Thread Rust Example User Applications
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.
Directory Structure
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
Build and Run
Prerequisites
- Ensure Rust support is enabled in RT-Thread configuration (
RT_USING_RUST), and enable examples compilation (RT_USING_RUST_EXAMPLES) and application examples compilation (RT_RUST_BUILD_APPLICATIONS). - Install Rust toolchain and related dependencies
- Configure the correct cross-compilation environment
Build Steps
-
Execute in the RT-Thread project root directory:
scons -j$(nproc) -
The build system will automatically:
- Detect enabled RT-Thread configurations
- Enable corresponding Rust features based on configuration
- Compile all example applications as static libraries
- Link to the final firmware image
Running Examples
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...
Technical Features
Dependency Management
All example applications depend on the following core components:
rt-rust: RT-Thread Rust binding librarymacro_main: Main function macro support
The fs example also depends on the logging component:
em_component_log: Logging component
Feature Configuration
- Support for conditional compilation features
- Automatic feature detection and enabling
- Modular functionality configuration
Build System Integration
- Fully integrated with SCons build system
- Support for clean and incremental builds
- Automatic dependency management
Development Guide
Adding New Examples
- Create a new directory under
example_usrapp/ - Add
Cargo.tomlconfiguration file - Implement example code in
src/lib.rs - Use
#[macro_main_use]macro to define entry point
Example Template
#![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...
}
Troubleshooting
Common Issues
- Compilation failure: Check if Rust toolchain is correctly installed
- Linking errors: Confirm cross-compilation target configuration is correct
- Runtime errors: Check stack size and memory configuration
Debugging Suggestions
- Use
println!for basic debug output - Enable logging features to get detailed information
- Check if RT-Thread configuration items are correctly enabled