Skip to content

Commit 508fedd

Browse files
committed
Merge tag '0.19.0' into sync/upstream
2 parents d018ab6 + 331c263 commit 508fedd

File tree

652 files changed

+40985
-10653
lines changed

Some content is hidden

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

652 files changed

+40985
-10653
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"
23-
"make aarch64-gcc"
24-
"make arm-gcc"
25-
"make msp430-gcc"
26-
"make riscv-gcc"
27-
"make rx-gcc"
24+
"cmake arm-gcc"
2825
"cmake esp-idf"
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+"

.circleci/config2.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,7 @@ commands:
1010
- run:
1111
name: Set toolchain url and key
1212
command: |
13-
TOOLCHAIN_JSON='{
14-
"aarch64-gcc": "https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz",
15-
"arm-clang": "https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-19.1.1/LLVM-ET-Arm-19.1.1-Linux-x86_64.tar.xz",
16-
"arm-gcc": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-linux-x64.tar.gz",
17-
"msp430-gcc": "http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/9_2_0_0/export/msp430-gcc-9.2.0.50_linux64.tar.bz2",
18-
"riscv-gcc": "https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v13.2.0-2/xpack-riscv-none-elf-gcc-13.2.0-2-linux-x64.tar.gz",
19-
"rx-gcc": "https://github.com/hathach/rx_device/releases/download/0.0.1/gcc-8.3.0.202411-GNURX-ELF.run",
20-
"arm-iar": "https://updates.iar.com/FileStore/STANDARD/001/003/322/cxarm-9.60.3.deb"
21-
}'
22-
toolchain_url=$(echo $TOOLCHAIN_JSON | jq -r '.["<< parameters.toolchain >>"]')
23-
13+
toolchain_url=$(jq -r '."<< parameters.toolchain >>"' .github/actions/setup_toolchain/toolchain.json)
2414
# only cache if not a github link
2515
if [[ $toolchain_url != "https://github.com"* ]]; then
2616
echo "<< parameters.toolchain >>-$toolchain_url" > toolchain_key
@@ -121,7 +111,6 @@ commands:
121111
TOOLCHAIN_OPTION="--toolchain clang"
122112
elif [ << parameters.toolchain >> == arm-iar ]; then
123113
TOOLCHAIN_OPTION="--toolchain iar"
124-
echo IAR_LMS_CLOUD_URL=$IAR_LMS_CLOUD_URL
125114
iccarm --version
126115
elif [ << parameters.toolchain >> == arm-gcc ]; then
127116
TOOLCHAIN_OPTION="--toolchain gcc"

.github/actions/setup_toolchain/action.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ runs:
1717
if: inputs.toolchain == 'arm-gcc'
1818
uses: carlosperate/arm-none-eabi-gcc-action@v1
1919
with:
20-
release: '13.2.Rel1'
20+
release: '14.2.Rel1'
2121

2222
- name: Pull ESP-IDF docker
2323
if: inputs.toolchain == 'esp-idf'
@@ -28,26 +28,17 @@ runs:
2828
- name: Get Toolchain URL
2929
if: >-
3030
inputs.toolchain != 'arm-gcc' &&
31-
inputs.toolchain != 'arm-iar' &&
3231
inputs.toolchain != 'esp-idf'
3332
id: set-toolchain-url
3433
run: |
35-
TOOLCHAIN_JSON='{
36-
"aarch64-gcc": "https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz",
37-
"arm-clang": "https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-19.1.1/LLVM-ET-Arm-19.1.1-Linux-x86_64.tar.xz",
38-
"msp430-gcc": "http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/9_2_0_0/export/msp430-gcc-9.2.0.50_linux64.tar.bz2",
39-
"riscv-gcc": "https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v13.2.0-2/xpack-riscv-none-elf-gcc-13.2.0-2-linux-x64.tar.gz",
40-
"rx-gcc": "https://github.com/hathach/rx_device/releases/download/0.0.1/gcc-8.3.0.202411-GNURX-ELF.run"
41-
}'
42-
TOOLCHAIN_URL=$(echo $TOOLCHAIN_JSON | jq -r '.["${{ inputs.toolchain }}"]')
34+
TOOLCHAIN_URL=$(jq -r '."${{ inputs.toolchain }}"' .github/actions/setup_toolchain/toolchain.json)
4335
echo "toolchain_url=$TOOLCHAIN_URL"
4436
echo "toolchain_url=$TOOLCHAIN_URL" >> $GITHUB_OUTPUT
4537
shell: bash
4638

4739
- name: Download Toolchain
4840
if: >-
4941
inputs.toolchain != 'arm-gcc' &&
50-
inputs.toolchain != 'arm-iar' &&
5142
inputs.toolchain != 'esp-idf'
5243
uses: ./.github/actions/setup_toolchain/download
5344
with:

.github/actions/setup_toolchain/download/action.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,25 @@ runs:
2323
if: steps.cache-toolchain-download.outputs.cache-hit != 'true'
2424
run: |
2525
mkdir -p ~/cache/${{ inputs.toolchain }}
26-
wget --progress=dot:giga ${{ inputs.toolchain_url }} -O toolchain.tar.gz
26+
2727
if [[ ${{ inputs.toolchain }} == rx-gcc ]]; then
28-
mv toolchain.tar.gz toolchain.run
28+
wget --progress=dot:giga ${{ inputs.toolchain_url }} -O toolchain.run
2929
chmod +x toolchain.run
3030
./toolchain.run -p ~/cache/${{ inputs.toolchain }}/gnurx -y
31+
elif [[ ${{ inputs.toolchain }} == arm-iar ]]; then
32+
wget --progress=dot:giga ${{ inputs.toolchain_url }} -O ~/cache/${{ inputs.toolchain }}/cxarm.deb
3133
else
34+
wget --progress=dot:giga ${{ inputs.toolchain_url }} -O toolchain.tar.gz
3235
tar -C ~/cache/${{ inputs.toolchain }} -xaf toolchain.tar.gz
3336
fi
3437
shell: bash
3538

36-
- name: Set Toolchain Path
39+
- name: Setup Toolchain
3740
run: |
38-
echo >> $GITHUB_PATH `echo ~/cache/${{ inputs.toolchain }}/*/bin`
41+
if [[ ${{ inputs.toolchain }} == arm-iar ]]; then
42+
sudo apt-get install -y ~/cache/${{ inputs.toolchain }}/cxarm.deb
43+
echo >> $GITHUB_PATH "/opt/iar/cxarm/arm/bin"
44+
else
45+
echo >> $GITHUB_PATH `echo ~/cache/${{ inputs.toolchain }}/*/bin`
46+
fi
3947
shell: bash
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"aarch64-gcc": "https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz",
3+
"arm-clang": "https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-19.1.1/LLVM-ET-Arm-19.1.1-Linux-x86_64.tar.xz",
4+
"arm-gcc": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v14.2.1-1.1/xpack-arm-none-eabi-gcc-14.2.1-1.1-linux-x64.tar.gz",
5+
"msp430-gcc": "http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/9_2_0_0/export/msp430-gcc-9.2.0.50_linux64.tar.bz2",
6+
"riscv-gcc": "https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v13.2.0-2/xpack-riscv-none-elf-gcc-13.2.0-2-linux-x64.tar.gz",
7+
"rx-gcc": "https://github.com/hathach/rx_device/releases/download/0.0.1/gcc-8.3.0.202411-GNURX-ELF.run",
8+
"arm-iar": "https://netstorage.iar.com/FileStore/STANDARD/001/003/583/cxarm-9.60.4.deb"
9+
}

.github/copilot-instructions.md

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
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=raspberry_pi_pico -DCMAKE_BUILD_TYPE=MinSizeRel ..
22+
cmake --build . -j4
23+
```
24+
-- takes 1-2 seconds. NEVER CANCEL. Set timeout to 5+ minutes.
25+
26+
**CMake with Ninja (Alternative)**
27+
```bash
28+
cd examples/device/cdc_msc
29+
mkdir build && cd build
30+
cmake -G Ninja -DBOARD=raspberry_pi_pico ..
31+
ninja
32+
```
33+
34+
**Option 2: Individual Example with Make**
35+
```bash
36+
cd examples/device/cdc_msc
37+
make BOARD=raspberry_pi_pico all
38+
```
39+
-- takes 2-3 seconds. NEVER CANCEL. Set timeout to 5+ minutes.
40+
41+
**Option 3: All Examples for a Board**
42+
```bash
43+
python3 tools/build.py -b BOARD_NAME
44+
```
45+
-- takes 15-20 seconds, may have some objcopy failures that are non-critical. NEVER CANCEL. Set timeout to 30+ minutes.
46+
47+
### Build Options
48+
- **Debug build**:
49+
- CMake: `-DCMAKE_BUILD_TYPE=Debug`
50+
- Make: `DEBUG=1`
51+
- **With logging**:
52+
- CMake: `-DLOG=2`
53+
- Make: `LOG=2`
54+
- **With RTT logger**:
55+
- CMake: `-DLOG=2 -DLOGGER=rtt`
56+
- Make: `LOG=2 LOGGER=rtt`
57+
- **RootHub port selection**:
58+
- CMake: `-DRHPORT_DEVICE=1`
59+
- Make: `RHPORT_DEVICE=1`
60+
- **Port speed**:
61+
- CMake: `-DRHPORT_DEVICE_SPEED=OPT_MODE_FULL_SPEED`
62+
- Make: `RHPORT_DEVICE_SPEED=OPT_MODE_FULL_SPEED`
63+
64+
### Flashing and Deploymen
65+
- **Flash with JLink**:1
66+
- CMake: `ninja cdc_msc-jlink`
67+
- Make: `make BOARD=raspberry_pi_pico flash-jlink`
68+
- **Flash with OpenOCD**:
69+
- CMake: `ninja cdc_msc-openocd`
70+
- Make: `make BOARD=raspberry_pi_pico flash-openocd`
71+
- **Generate UF2**:
72+
- CMake: `ninja cdc_msc-uf2`
73+
- Make: `make BOARD=raspberry_pi_pico all uf2`
74+
- **List all targets** (CMake/Ninja): `ninja -t targets`
75+
76+
### Unit Testing
77+
- Install Ceedling: `sudo gem install ceedling`
78+
- Run all unit tests: `cd test/unit-test && ceedling` or `cd test/unit-test && ceedling test:all` -- takes 4 seconds. NEVER CANCEL. Set timeout to 10+ minutes.
79+
- Run specific test: `cd test/unit-test && ceedling test:test_fifo`
80+
- Tests use Unity framework with CMock for mocking
81+
82+
### Documentation
83+
- Install requirements: `pip install -r docs/requirements.txt`
84+
- Build docs: `cd docs && sphinx-build -b html . _build` -- takes 2-3 seconds. NEVER CANCEL. Set timeout to 10+ minutes.
85+
86+
### Code Quality and Validation
87+
- Format code: `clang-format -i path/to/file.c` (uses `.clang-format` config)
88+
- Check spelling: `pip install codespell && codespell` (uses `.codespellrc` config)
89+
- Pre-commit hooks validate unit tests and code quality automatically
90+
91+
## Validation
92+
93+
### ALWAYS Run These After Making Changes
94+
1. **Pre-commit validation** (RECOMMENDED): `pre-commit run --all-files`
95+
- Install pre-commit: `pip install pre-commit && pre-commit install`
96+
- Runs all quality checks, unit tests, spell checking, and formatting
97+
- Takes 10-15 seconds. NEVER CANCEL. Set timeout to 15+ minutes.
98+
2. **Build validation**: Build at least one example that exercises your changes
99+
```bash
100+
cd examples/device/cdc_msc
101+
make BOARD=raspberry_pi_pico all
102+
```
103+
104+
### Manual Testing Scenarios
105+
- **Device examples**: Cannot be fully tested without real hardware, but must build successfully
106+
- **Unit tests**: Exercise core stack functionality - ALL tests must pass
107+
- **Build system**: Must be able to build examples for multiple board families
108+
109+
### Board Selection for Testing
110+
- **STM32F4**: `stm32f407disco` - no external SDK required, good for testing
111+
- **RP2040**: `raspberry_pi_pico` - requires Pico SDK, commonly used
112+
- **Other families**: Check `hw/bsp/FAMILY/boards/` for available boards
113+
114+
## Common Tasks and Time Expectations
115+
116+
### Repository Structure Quick Reference
117+
```
118+
├── src/ # Core TinyUSB stack
119+
│ ├── class/ # USB device classes (CDC, HID, MSC, Audio, etc.)
120+
│ ├── portable/ # MCU-specific drivers (organized by vendor)
121+
│ ├── device/ # USB device stack core
122+
│ ├── host/ # USB host stack core
123+
│ └── common/ # Shared utilities (FIFO, etc.)
124+
├── examples/ # Example applications
125+
│ ├── device/ # Device examples (cdc_msc, hid_generic, etc.)
126+
│ ├── host/ # Host examples
127+
│ └── dual/ # Dual-role examples
128+
├── hw/bsp/ # Board Support Packages
129+
│ └── FAMILY/boards/ # Board-specific configurations
130+
├── test/unit-test/ # Unit tests using Ceedling
131+
├── tools/ # Build and utility scripts
132+
└── docs/ # Sphinx documentation
133+
```
134+
135+
### Build Time Reference
136+
- **Dependency fetch**: <1 second
137+
- **Single example build**: 1-3 seconds
138+
- **Unit tests**: ~4 seconds
139+
- **Documentation build**: ~2.5 seconds
140+
- **Full board examples**: 15-20 seconds
141+
- **Toolchain installation**: 2-5 minutes (one-time)
142+
143+
### Key Files to Know
144+
- `tools/get_deps.py`: Manages dependencies for MCU families
145+
- `tools/build.py`: Builds multiple examples, supports make/cmake
146+
- `src/tusb.h`: Main TinyUSB header file
147+
- `src/tusb_config.h`: Configuration template
148+
- `examples/device/cdc_msc/`: Most commonly used example for testing
149+
- `test/unit-test/project.yml`: Ceedling test configuration
150+
151+
### Debugging Build Issues
152+
- **Missing compiler**: Install `gcc-arm-none-eabi` package
153+
- **Missing dependencies**: Run `python3 tools/get_deps.py FAMILY`
154+
- **Board not found**: Check `hw/bsp/FAMILY/boards/` for valid board names
155+
- **objcopy errors**: Often non-critical in full builds, try individual example builds
156+
157+
### Working with USB Device Classes
158+
- **CDC (Serial)**: `src/class/cdc/` - Virtual serial port
159+
- **HID**: `src/class/hid/` - Human Interface Device (keyboard, mouse, etc.)
160+
- **MSC**: `src/class/msc/` - Mass Storage Class (USB drive)
161+
- **Audio**: `src/class/audio/` - USB Audio Class
162+
- Each class has device (`*_device.c`) and host (`*_host.c`) implementations
163+
164+
### MCU Family Support
165+
- **STM32**: Largest support (F0, F1, F2, F3, F4, F7, G0, G4, H7, L4, U5, etc.)
166+
- **Raspberry Pi**: RP2040, RP2350 with PIO-USB host support
167+
- **NXP**: iMXRT, Kinetis, LPC families
168+
- **Microchip**: SAM D/E/G/L families
169+
- Check `hw/bsp/` for complete list and `docs/reference/boards.rst` for details
170+
171+
## Code Style Guidelines
172+
173+
### General Coding Standards
174+
- Use C99 standard
175+
- Memory-safe: no dynamic allocation
176+
- Thread-safe: defer all interrupt events to non-ISR task functions
177+
- 2-space indentation, no tabs
178+
- Use snake_case for variables/functions
179+
- Use UPPER_CASE for macros and constants
180+
- Follow existing variable naming patterns in files you're modifying
181+
- Include proper header comments with MIT license
182+
- Add descriptive comments for non-obvious functions
183+
184+
### Best Practices
185+
- When including headers, group in order: C stdlib, tusb common, drivers, classes
186+
- Always check return values from functions that can fail
187+
- Use TU_ASSERT() for error checking with return statements
188+
- Follow the existing code patterns in the files you're modifying
189+
190+
Remember: TinyUSB is designed for embedded systems - builds are fast, tests are focused, and the codebase is optimized for resource-constrained environments.

0 commit comments

Comments
 (0)