Skip to content

Commit fad3dc4

Browse files
committed
Merge branch 'master' into sb-ep
2 parents 4ae433f + 2027ac2 commit fad3dc4

File tree

358 files changed

+20542
-4306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

358 files changed

+20542
-4306
lines changed

.circleci/config.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,20 @@ jobs:
1919
echo "MATRIX_JSON=$MATRIX_JSON"
2020
2121
BUILDSYSTEM_TOOLCHAIN=(
22+
"cmake aarch64-gcc"
2223
"cmake arm-clang"
24+
"cmake arm-gcc"
2325
"cmake esp-idf"
24-
"make aarch64-gcc"
25-
"make arm-gcc"
26-
"make msp430-gcc"
27-
"make riscv-gcc"
28-
"make rx-gcc"
26+
"cmake msp430-gcc"
27+
"cmake riscv-gcc"
2928
)
3029
3130
# only build IAR if not forked PR, since IAR token is not shared
3231
if [ -z $CIRCLE_PR_USERNAME ]; then
3332
BUILDSYSTEM_TOOLCHAIN+=("cmake arm-iar")
3433
fi
3534
36-
RESOURCE_LARGE='["nrf", "imxrt", "stm32f4", "stm32h7"]'
35+
RESOURCE_LARGE='["nrf", "imxrt", "stm32f4", "stm32h7 stm32h7rs"]'
3736
3837
gen_build_entry() {
3938
local build_system="$1"
@@ -67,7 +66,7 @@ jobs:
6766
FAMILY_LARGE=$(jq -n --argjson family "$FAMILY" --argjson resource "$RESOURCE_LARGE" '$family | map(select(IN($resource[])))')
6867
FAMILY=$(jq -n --argjson family "$FAMILY" --argjson resource "$RESOURCE_LARGE" '$family | map(select(IN($resource[]) | not))')
6968
70-
if [[ $toolchain == esp-idf ]]; then
69+
if [[ $toolchain == esp-idf || $toolchain == arm-iar ]]; then
7170
gen_build_entry "$build_system" "$toolchain" "$FAMILY" "large"
7271
else
7372
gen_build_entry "$build_system" "$toolchain" "$FAMILY" "medium+"

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ body:
8686

8787
- type: checkboxes
8888
attributes:
89-
label: I have checked existing issues, dicussion and documentation
89+
label: I have checked existing issues, discussion and documentation
9090
description: You agree to check all the resources above before opening a new issue.
9191
options:
92-
- label: I confirm I have checked existing issues, dicussion and documentation.
92+
- label: I confirm I have checked existing issues, discussion and documentation.
9393
required: true

.github/copilot-instructions.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# TinyUSB
2+
TinyUSB is an open-source cross-platform USB Host/Device stack for embedded systems, designed to be memory-safe with no dynamic allocation and thread-safe with all interrupt events deferred to non-ISR task functions.
3+
4+
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
5+
6+
## Working Effectively
7+
8+
### Bootstrap and Build Setup
9+
- Install ARM GCC toolchain: `sudo apt-get update && sudo apt-get install -y gcc-arm-none-eabi`
10+
- Fetch core dependencies: `python3 tools/get_deps.py` -- takes <1 second. NEVER CANCEL.
11+
- For specific board families: `python3 tools/get_deps.py FAMILY_NAME` (e.g., rp2040, stm32f4)
12+
- Dependencies are cached in `lib/` and `hw/mcu/` directories
13+
14+
### Build Examples
15+
Choose ONE of these approaches:
16+
17+
**Option 1: Individual Example with CMake (RECOMMENDED)**
18+
```bash
19+
cd examples/device/cdc_msc
20+
mkdir -p build && cd build
21+
cmake -DBOARD=stm32f407disco -DCMAKE_BUILD_TYPE=MinSizeRel ..
22+
cmake --build . -j4
23+
```
24+
-- takes 1-2 seconds. NEVER CANCEL. Set timeout to 5+ minutes.
25+
26+
**Option 2: Individual Example with Make**
27+
```bash
28+
cd examples/device/cdc_msc
29+
make BOARD=stm32f407disco all
30+
```
31+
-- takes 2-3 seconds. NEVER CANCEL. Set timeout to 5+ minutes.
32+
33+
**Option 3: All Examples for a Board**
34+
```bash
35+
python3 tools/build.py -b BOARD_NAME
36+
```
37+
-- takes 15-20 seconds, may have some objcopy failures that are non-critical. NEVER CANCEL. Set timeout to 30+ minutes.
38+
39+
### Unit Testing
40+
- Install Ceedling: `sudo gem install ceedling`
41+
- Run all unit tests: `cd test/unit-test && ceedling` -- takes 4 seconds. NEVER CANCEL. Set timeout to 10+ minutes.
42+
- Tests use Unity framework with CMock for mocking
43+
44+
### Documentation
45+
- Install requirements: `pip install -r docs/requirements.txt`
46+
- Build docs: `cd docs && sphinx-build -b html . _build` -- takes 2-3 seconds. NEVER CANCEL. Set timeout to 10+ minutes.
47+
48+
### Code Quality and Validation
49+
- Format code: `clang-format -i path/to/file.c` (uses `.clang-format` config)
50+
- Check spelling: `pip install codespell && codespell` (uses `.codespellrc` config)
51+
- Pre-commit hooks validate unit tests and code quality automatically
52+
53+
## Validation
54+
55+
### ALWAYS Run These After Making Changes
56+
1. **Pre-commit validation** (RECOMMENDED): `pre-commit run --all-files`
57+
- Install pre-commit: `pip install pre-commit && pre-commit install`
58+
- Runs all quality checks, unit tests, spell checking, and formatting
59+
- Takes 10-15 seconds. NEVER CANCEL. Set timeout to 15+ minutes.
60+
2. **Build validation**: Build at least one example that exercises your changes
61+
```bash
62+
cd examples/device/cdc_msc
63+
make BOARD=stm32f407disco all
64+
```
65+
66+
### Manual Testing Scenarios
67+
- **Device examples**: Cannot be fully tested without real hardware, but must build successfully
68+
- **Unit tests**: Exercise core stack functionality - ALL tests must pass
69+
- **Build system**: Must be able to build examples for multiple board families
70+
71+
### Board Selection for Testing
72+
- **STM32F4**: `stm32f407disco` - no external SDK required, good for testing
73+
- **RP2040**: `pico_sdk` - requires Pico SDK, commonly used
74+
- **Other families**: Check `hw/bsp/FAMILY/boards/` for available boards
75+
76+
## Common Tasks and Time Expectations
77+
78+
### Repository Structure Quick Reference
79+
```
80+
├── src/ # Core TinyUSB stack
81+
│ ├── class/ # USB device classes (CDC, HID, MSC, Audio, etc.)
82+
│ ├── portable/ # MCU-specific drivers (organized by vendor)
83+
│ ├── device/ # USB device stack core
84+
│ ├── host/ # USB host stack core
85+
│ └── common/ # Shared utilities (FIFO, etc.)
86+
├── examples/ # Example applications
87+
│ ├── device/ # Device examples (cdc_msc, hid_generic, etc.)
88+
│ ├── host/ # Host examples
89+
│ └── dual/ # Dual-role examples
90+
├── hw/bsp/ # Board Support Packages
91+
│ └── FAMILY/boards/ # Board-specific configurations
92+
├── test/unit-test/ # Unit tests using Ceedling
93+
├── tools/ # Build and utility scripts
94+
└── docs/ # Sphinx documentation
95+
```
96+
97+
### Build Time Reference
98+
- **Dependency fetch**: <1 second
99+
- **Single example build**: 1-3 seconds
100+
- **Unit tests**: ~4 seconds
101+
- **Documentation build**: ~2.5 seconds
102+
- **Full board examples**: 15-20 seconds
103+
- **Toolchain installation**: 2-5 minutes (one-time)
104+
105+
### Key Files to Know
106+
- `tools/get_deps.py`: Manages dependencies for MCU families
107+
- `tools/build.py`: Builds multiple examples, supports make/cmake
108+
- `src/tusb.h`: Main TinyUSB header file
109+
- `src/tusb_config.h`: Configuration template
110+
- `examples/device/cdc_msc/`: Most commonly used example for testing
111+
- `test/unit-test/project.yml`: Ceedling test configuration
112+
113+
### Debugging Build Issues
114+
- **Missing compiler**: Install `gcc-arm-none-eabi` package
115+
- **Missing dependencies**: Run `python3 tools/get_deps.py FAMILY`
116+
- **Board not found**: Check `hw/bsp/FAMILY/boards/` for valid board names
117+
- **objcopy errors**: Often non-critical in full builds, try individual example builds
118+
119+
### Working with USB Device Classes
120+
- **CDC (Serial)**: `src/class/cdc/` - Virtual serial port
121+
- **HID**: `src/class/hid/` - Human Interface Device (keyboard, mouse, etc.)
122+
- **MSC**: `src/class/msc/` - Mass Storage Class (USB drive)
123+
- **Audio**: `src/class/audio/` - USB Audio Class
124+
- Each class has device (`*_device.c`) and host (`*_host.c`) implementations
125+
126+
### MCU Family Support
127+
- **STM32**: Largest support (F0, F1, F2, F3, F4, F7, G0, G4, H7, L4, U5, etc.)
128+
- **Raspberry Pi**: RP2040, RP2350 with PIO-USB host support
129+
- **NXP**: iMXRT, Kinetis, LPC families
130+
- **Microchip**: SAM D/E/G/L families
131+
- Check `hw/bsp/` for complete list and `docs/reference/boards.rst` for details
132+
133+
Remember: TinyUSB is designed for embedded systems - builds are fast, tests are focused, and the codebase is optimized for resource-constrained environments.

.github/workflows/build.yml

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ env:
3636
HIL_JSON: test/hil/tinyusb.json
3737

3838
jobs:
39-
# ---------------------------------------
40-
#
41-
# Build
42-
#
43-
# ---------------------------------------
4439
set-matrix:
4540
runs-on: ubuntu-latest
4641
outputs:
@@ -63,28 +58,31 @@ jobs:
6358
echo "hil_matrix=$HIL_MATRIX_JSON" >> $GITHUB_OUTPUT
6459
6560
# ---------------------------------------
66-
# Build CMake
61+
# Build CMake: only build on push with one-per-family.
62+
# Full built is done by CircleCI in PR
6763
# ---------------------------------------
6864
cmake:
65+
if: github.event_name == 'push'
6966
needs: set-matrix
7067
uses: ./.github/workflows/build_util.yml
7168
strategy:
7269
fail-fast: false
7370
matrix:
7471
toolchain:
75-
# - 'arm-clang' is built by circle-ci in PR
7672
- 'aarch64-gcc'
73+
#- 'arm-clang'
7774
- 'arm-gcc'
75+
- 'esp-idf'
7876
- 'msp430-gcc'
7977
- 'riscv-gcc'
8078
with:
8179
build-system: 'cmake'
8280
toolchain: ${{ matrix.toolchain }}
8381
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain]) }}
84-
one-per-family: ${{ github.event_name == 'push' }}
82+
one-per-family: true
8583

8684
# ---------------------------------------
87-
# Build Make (built by circle-ci in PR, only build on push here)
85+
# Build Make: only build on push with one-per-family
8886
# ---------------------------------------
8987
make:
9088
if: github.event_name == 'push'
@@ -94,36 +92,18 @@ jobs:
9492
fail-fast: false
9593
matrix:
9694
toolchain:
97-
# 'arm-clang'
98-
- 'arm-gcc'
9995
- 'aarch64-gcc'
96+
#- 'arm-clang'
97+
- 'arm-gcc'
10098
- 'msp430-gcc'
10199
- 'riscv-gcc'
102100
- 'rx-gcc'
103-
- 'esp-idf'
104101
with:
105102
build-system: 'make'
106103
toolchain: ${{ matrix.toolchain }}
107104
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain]) }}
108105
one-per-family: true
109106

110-
# ---------------------------------------
111-
# Build Make on Windows/MacOS
112-
# ---------------------------------------
113-
make-os:
114-
if: github.event_name == 'pull_request'
115-
uses: ./.github/workflows/build_util.yml
116-
strategy:
117-
fail-fast: false
118-
matrix:
119-
os: [windows-latest, macos-latest]
120-
with:
121-
os: ${{ matrix.os }}
122-
build-system: 'make'
123-
toolchain: 'arm-gcc'
124-
build-args: '["stm32h7"]'
125-
one-per-family: true
126-
127107
# ---------------------------------------
128108
# Build IAR
129109
# Since IAR Token secret is not passed to forked PR, only build non-forked PR with make.
@@ -146,6 +126,23 @@ jobs:
146126
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)['arm-iar']) }}
147127
one-per-family: true
148128

129+
# ---------------------------------------
130+
# Build Make on Windows/MacOS
131+
# ---------------------------------------
132+
make-os:
133+
if: github.event_name == 'pull_request'
134+
uses: ./.github/workflows/build_util.yml
135+
strategy:
136+
fail-fast: false
137+
matrix:
138+
os: [windows-latest, macos-latest]
139+
with:
140+
os: ${{ matrix.os }}
141+
build-system: 'make'
142+
toolchain: 'arm-gcc'
143+
build-args: '["stm32h7"]'
144+
one-per-family: true
145+
149146
# ---------------------------------------
150147
# Zephyr
151148
# ---------------------------------------
@@ -168,14 +165,9 @@ jobs:
168165
west build -b pca10056 -d examples/device/msc_dual_lun/build examples/device/msc_dual_lun -- -DRTOS=zephyr
169166
170167
# ---------------------------------------
171-
#
172168
# Hardware in the loop (HIL)
173169
# Run on PR only (hil-tinyusb), hil-hfp only run on non-forked PR
174170
# ---------------------------------------
175-
176-
# ---------------------------------------
177-
# Build arm-gcc
178-
# ---------------------------------------
179171
hil-build:
180172
if: |
181173
github.repository_owner == 'hathach' &&
@@ -207,17 +199,20 @@ jobs:
207199
runs-on: [self-hosted, X64, hathach, hardware-in-the-loop]
208200
steps:
209201
- name: Clean workspace
202+
if: github.run_attempt == '1'
210203
run: |
211-
echo "Cleaning up previous run"
204+
echo "Cleaning up for the first run"
212205
rm -rf "${{ github.workspace }}"
213206
mkdir -p "${{ github.workspace }}"
214207
215208
- name: Checkout TinyUSB
209+
if: github.run_attempt == '1'
216210
uses: actions/checkout@v4
217211
with:
218212
sparse-checkout: test/hil
219213

220214
- name: Download Artifacts
215+
if: github.run_attempt == '1'
221216
uses: actions/download-artifact@v4
222217
with:
223218
path: cmake-build
@@ -226,7 +221,15 @@ jobs:
226221
- name: Test on actual hardware
227222
run: |
228223
ls cmake-build/
229-
python3 test/hil/hil_test.py ${{ env.HIL_JSON }}
224+
225+
# Skip boards that passed with previous run, file is generated by hil_test.py
226+
SKIP_BOARDS=""
227+
if [ -f ${{ env.HIL_JSON }}.skip ]; then
228+
SKIP_BOARDS=$(cat "${HIL_JSON}.skip")
229+
fi
230+
echo "SKIP_BOARDS=$SKIP_BOARDS"
231+
232+
python3 test/hil/hil_test.py ${{ env.HIL_JSON }} $SKIP_BOARDS
230233
231234
# ---------------------------------------
232235
# Hardware in the loop (HIL)

.github/workflows/ci_set_matrix.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
# family: [supported toolchain]
1717
family_list = {
18+
"at32f402_405 at32f403a_407 at32f413 at32f415 at32f423 at32f425 at32f435_437": ["arm-gcc"],
1819
"broadcom_32bit": ["arm-gcc"],
1920
"broadcom_64bit": ["aarch64-gcc"],
20-
"ch32v10x ch32v20x ch32v307 fomu gd32vf103": ["riscv-gcc"],
21+
"ch32v10x ch32v20x ch32v30x fomu gd32vf103": ["riscv-gcc"],
2122
"da1469x": ["arm-gcc"],
2223
"imxrt": ["arm-gcc", "arm-clang"],
2324
"kinetis_k kinetis_kl kinetis_k32l2": ["arm-gcc", "arm-clang"],
@@ -44,6 +45,7 @@
4445
"stm32l0 stm32l4": ["arm-gcc", "arm-clang", "arm-iar"],
4546
"stm32n6": ["arm-gcc"],
4647
"stm32u5 stm32wb": ["arm-gcc", "arm-clang", "arm-iar"],
48+
"stm32wba": ["arm-gcc", "arm-clang"],
4749
"xmc4000": ["arm-gcc"],
4850
"-bespressif_s2_devkitc": ["esp-idf"],
4951
# S3, P4 will be built by hil test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ RelWithDebInfo
5252
Release
5353
BrowseInfo
5454
.cmake_build
55+
README_processed.rst

0 commit comments

Comments
 (0)