Skip to content

Commit ae3864d

Browse files
authored
Merge pull request #3423 from armusin/threadx_osal
ThreadX OSAL header
2 parents cd7bbba + ce8a770 commit ae3864d

File tree

14 files changed

+584
-82
lines changed

14 files changed

+584
-82
lines changed

.github/workflows/claude-code-review.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
name: Claude Code Review
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types: [opened, synchronize, ready_for_review, reopened]
6-
# Optional: Only run on specific file changes
7-
# paths:
8-
# - "src/**/*.ts"
9-
# - "src/**/*.tsx"
10-
# - "src/**/*.js"
11-
# - "src/**/*.jsx"
126

137
jobs:
148
claude-review:
15-
# Optional: Filter by PR author
16-
# if: |
17-
# github.event.pull_request.user.login == 'external-contributor' ||
18-
# github.event.pull_request.user.login == 'new-developer' ||
19-
# github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
20-
219
runs-on: ubuntu-latest
2210
permissions:
2311
contents: read
24-
pull-requests: read
12+
pull-requests: write
2513
issues: read
2614
id-token: write
2715

AGENTS.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,72 @@ Use `-DBOARD=...` with any supported board under `hw/bsp/espressif/boards/`. NEV
114114
- `cd examples/device/cdc_msc_freertos`
115115
- `idf.py -DBOARD=espressif_s3_devkitc monitor`
116116

117-
## J-Link GDB Server + RTT Logging
117+
## GDB Debugging
118+
119+
Look up the board's `JLINK_DEVICE` and `OPENOCD_OPTION` from `hw/bsp/*/boards/*/board.cmake` (or `board.mk`).
120+
121+
### JLinkGDBServer
122+
123+
**Terminal 1 – start the GDB server:**
124+
```bash
125+
JLinkGDBServer -device stm32h743xi -if SWD -speed 4000 \
126+
-port 2331 -swoport 2332 -telnetport 2333 -nogui
127+
```
128+
129+
**Terminal 2 – connect GDB:**
130+
```bash
131+
arm-none-eabi-gdb /tmp/build/firmware.elf
132+
(gdb) target remote :2331
133+
(gdb) monitor reset halt
134+
(gdb) load
135+
(gdb) continue
136+
```
137+
138+
To break on entry instead of running immediately:
139+
```bash
140+
(gdb) monitor reset halt
141+
(gdb) load
142+
(gdb) break main
143+
(gdb) continue
144+
```
145+
146+
### OpenOCD
147+
148+
**Terminal 1 – start the GDB server:**
149+
```bash
150+
openocd -f interface/stlink.cfg -f target/stm32h7x.cfg
151+
# or with J-Link probe:
152+
openocd -f interface/jlink.cfg -f target/stm32h7x.cfg
153+
```
154+
155+
For boards that define `OPENOCD_OPTION` in `board.cmake`, use those options directly:
156+
```bash
157+
openocd $(cat hw/bsp/FAMILY/boards/BOARD/board.cmake | grep OPENOCD_OPTION | ...)
158+
```
159+
160+
**Terminal 2 – connect GDB (OpenOCD default port is 3333):**
161+
```bash
162+
arm-none-eabi-gdb /tmp/build/firmware.elf
163+
(gdb) target remote :3333
164+
(gdb) monitor reset halt
165+
(gdb) load
166+
(gdb) continue
167+
```
168+
169+
### RTT Logging with JLinkGDBServer
118170

119171
- Build with RTT logging enabled (example):
120172
`cd examples/device/cdc_msc && make BOARD=stm32h743eval LOG=2 LOGGER=rtt all`
121173
- Flash with J-Link:
122174
`cd examples/device/cdc_msc && make BOARD=stm32h743eval LOG=2 LOGGER=rtt flash-jlink`
123-
- Launch GDB server (keep this running in terminal 1):
175+
- Launch GDB server with RTT port (keep this running in terminal 1):
124176
`JLinkGDBServer -device stm32h743xi -if SWD -speed 4000 -port 2331 -swoport 2332 -telnetport 2333 -RTTTelnetPort 19021 -nogui`
125177
- Read RTT output (terminal 2):
126178
`JLinkRTTClient`
127179
- Capture RTT to file (optional):
128180
`JLinkRTTClient | tee rtt.log`
129181
- For non-interactive capture:
130182
`timeout 20s JLinkRTTClient > rtt.log`
131-
- Use the board-specific `JLINK_DEVICE` from `hw/bsp/*/boards/*/board.mk` if you are not using `stm32h743eval`.
132183

133184
## Unit Testing
134185

docs/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Yes, TinyUSB is released under the MIT license, allowing commercial use with min
1515

1616
**Q: Does TinyUSB require an RTOS?**
1717

18-
No, TinyUSB works in bare metal environments. It also supports FreeRTOS, RT-Thread, and Mynewt.
18+
No, TinyUSB works in bare metal environments. It also supports FreeRTOS, RT-Thread, ThreadX, and Mynewt.
1919

2020
**Q: How much memory does TinyUSB use?**
2121

examples/device/board_test/src/main.c

Lines changed: 107 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,35 @@ enum {
3939

4040
#define HELLO_STR "Hello from TinyUSB\r\n"
4141

42-
int main(void) {
43-
board_init();
44-
board_led_write(true);
42+
// board test example does not use both device and host stack
43+
#if CFG_TUSB_OS != OPT_OS_NONE
44+
uint32_t tusb_time_millis_api(void) {
45+
return osal_time_millis();
46+
}
47+
48+
void tusb_time_delay_ms_api(uint32_t ms) {
49+
osal_task_delay(ms);
50+
}
51+
#endif
52+
53+
//--------------------------------------------------------------------+
54+
//
55+
//--------------------------------------------------------------------+
56+
57+
// Task parameter type: ULONG for ThreadX, void* for FreeRTOS and noos
58+
#if CFG_TUSB_OS == OPT_OS_THREADX
59+
#define RTOS_PARAM ULONG
60+
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
61+
#define RTOS_PARAM void*
62+
static void freertos_init(void);
63+
#else
64+
#define RTOS_PARAM void*
65+
#endif
4566

67+
static void board_test_loop(RTOS_PARAM param) {
68+
(void) param;
4669
uint32_t start_ms = 0;
70+
(void) start_ms;
4771
bool led_state = false;
4872

4973
while (1) {
@@ -58,26 +82,94 @@ int main(void) {
5882
}
5983

6084
// Blink and print every interval ms
61-
if (!(tusb_time_millis_api() - start_ms < interval_ms)) {
62-
start_ms = tusb_time_millis_api();
63-
64-
if (ch < 0) {
65-
// skip if echoing
66-
printf(HELLO_STR);
85+
#if CFG_TUSB_OS == OPT_OS_FREERTOS
86+
vTaskDelay(interval_ms / portTICK_PERIOD_MS);
87+
#elif CFG_TUSB_OS == OPT_OS_THREADX
88+
tx_thread_sleep(_osal_ms2tick(interval_ms));
89+
#else
90+
if (tusb_time_millis_api() - start_ms < interval_ms) {
91+
continue; // not enough time
92+
}
93+
#endif
94+
start_ms = tusb_time_millis_api();
6795

68-
#ifndef LOGGER_UART
69-
board_uart_write(HELLO_STR, sizeof(HELLO_STR)-1);
70-
#endif
71-
}
96+
if (ch < 0) {
97+
// skip if echoing
98+
printf(HELLO_STR);
7299

73-
board_led_write(led_state);
74-
led_state = !led_state; // toggle
100+
#ifndef LOGGER_UART
101+
board_uart_write(HELLO_STR, sizeof(HELLO_STR)-1);
102+
#endif
75103
}
104+
105+
board_led_write(led_state);
106+
led_state = !led_state; // toggle
76107
}
77108
}
78109

110+
int main(void) {
111+
board_init();
112+
board_led_write(true);
113+
114+
#if CFG_TUSB_OS == OPT_OS_FREERTOS
115+
freertos_init();
116+
#elif CFG_TUSB_OS == OPT_OS_THREADX
117+
tx_kernel_enter();
118+
#else
119+
board_test_loop(NULL);
120+
#endif
121+
122+
return 0;
123+
}
124+
79125
#ifdef ESP_PLATFORM
80126
void app_main(void) {
81127
main();
82128
}
83129
#endif
130+
131+
//--------------------------------------------------------------------+
132+
// FreeRTOS
133+
//--------------------------------------------------------------------+
134+
#if CFG_TUSB_OS == OPT_OS_FREERTOS
135+
136+
#ifdef ESP_PLATFORM
137+
#define MAIN_STACK_SIZE 4096
138+
#else
139+
#define MAIN_STACK_SIZE 512
140+
#endif
141+
142+
#if configSUPPORT_STATIC_ALLOCATION
143+
static StackType_t _main_stack[MAIN_STACK_SIZE];
144+
static StaticTask_t _main_taskdef;
145+
#endif
146+
147+
static void freertos_init(void) {
148+
#if configSUPPORT_STATIC_ALLOCATION
149+
xTaskCreateStatic(board_test_loop, "main", MAIN_STACK_SIZE, NULL, 1, _main_stack, &_main_taskdef);
150+
#else
151+
xTaskCreate(board_test_loop, "main", MAIN_STACK_SIZE, NULL, 1, NULL);
152+
#endif
153+
154+
#ifndef ESP_PLATFORM
155+
vTaskStartScheduler();
156+
#endif
157+
}
158+
159+
//--------------------------------------------------------------------+
160+
// ThreadX
161+
//--------------------------------------------------------------------+
162+
#elif CFG_TUSB_OS == OPT_OS_THREADX
163+
164+
#define MAIN_TASK_STACK_SIZE 1024
165+
static TX_THREAD _main_thread;
166+
static ULONG _main_thread_stack[MAIN_TASK_STACK_SIZE / sizeof(ULONG)];
167+
168+
void tx_application_define(void *first_unused_memory) {
169+
(void) first_unused_memory;
170+
static CHAR main_thread_name[] = "main";
171+
tx_thread_create(&_main_thread, main_thread_name, board_test_loop, 0,
172+
_main_thread_stack, MAIN_TASK_STACK_SIZE,
173+
1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
174+
}
175+
#endif

0 commit comments

Comments
 (0)