Skip to content

Commit 303b43a

Browse files
committed
feat: add rt-thread sever exmples
1 parent a86a06b commit 303b43a

File tree

23 files changed

+1113
-7
lines changed

23 files changed

+1113
-7
lines changed

.github/workflows/unit_tests.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,78 @@ jobs:
7777
esp_idf_version: v5.2
7878
target: esp32
7979
path: 'examples/esp32_server'
80+
81+
rt-thread-qemu:
82+
runs-on: ubuntu-22.04
83+
name: Build RT-Thread QEMU
84+
steps:
85+
- name: checkout
86+
uses: actions/checkout@v4
87+
88+
- name: Install Tools
89+
run: |
90+
sudo apt-get update
91+
sudo apt-get install -y scons qemu-system libncurses5-dev git
92+
pip install kconfiglib requests
93+
94+
- name: Install Arm ToolChains
95+
run: |
96+
wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.3/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
97+
sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 -C /opt
98+
99+
- name: Checkout RT-Thread Source
100+
uses: actions/checkout@v4
101+
with:
102+
repository: RT-Thread/rt-thread
103+
path: rt-thread
104+
ref: master
105+
106+
- name: Build and Verify
107+
shell: bash
108+
run: |
109+
export RTT_CC=gcc
110+
export RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin
111+
export RTT_ROOT=${{ github.workspace }}/rt-thread
112+
113+
BSP_PATH=$RTT_ROOT/bsp/qemu-vexpress-a9
114+
USER_SCONSCRIPT=${{ github.workspace }}/examples/rtt_server/SConscript
115+
116+
cd $BSP_PATH
117+
118+
sed -i "/DoBuilding/i objs += SConscript('$USER_SCONSCRIPT')" SConstruct
119+
120+
scons --pyconfig-silent
121+
122+
echo "Injecting ISO14229 Configurations..."
123+
124+
echo "#define PKG_USING_ISO14229 1" >> rtconfig.h
125+
echo "#define UDS_USING_EXAMPLE 1" >> rtconfig.h
126+
127+
echo "#define RT_USING_ULOG 1" >> rtconfig.h
128+
echo "#define UDS_RTTHREAD_ULOG_ENABLED 1" >> rtconfig.h
129+
echo "#define UDS_LOG_LEVEL 3" >> rtconfig.h
130+
echo "#define UDS_EXAMPLE_ENABLE_DEBUG_LOG 1" >> rtconfig.h
131+
132+
echo "#define UDS_EXAMPLE_CAN_DEVICE_NAME \"can1\"" >> rtconfig.h
133+
echo "#define UDS_EXAMPLE_THREAD_PRIO 10" >> rtconfig.h
134+
echo "#define UDS_EXAMPLE_THREAD_STACK_SIZE 4096" >> rtconfig.h
135+
136+
echo "#define UDS_EXAMPLE_LED_CTRL_DID 0x0001" >> rtconfig.h
137+
echo "#define UDS_EXAMPLE_PIN_LED_R -1" >> rtconfig.h
138+
echo "#define UDS_EXAMPLE_PIN_LED_G -1" >> rtconfig.h
139+
echo "#define UDS_EXAMPLE_PIN_LED_B -1" >> rtconfig.h
140+
141+
echo "#define RT_USING_CAN" >> rtconfig.h
142+
echo "#define BSP_USING_CAN" >> rtconfig.h
143+
echo "#define RT_USING_FILTER" >> rtconfig.h
144+
145+
echo "Start Compiling..."
146+
scons -j$(nproc)
147+
148+
echo "Verifying symbols..."
149+
if /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-nm rtthread.elf | grep -i "uds"; then
150+
echo "✅ Verification Passed: UDS/ISO14229 symbols found in binary!"
151+
else
152+
echo "❌ Verification Failed: No UDS/ISO14229 symbols found!"
153+
exit 1
154+
fi

Doxyfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ INPUT = docs/mainpage.md \
126126
iso14229.c \
127127
examples/arduino_server/README.md \
128128
examples/esp32_server/README.md \
129+
examples/rtt_server/README.md \
129130
examples/linux_server/README.md \
130131
examples/linux_rdbi_wdbi/README.md \
131132
examples/linux_server_0x27/README.md \

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ API status: Major version zero (0.y.z) **(not yet stable)**. Anything MAY change
2121
- static memory allocation. (no `malloc`, `calloc`, ...)
2222
- highly portable and tested
2323
- architectures: arm, x86-64, ppc, ppc64, risc
24-
- systems: linux, Windows, esp32, Arduino, NXP s32k
24+
- systems: linux, Windows, esp32, RT-Thread, Arduino, NXP s32k
2525
- multiple transports supported: isotp-c, linux isotp sockets
26-
- examples for esp32, Arduino, NXP S32K144
26+
- examples for esp32, RT-Thread, Arduino, NXP S32K144
2727

2828
# Documentation
2929

docs/mainpage.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ To access the examples, clone or download the repository from https://github.com
2222
| \ref examples/linux_server_0x27/README.md "linux_server_0x27" | Security Access (0x27) |
2323
| \ref examples/arduino_server/README.md "arduino_server" | Arduino server |
2424
| \ref examples/esp32_server/README.md "esp32_server" | ESP32 server |
25+
| \ref examples/rtt_server/README.md "rtt_server" | RTT server |
2526
| \ref examples/s32k144_server/README.md "s32k144_server" | NXP S32K144 server |
2627

2728
---
@@ -42,7 +43,7 @@ Configure the library at compilation time with preprocessor defines:
4243
|-----------|--------|-------------|-------------|------------|
4344
| **isotp_sock** | `-DUDS_TP_ISOTP_SOCK` | Linux kernel ISO-TP socket | Linux newer than 5.10 | \ref examples/linux_server_0x27/README.md "linux_server_0x27" |
4445
| **isotp_c_socketcan** | `-DUDS_TP_ISOTP_C_SOCKETCAN` | isotp-c over SocketCAN | Linux newer than 2.6.25 | \ref examples/linux_server_0x27/README.md "linux_server_0x27" |
45-
| **isotp_c** | `-DUDS_TP_ISOTP_C` | Software ISO-TP | Everything else | \ref examples/arduino_server/README.md "arduino_server" \ref examples/esp32_server/README.md "esp32_server" \ref examples/s32k144_server/README.md "s32k144_server" |
46+
| **isotp_c** | `-DUDS_TP_ISOTP_C` | Software ISO-TP | Everything else | \ref examples/arduino_server/README.md "arduino_server" \ref examples/esp32_server/README.md "esp32_server" \ref examples/rtt_server/README.md "rtt_server" \ref examples/s32k144_server/README.md "s32k144_server" |
4647
| **isotp_mock** | `-DUDS_TP_ISOTP_MOCK` | In-memory transport for testing | platform-independent unit tests | see unit tests |
4748

4849
### System Selection Override
@@ -51,9 +52,9 @@ The system is usually detected by default, but can be overridden with the follow
5152

5253
| Define | Values |
5354
|--------|--------|
54-
| `-DUDS_SYS=` | `UDS_SYS_UNIX`, `UDS_SYS_WINDOWS`, `UDS_SYS_ARDUINO`, `UDS_SYS_ESP32`, `UDS_SYS_CUSTOM` |
55+
| `-DUDS_SYS=` | `UDS_SYS_UNIX`, `UDS_SYS_WINDOWS`, `UDS_SYS_ARDUINO`, `UDS_SYS_ESP32`, `UDS_SYS_RTT` `UDS_SYS_CUSTOM` |
5556

56-
For examples of `UDS_SYS_CUSTOM`, see \ref examples/arduino_server/README.md "arduino_server", \ref examples/esp32_server/README.md "esp32_server", \ref examples/s32k144_server/README.md "s32k144_server".
57+
For examples of `UDS_SYS_CUSTOM`, see \ref examples/arduino_server/README.md "arduino_server", \ref examples/esp32_server/README.md "esp32_server", \ref examples/rtt_server/README.md "rtt_server", \ref examples/s32k144_server/README.md "s32k144_server".
5758

5859
### Logging
5960

examples/rtt_server/Kconfig

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
menuconfig PKG_USING_ISO14229
2+
bool "Enable iso14229 (UDS) library"
3+
default n
4+
help
5+
ISO14229-1 (UDS) library for RT-Thread.
6+
This library provides a platform-agnostic UDS client and server implementation.
7+
8+
if PKG_USING_ISO14229
9+
10+
menu "Logging Configuration"
11+
config UDS_LOG_LEVEL
12+
int "Log level"
13+
range 0 5
14+
default 3
15+
help
16+
Set the log level for the UDS library.
17+
0: No log output
18+
1: Errors only
19+
2: Warnings and errors
20+
3: Info, warnings, and errors
21+
4: Debug, info, warnings, and errors
22+
5: Verbose, debug, info, warnings, and errors
23+
24+
config UDS_RTTHREAD_ULOG_ENABLED
25+
bool "Use ULOG for logging"
26+
default y
27+
depends on RT_USING_ULOG
28+
help
29+
If enabled, the library will use RT-Thread's ULOG component.
30+
Otherwise, it will fall back to rt_kprintf.
31+
32+
config UDS_CONFIG_LOG_COLORS
33+
bool "Enable colorized log output (when not using ULOG)"
34+
default y
35+
depends on !UDS_RTTHREAD_ULOG_ENABLED
36+
help
37+
Enables ANSI color codes in the log output.
38+
This option is only effective when ULOG is disabled, as ULOG
39+
has its own color configuration (ULOG_OUTPUT_COLOR).
40+
41+
config UDS_RTTHREAD_LOG_BUFFER_SIZE
42+
int "Buffer size for a single log message (if not using ULOG)"
43+
default 256
44+
depends on !UDS_RTTHREAD_ULOG_ENABLED
45+
help
46+
Specifies the size of the temporary buffer used to format
47+
a single log message before printing. This is only active
48+
when ULOG is disabled.
49+
endmenu
50+
51+
config UDS_USING_EXAMPLE
52+
bool "Enable UDS server example with Finsh/MSH commands"
53+
default n
54+
help
55+
This option compiles the rtt_uds_example.c file, which provides
56+
'uds_example start' and 'uds_example stop' commands in the shell.
57+
Disable this if you only need the core library and want to write
58+
your own application logic.
59+
60+
if UDS_USING_EXAMPLE
61+
menu "UDS Server Example Configuration"
62+
config UDS_EXAMPLE_CAN_DEVICE_NAME
63+
string "CAN device name for the example"
64+
default "can1"
65+
help
66+
Specify the name of the CAN device to be used by the UDS server example.
67+
68+
config UDS_EXAMPLE_THREAD_PRIO
69+
int "UDS task thread priority"
70+
default 10
71+
help
72+
Priority for the main UDS processing thread.
73+
74+
config UDS_EXAMPLE_THREAD_STACK_SIZE
75+
int "UDS task thread stack size (in bytes)"
76+
default 4096
77+
78+
config UDS_EXAMPLE_ENABLE_DEBUG_LOG
79+
bool "Enable debug logs in the example"
80+
default y
81+
help
82+
Enable verbose logging like CAN frame hex dumps in the
83+
uds_rtt_port.c example file.
84+
85+
config UDS_EXAMPLE_LED_CTRL_DID
86+
hex "DID for LED control"
87+
default 0x0001
88+
help
89+
The Data Identifier (DID) used in the example to control LEDs.
90+
91+
config UDS_EXAMPLE_PIN_LED_R
92+
int "GPIO Pin for Red LED"
93+
default -1
94+
help
95+
Set the GPIO pin number for the Red LED. -1 to disable.
96+
97+
config UDS_EXAMPLE_PIN_LED_G
98+
int "GPIO Pin for Green LED"
99+
default -1
100+
help
101+
Set the GPIO pin number for the Green LED. -1 to disable.
102+
103+
config UDS_EXAMPLE_PIN_LED_B
104+
int "GPIO Pin for Blue LED"
105+
default -1
106+
help
107+
Set the GPIO pin number for the Blue LED. -1 to disable.
108+
endmenu
109+
endif
110+
111+
endif

examples/rtt_server/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
SRCS += main/iso14229.c
2+
HDRS += main/iso14229.h
3+
TARGETS = client
4+
CFLAGS = -DUDS_TP_ISOTP_SOCK -DUDS_LINES -DUDS_LOG_LEVEL=UDS_LOG_INFO -g -Imain
5+
6+
all: $(TARGETS)
7+
8+
client: $(SRCS) $(HDRS) client.c Makefile
9+
$(CC) $(CFLAGS) $(SRCS) client.c -o client
10+
11+
clean:
12+
rm -f $(TARGETS)

examples/rtt_server/README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# UDS Server Example for RT-Thread
2+
3+
UDS server example for RT-Thread platform.
4+
5+
## Overview
6+
7+
This example demonstrates a UDS (ISO 14229) server running on an RT-Thread based embedded system. It uses the RT-Thread CAN device driver for communication.
8+
9+
Also included is a Linux-based client example that can be run from a host computer to test the server. This setup allows for diagnostics and interaction with the embedded device over a CAN bus.
10+
11+
## Required Hardware
12+
13+
#### Server (Embedded Device)
14+
* Any development board running the RT-Thread operating system.
15+
* A CAN transceiver connected to the board's CAN peripheral (e.g., a board with an integrated SN65HVD230).
16+
17+
#### Client (Host Machine)
18+
* A Linux computer (or a virtual machine).
19+
* A SocketCAN-compatible adapter (e.g., USB-to-CAN adapter) connected to the host and the embedded device's CAN bus.
20+
21+
## Setup: Server (RT-Thread Device)
22+
23+
1. **Integrate the Library**: Add the UDS library source code to your RT-Thread project.
24+
2. **Configure the Port**: Ensure the `rtt_uds_example.c` file is correctly configured for your target board, especially the CAN device name (`UDS_EXAMPLE_CAN_DEVICE_NAME`) and any GPIOs used in the example.
25+
3. **Compile and Flash**: Build and flash the RT-Thread project to your target hardware using your standard toolchain (e.g., SCons).
26+
4. **Run the Example**: Connect to the device's serial console (e.g., via MSH/Finsh) and start the UDS server example.
27+
28+
```sh
29+
# Connect to the RT-Thread serial console
30+
msh />
31+
msh />uds_example start
32+
11-14 19:53:09 isotp.rtt: UDS example started on can1.
33+
```
34+
35+
## Setup: Client (Linux Host)
36+
37+
1. **Configure SocketCAN**: Bring up the CAN interface on your Linux machine.
38+
39+
```sh
40+
# Example for a device at 1Mbit/s
41+
sudo ip link set can0 up type can bitrate 1000000
42+
```
43+
44+
2. **Compile and Run**: Navigate to the client example directory, compile it, and run the executable.
45+
46+
```sh
47+
# Assuming the client source files are in the current directory
48+
make && ./client
49+
```
50+
51+
## Example Interaction Log
52+
53+
This section shows a typical interaction between the Linux client and the RT-Thread server, along with the corresponding CAN traffic dump.
54+
55+
### Server Output (RT-Thread MSH/Finsh Console)
56+
57+
After starting the server with `uds_example start`, the device begins listening for CAN messages. When the client sends `WriteDataByIdentifier` requests, the server processes them and prints log messages.
58+
59+
```sh
60+
msh />uds_example start
61+
11-14 19:53:09 isotp.rtt: UDS example started on can1.
62+
63+
# Client sends a request to write 0x01 to DID 0x0001
64+
11-14 19:53:10 isotp.rtt: CAN RX ID:0x7E0 [5 bytes]: 04 2E 00 01 01
65+
11-14 19:53:10 UDS.core: I (6703) ./iso14229.c: phys link received 4 bytes
66+
11-14 19:53:10 isotp.rtt: Server Event: UDS_EVT_WriteDataByIdent (0xA)
67+
11-14 19:53:10 isotp.rtt: --> WDBI DID:0x0001 Data [1 bytes]: 01
68+
11-14 19:53:10 isotp.rtt: Controlling LEDs with value: 0x01
69+
11-14 19:53:10 isotp.rtt: [TX] ID: 0x7E8 [4 bytes]: 03 6E 00 01
70+
71+
# Client sends a request to write 0x02 to DID 0x0001
72+
11-14 19:53:10 isotp.rtt: CAN RX ID:0x7E0 [5 bytes]: 04 2E 00 01 02
73+
11-14 19:53:10 UDS.core: I (6762) ./iso14229.c: phys link received 4 bytes
74+
11-14 19:53:10 isotp.rtt: Server Event: UDS_EVT_WriteDataByIdent (0xA)
75+
11-14 19:53:10 isotp.rtt: --> WDBI DID:0x0001 Data [1 bytes]: 02
76+
11-14 19:53:10 isotp.rtt: Controlling LEDs with value: 0x02
77+
11-14 19:53:10 isotp.rtt: [TX] ID: 0x7E8 [4 bytes]: 03 6E 00 01
78+
# ... and so on ...
79+
```
80+
81+
### Client Output (Linux Console)
82+
83+
The client application shows the state transitions and events as it sends requests and receives responses from the server.
84+
85+
```sh
86+
root@root:/Debug# ./client
87+
I (2431038538) src/tp/isotp_sock.c: client initialized phys link (fd 3) rx 0x7e8 tx 0x7e0 func link (fd 4) rx 0x7e8 tx 0x7df
88+
I (2431038538) client.c: polling
89+
I (2431038538) src/client.c: client state: Idle (0) -> Sending (1)
90+
I (2431038538) src/client.c: client state: Sending (1) -> AwaitSendComplete (2)
91+
I (2431038538) client.c: UDS_EVT_SendComplete (26)
92+
I (2431038538) src/client.c: client state: AwaitSendComplete (2) -> AwaitResponse (3)
93+
I (2431038559) src/client.c: received 3 bytes. Processing...
94+
I (2431038559) client.c: UDS_EVT_ResponseReceived (27)
95+
I (2431038559) client.c: WDBI response received
96+
I (2431038559) src/client.c: client state: AwaitResponse (3) -> Idle (0)
97+
I (2431038559) client.c: UDS_EVT_Idle (28)
98+
# ... loop continues, sending next request ...
99+
```
100+
101+
### CAN Bus Traffic (`candump`)
102+
103+
Using the `candump` utility on the Linux host shows the raw CAN frames exchanged between the client and the server.
104+
105+
* `7E0`: Client (tester) sending a request to the server (ECU).
106+
* `7E8`: Server (ECU) sending a response back to the client.
107+
108+
```sh
109+
candump can0
110+
# Request: Write Data (0x2E) to DID 0x0001 with value 0x01
111+
can0 7E0 [5] 04 2E 00 01 01
112+
# Response: Positive Response (0x6E) for service 0x2E, DID 0x0001
113+
can0 7E8 [4] 03 6E 00 01
114+
115+
# Request: Write Data (0x2E) to DID 0x0001 with value 0x02
116+
can0 7E0 [5] 04 2E 00 01 02
117+
# Response: Positive Response
118+
can0 7E8 [4] 03 6E 00 01
119+
120+
# Request: Write Data (0x2E) to DID 0x0001 with value 0x03
121+
can0 7E0 [5] 04 2E 00 01 03
122+
# Response: Positive Response
123+
can0 7E8 [4] 03 6E 00 01
124+
# ... and so on ...
125+
```
126+
127+
### **⚠️ Important Note**
128+
129+
The code and installation instructions here are merely presented as a simple example to demonstrate the basic integration and functionality. For the complete application and detailed functional code, please refer to the code repository:
130+
**[iso14229 rtt software](https://github.com/wdfk-prog/can_uds)**

0 commit comments

Comments
 (0)