summaryrefslogtreecommitdiff
path: root/components/rust/docs/2.applications
diff options
context:
space:
mode:
authorzhang san <[email protected]>2025-12-08 18:34:25 +0800
committerGitHub <[email protected]>2025-12-08 18:34:25 +0800
commit69980f8b9d29b38dbd4ddf6373b4b45f3a138409 (patch)
tree21dd9a8ce80e3d30192e9ffa56ea39a199bae309 /components/rust/docs/2.applications
parentcd1d47b87c5d47e131730e5506eb3ad77d357653 (diff)
Adding Rust Language Support for RT-Thread #10910
Diffstat (limited to 'components/rust/docs/2.applications')
-rw-r--r--components/rust/docs/2.applications/application.md123
-rw-r--r--components/rust/docs/2.applications/application_cn.md123
2 files changed, 246 insertions, 0 deletions
diff --git a/components/rust/docs/2.applications/application.md b/components/rust/docs/2.applications/application.md
new file mode 100644
index 0000000000..f393bf1e20
--- /dev/null
+++ b/components/rust/docs/2.applications/application.md
@@ -0,0 +1,123 @@
+# 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
+
+1. 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`).
+2. Install Rust toolchain and related dependencies
+3. Configure the correct cross-compilation environment
+
+### Build Steps
+
+1. Execute in the RT-Thread project root directory:
+ ```bash
+ scons -j$(nproc)
+ ```
+
+2. 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:
+
+```bash
+# 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 library
+- `macro_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
+
+1. Create a new directory under `example_usrapp/`
+2. Add `Cargo.toml` configuration file
+3. Implement example code in `src/lib.rs`
+4. Use `#[macro_main_use]` macro to define entry point
+
+### Example Template
+
+```rust
+#![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
+
+1. **Compilation failure**: Check if Rust toolchain is correctly installed
+2. **Linking errors**: Confirm cross-compilation target configuration is correct
+3. **Runtime errors**: Check stack size and memory configuration
+
+### Debugging Suggestions
+
+1. Use `println!` for basic debug output
+2. Enable logging features to get detailed information
+3. Check if RT-Thread configuration items are correctly enabled \ No newline at end of file
diff --git a/components/rust/docs/2.applications/application_cn.md b/components/rust/docs/2.applications/application_cn.md
new file mode 100644
index 0000000000..d2f1568fb3
--- /dev/null
+++ b/components/rust/docs/2.applications/application_cn.md
@@ -0,0 +1,123 @@
+# RT-Thread Rust 示例用户应用程序
+
+这个目录包含了一系列用于演示 RT-Thread 中 Rust 编程功能的示例用户应用程序和组件。这些示例展示了如何在 RT-Thread 实时操作系统中使用 Rust 语言进行系统编程。
+
+## 目录结构
+
+```
+example_usrapp/
+├── SConscript # SCons 构建脚本
+├── fs/ # 文件系统操作示例
+├── loadlib/ # 动态库加载示例
+├── mutex/ # 互斥锁同步示例
+├── param/ # 参数处理示例
+├── queue/ # 消息队列示例
+├── semaphore/ # 信号量同步示例
+└── thread/ # 线程管理示例
+```
+
+## 构建和运行
+
+### 前提条件
+
+1. 确保 RT-Thread 配置中启用了 Rust 支持 (`RT_USING_RUST`),并且开启 examples 编译(`RT_USING_RUST_EXAMPLES`)中的应用(`RT_RUST_BUILD_APPLICATIONS`)
+2. 安装 Rust 工具链和相关依赖
+3. 配置正确的交叉编译环境
+
+### 构建步骤
+
+1. 在 RT-Thread 项目根目录执行:
+ ```bash
+ scons -j$(nproc)
+ ```
+
+2. 构建系统会自动:
+ - 检测启用的 RT-Thread 配置
+ - 根据配置启用相应的 Rust 特性
+ - 编译所有示例应用为静态库
+ - 链接到最终的固件镜像
+
+### 运行示例
+
+在 RT-Thread 系统启动后,可以通过命令行运行各个示例:
+
+```bash
+# 查看所有可用示例
+help
+
+# 运行线程示例
+rust_thread_demo
+
+# 运行文件系统示例
+rust_file_demo
+
+# 其他示例类似...
+```
+
+## 技术特性
+
+### 依赖管理
+
+所有示例应用都依赖以下核心组件:
+- `rt-rust`: RT-Thread Rust 绑定库
+- `rt-macro`: 主函数宏支持
+
+`fs`示例还依赖日志组件:
+- `em_component_log`: 日志组件
+
+### 特性配置
+
+- 支持条件编译特性
+- 自动特性检测和启用
+- 模块化的功能配置
+
+### 构建系统集成
+
+- 与 SCons 构建系统完全集成
+- 支持清理和增量构建
+- 自动依赖管理
+
+## 开发指南
+
+### 添加新示例
+
+1. 在 `example_usrapp/` 下创建新目录
+2. 添加 `Cargo.toml` 配置文件
+3. 在 `src/lib.rs` 中实现示例代码
+4. 使用 `#[macro_main_use]` 宏定义入口点
+
+### 示例模板
+
+```rust
+#![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 = "是否为组件示例",
+ app = "是否为用户应用示例",
+ cmd = true,
+ desc = "Your demo description."
+)]
+fn main(_param: Param) {
+ println!("Hello from your demo!");
+ // 你的示例代码...
+}
+```
+
+## 故障排除
+
+### 常见问题
+
+1. **编译失败**: 检查 Rust 工具链是否正确安装
+2. **链接错误**: 确认交叉编译目标配置正确
+3. **运行时错误**: 检查栈大小和内存配置
+
+### 调试建议
+
+1. 使用 `println!` 进行基本调试输出
+2. 启用日志特性获取详细信息
+3. 检查 RT-Thread 配置项是否正确启用