Skip to content

Commit f448421

Browse files
committed
docs: 更新 message/topic 线程安全说明,补充 STM32 工具链切换文档
1 parent b6a5d63 commit f448421

File tree

4 files changed

+79
-20
lines changed

4 files changed

+79
-20
lines changed

docs/basic_coding/middleware/message.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LibXR 中的 `Message` 模块是一个基于 **发布-订阅(Publish-Subscribe
3030

3131
```cpp
3232
auto domain = LibXR::Topic::Domain("sensor_data");
33-
auto topic = LibXR::Topic::CreateTopic<float>("temperature", &domain, true);
33+
auto topic = LibXR::Topic::CreateTopic<float>("temperature", &domain);
3434

3535
float temp = 23.5f;
3636
topic.Publish(temp);
@@ -81,6 +81,20 @@ auto cb = LibXR::Topic::Callback::Create(
8181
topic.RegisterCallback(cb);
8282
```
8383

84+
## 线程安全
85+
86+
topic在构造时有`bool multi_publisher_ = false;`参数,默认为false,即只允许同时有一个线程/中断发布数据。当设置为true时,使用`mutex_`进行线程同步,允许多个线程同时发布数据,但无法在中断使用。
87+
88+
```cpp
89+
Topic(const char *name, uint32_t max_length, Domain *domain = nullptr,
90+
bool multi_publisher = false, bool cache = false, bool check_length = false);
91+
92+
template <typename Data>
93+
Topic CreateTopic(const char *name, Domain *domain = nullptr,
94+
bool multi_publisher = false, bool cache = false,
95+
bool check_length = true);
96+
```
97+
8498
---
8599
86100
## 类接口概览

docs/code_gen/stm32/README.md

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,26 @@ int main() {
162162

163163
## 可选参数
164164

165-
| 参数 | 说明 |
166-
| ---------- | ----------------------------- |
167-
| `-d` | 指定 STM32 工程根目录 |
168-
| `-t` | 设置终端外设(如 `usart1`|
169-
| `-c` | 启用 Clang 构建支持(已弃用) |
170-
| `--xrobot` | 生成 XRobot 模块 glue 代码 |
165+
| 参数 | 说明 |
166+
| ---------- | --------------------------- |
167+
| `-d` | 指定 STM32 工程根目录 |
168+
| `-t` | 设置终端外设(如 `usart1`|
169+
| `--xrobot` | 生成 XRobot 模块 glue 代码 |
170+
171+
---
172+
173+
## 工具链切换
174+
175+
如需切换 GCC/Clang编译器 或更改 Clang 标准库,请使用如下命令:
176+
177+
```bash
178+
xr_stm32_toolchain_switch gcc
179+
xr_stm32_toolchain_switch clang -g
180+
xr_stm32_toolchain_switch clang --newlib
181+
xr_stm32_toolchain_switch clang --picolibc
182+
```
183+
184+
执行命令会自动修改 CMakePresets.json 和 cmake/starm-clang.cmake,重启 VSCode 即可生效。
171185

172186
---
173187

@@ -187,12 +201,13 @@ int main() {
187201

188202
## 相关命令(由 `xr_cubemx_cfg` 内部调用,可单独执行)
189203

190-
| 工具名 | 功能说明 |
191-
| ------------------- | ------------------------------------ |
192-
| `xr_parse_ioc` | 解析 `.ioc`,生成 `.config.yaml` |
193-
| `xr_gen_code_stm32` | 根据 YAML 配置生成 `app_main.cpp` |
194-
| `xr_stm32_it` | 补丁中断文件,插入 UART/USB 回调支持 |
195-
| `xr_stm32_cmake` | 修改 CMake 构建文件,集成 LibXR |
204+
| 工具名 | 功能说明 |
205+
| --------------------------- | ------------------------------------ |
206+
| `xr_parse_ioc` | 解析 `.ioc`,生成 `.config.yaml` |
207+
| `xr_gen_code_stm32` | 根据 YAML 配置生成 `app_main.cpp` |
208+
| `xr_stm32_it` | 补丁中断文件,插入 UART/USB 回调支持 |
209+
| `xr_stm32_cmake` | 修改 CMake 构建文件,集成 LibXR |
210+
| `xr_stm32_toolchain_switch` | 切换工具链和标准库 |
196211

197212
## 参考
198213

i18n/en/docusaurus-plugin-content-docs/current/basic_coding/middleware/message.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ auto cb = LibXR::Topic::Callback::Create(
8181
topic.RegisterCallback(cb);
8282
```
8383

84+
## Thread Safety
85+
86+
The `topic` class has a constructor parameter `bool multi_publisher_ = false;`, which is `false` by default. This means only one thread or interrupt is allowed to publish data at any given time.
87+
When set to `true`, a `mutex_` is used for thread synchronization, allowing multiple threads to publish data concurrently. However, in this mode, publishing from interrupts is **not supported**.
88+
89+
```cpp
90+
Topic(const char *name, uint32_t max_length, Domain *domain = nullptr,
91+
bool multi_publisher = false, bool cache = false, bool check_length = false);
92+
93+
template <typename Data>
94+
Topic CreateTopic(const char *name, Domain *domain = nullptr,
95+
bool multi_publisher = false, bool cache = false,
96+
bool check_length = true);
97+
```
98+
8499
---
85100
86101
## Interface Overview

i18n/en/docusaurus-plugin-content-docs/current/code_gen/stm32/README.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,25 @@ Make sure to adjust the initial thread stack size in STM32CubeMX to avoid stack
174174
| ---------- | --------------------------------------- |
175175
| `-d` | Specify STM32 project root directory |
176176
| `-t` | Set terminal peripheral (e.g. `usart1`) |
177-
| `-c` | Enable Clang build support (Deprecated) |
178177
| `--xrobot` | Generate glue code for XRobot modules |
179178

180179
---
181180

181+
## Toolchain Switch
182+
183+
If you need to switch between GCC/Clang compilers or change the Clang standard library, use the following commands:
184+
185+
```bash
186+
xr_stm32_toolchain_switch gcc
187+
xr_stm32_toolchain_switch clang -g
188+
xr_stm32_toolchain_switch clang --newlib
189+
xr_stm32_toolchain_switch clang --picolibc
190+
```
191+
192+
Command execution will automatically modify CMakePresets.json and cmake/starm-clang.cmake, restart VSCode to take effect.
193+
194+
---
195+
182196
## Project Requirements
183197

184198
- Must be a CMake project exported from STM32CubeMX
@@ -195,12 +209,13 @@ By default, the generated CMake configuration applies the `-O2` optimization opt
195209

196210
## Subcommands (Internally used by `xr_cubemx_cfg`, can also be run separately)
197211

198-
| Tool | Description |
199-
| ------------------- | ------------------------------------------------ |
200-
| `xr_parse_ioc` | Parses `.ioc` and generates `.config.yaml` |
201-
| `xr_gen_code_stm32` | Generates `app_main.cpp` from the YAML config |
202-
| `xr_stm32_it` | Patches interrupt handlers with UART/USB support |
203-
| `xr_stm32_cmake` | Integrates LibXR into the project build system |
212+
| Tool | Description |
213+
| --------------------------- | ------------------------------------------------ |
214+
| `xr_parse_ioc` | Parses `.ioc` and generates `.config.yaml` |
215+
| `xr_gen_code_stm32` | Generates `app_main.cpp` from the YAML config |
216+
| `xr_stm32_it` | Patches interrupt handlers with UART/USB support |
217+
| `xr_stm32_cmake` | Integrates LibXR into the project build system |
218+
| `xr_stm32_toolchain_switch` | Switch toolchain and standard library |
204219

205220
---
206221

0 commit comments

Comments
 (0)