Skip to content

Commit 947e1e8

Browse files
committed
docs(perf): 更新文档结构,新增 CAN / CANFD 性能测试
1 parent f448421 commit 947e1e8

File tree

6 files changed

+204
-8
lines changed

6 files changed

+204
-8
lines changed

docs/perf/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
id: perf
3+
title: 关于性能
4+
sidebar_position: 3
5+
---
6+
7+
# 关于性能
8+
9+
本章会分析LibXR的不同模块/外设在极限性能测试下的表现,同时也作为高性能开发的参考。

docs/perf/perf-can.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
id: perf-can
3+
title: CAN性能测试
4+
sidebar_position: 2
5+
---
6+
7+
# CAN/CAN FD性能测试
8+
9+
## 测试环境
10+
11+
* STM32H750VB 480MHz
12+
* FDCAN1 连接到 FDCAN2
13+
* FDCAN1/FDCAN2 接收回调中直接转发
14+
* 每秒统计回调中接收到的包数量
15+
* 仲裁段配置为1Mbps,FD数据段配置为2.5Mbps
16+
17+
## 测试代码
18+
19+
```cpp
20+
STDIO::write_ = uart_cdc.write_port_;
21+
constexpr uint32_t PACK_ID = 0x123;
22+
constexpr CAN::Type PACK_TYPE = CAN::Type::STANDARD;
23+
constexpr uint32_t PACK_NUM = 8;
24+
25+
static volatile uint32_t counter = 0, speed = 0;
26+
27+
void (*can_func)(bool, LibXR::STM32CANFD *, const CAN::ClassicPack &) =
28+
[](bool, LibXR::STM32CANFD *can, const CAN::ClassicPack &pack)
29+
{
30+
can->AddMessage(pack);
31+
counter++;
32+
};
33+
34+
auto cb_can1 = CAN::Callback::Create(can_func, &fdcan1);
35+
fdcan1.Register(cb_can1, PACK_TYPE);
36+
auto cb_can2 = CAN::Callback::Create(can_func, &fdcan2);
37+
fdcan2.Register(cb_can2, PACK_TYPE);
38+
39+
LibXR::CAN::ClassicPack pack;
40+
pack.id = PACK_ID;
41+
pack.type = PACK_TYPE;
42+
43+
for (uint32_t i = 0; i < PACK_NUM; i++)
44+
{
45+
fdcan1.AddMessage(pack);
46+
}
47+
48+
while (true)
49+
{
50+
Thread::Sleep(1000);
51+
speed = counter;
52+
counter = 0;
53+
XR_LOG_DEBUG("speed: %d", speed);
54+
}
55+
```
56+
57+
## 测试结果
58+
59+
负载按5%位填充计算
60+
61+
### 标准帧 8字节数据
62+
63+
8917包/s,每包108位,数据段的速率为0.57Mbps,平均总线负载接近100%
64+
65+
理想情况下,数据段的速率位`64 / 108 * 1Mbps / 105% = 0.564Mbps`
66+
67+
### 拓展帧 8字节数据
68+
69+
7401包/s,每包128位,数据段的速率为0.47Mbps,平均总线负载接近100%
70+
71+
### 标准远程帧
72+
73+
20357包/s,每包44位,平均总线负载接近100%
74+
75+
### 拓展远程帧
76+
77+
14054包/s,每包64位,平均总线负载接近100%
78+
79+
### FD标准帧 64字节数据
80+
81+
3929包/s,数据段的速率为2.01Mbps,平均总线负载接近100%
82+
83+
### FD拓展帧 64字节数据
84+
85+
3617包/s,数据段的速率为1.85Mbps,平均总线负载接近100%
86+
87+
## 总结
88+
89+
本次测试表明,在 STM32H750(480MHz)平台下,LibXR 框架封装的 FDCAN 驱动在高频率双向回环通信中表现稳定高效。无论是经典帧还是 FD 帧,在配置为 1Mbps 仲裁段、2.5Mbps 数据段的情况下,系统均可实现接近理论极限的收发速率。

docs/perf.md renamed to docs/perf/perf-uart.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
id: perf
3-
title: 关于性能
4-
sidebar_position: 3
2+
id: perf-uart
3+
title: 串口收发性能测试
4+
sidebar_position: 1
55
---
66

7-
# 关于性能
7+
# 串口收发性能测试
88

99
对于本框架来说,有一个问题经常会被问到:**"LibXR对底层驱动封装之后,性能是否会很差?"**
1010

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
id: perf
3+
title: About Performance
4+
sidebar_position: 3
5+
---
6+
7+
# About Performance
8+
9+
This chapter will analyze the performance of different modules/devices in extreme performance testing, and also serve as a reference for high-performance development.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
id: perf-can
3+
title: CAN Performance Test
4+
sidebar_position: 2
5+
---
6+
7+
# CAN/CAN FD Performance Test
8+
9+
## Test Environment
10+
11+
* STM32H750VB @ 480MHz
12+
* FDCAN1 connected to FDCAN2
13+
* FDCAN1/FDCAN2 directly forward received frames in callback
14+
* Count number of received CAN packets per second in ISR
15+
* Arbitration phase set to 1Mbps, FD data phase set to 2.5Mbps
16+
17+
## Test Code
18+
19+
```cpp
20+
STDIO::write_ = uart_cdc.write_port_;
21+
constexpr uint32_t PACK_ID = 0x123;
22+
constexpr CAN::Type PACK_TYPE = CAN::Type::STANDARD;
23+
constexpr uint32_t PACK_NUM = 8;
24+
25+
static volatile uint32_t counter = 0, speed = 0;
26+
27+
void (*can_func)(bool, LibXR::STM32CANFD *, const CAN::ClassicPack &) =
28+
[](bool, LibXR::STM32CANFD *can, const CAN::ClassicPack &pack)
29+
{
30+
can->AddMessage(pack);
31+
counter++;
32+
};
33+
34+
auto cb_can1 = CAN::Callback::Create(can_func, &fdcan1);
35+
fdcan1.Register(cb_can1, PACK_TYPE);
36+
auto cb_can2 = CAN::Callback::Create(can_func, &fdcan2);
37+
fdcan2.Register(cb_can2, PACK_TYPE);
38+
39+
LibXR::CAN::ClassicPack pack;
40+
pack.id = PACK_ID;
41+
pack.type = PACK_TYPE;
42+
43+
for (uint32_t i = 0; i < PACK_NUM; i++)
44+
{
45+
fdcan1.AddMessage(pack);
46+
}
47+
48+
while (true)
49+
{
50+
Thread::Sleep(1000);
51+
speed = counter;
52+
counter = 0;
53+
XR_LOG_DEBUG("speed: %d", speed);
54+
}
55+
```
56+
57+
## Test Results
58+
59+
Bit stuffing is estimated at 5%.
60+
61+
### Standard Frame (8-byte data)
62+
63+
8917 packets/s, 108 bits per frame, data segment rate = 0.57 Mbps, bus load ≈ 100%
64+
65+
Ideal case: `64 / 108 * 1Mbps / 105% = 0.564 Mbps`
66+
67+
### Extended Frame (8-byte data)
68+
69+
7401 packets/s, 128 bits per frame, data segment rate = 0.47 Mbps, bus load ≈ 100%
70+
71+
### Standard Remote Frame
72+
73+
20357 packets/s, 44 bits per frame, bus load ≈ 100%
74+
75+
### Extended Remote Frame
76+
77+
14054 packets/s, 64 bits per frame, bus load ≈ 100%
78+
79+
### FD Standard Frame (64-byte data)
80+
81+
3929 packets/s, data segment rate = 2.01 Mbps, bus load ≈ 100%
82+
83+
### FD Extended Frame (64-byte data)
84+
85+
3617 packets/s, data segment rate = 1.85 Mbps, bus load ≈ 100%
86+
87+
## Summary
88+
89+
This test demonstrates that on the STM32H750 (480 MHz) platform, the FDCAN driver wrapped by the LibXR framework performs with excellent stability and efficiency in high-frequency, bi-directional loopback communication. Whether using classic CAN or CAN FD frames, the system can consistently reach transmission rates close to the theoretical limits under a configuration of 1 Mbps arbitration and 2.5 Mbps data phases.

i18n/en/docusaurus-plugin-content-docs/current/perf.md renamed to i18n/en/docusaurus-plugin-content-docs/current/perf/perf-uart.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
id: perf
3-
title: About Performance
4-
sidebar_position: 3
2+
id: perf-uart
3+
title: UART Performance Testing
4+
sidebar_position: 1
55
---
66

7-
# About Performance
7+
# UART Performance Testing
88

99
One common question often asked about this framework is: **"Will LibXR's abstraction over low-level drivers cause significant performance loss?"**
1010

0 commit comments

Comments
 (0)