summaryrefslogtreecommitdiff
path: root/.github
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-11-18 10:18:27 +0700
committerhathach <[email protected]>2025-11-18 10:18:27 +0700
commit6c140930591fd49725a1ec1434dfb841560bc6ae (patch)
tree8433576ea573a2f6f5d88ff309716f3ad5538f05 /.github
parent619ef71fdb5da5dbfabe76189ead4ab97837ec12 (diff)
parent66c84528f67c0eedc23d25221500d820e702d93f (diff)
Merge branch 'master' into fork/HiFiPhile/xfer_close
Diffstat (limited to '.github')
-rw-r--r--.github/ISSUE_TEMPLATE/bug_report.yml13
-rw-r--r--.github/actions/get_deps/action.yml9
-rw-r--r--.github/actions/setup_toolchain/action.yml10
-rw-r--r--.github/actions/setup_toolchain/download/action.yml29
-rw-r--r--.github/actions/setup_toolchain/espressif/action.yml14
-rw-r--r--.github/actions/setup_toolchain/toolchain.json2
-rw-r--r--.github/copilot-instructions.md214
-rw-r--r--.github/workflows/build.yml86
-rw-r--r--.github/workflows/build_util.yml3
-rwxr-xr-x.github/workflows/ci_set_matrix.py15
-rw-r--r--.github/workflows/codeql-buildscript.sh6
-rw-r--r--.github/workflows/codeql.yml137
-rwxr-xr-x.github/workflows/fail_on_error.py34
-rw-r--r--.github/workflows/static_analysis.yml242
14 files changed, 563 insertions, 251 deletions
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index d00ee78bd..34e177984 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -24,8 +24,15 @@ body:
- type: input
attributes:
+ label: Commit SHA
+ placeholder: e.g 3a042b37da28d0ba1e5593eb1068ca5645d77b56 or version bundled by esp-idf or pico-sdk
+ validations:
+ required: true
+
+ - type: input
+ attributes:
label: Board
- placeholder: e.g Feather nRF52840 Express
+ placeholder: e.g Adafruit Feather nRF52840 Express
validations:
required: true
@@ -79,8 +86,8 @@ body:
- type: checkboxes
attributes:
- label: I have checked existing issues, dicussion and documentation
+ label: I have checked existing issues, discussion and documentation
description: You agree to check all the resources above before opening a new issue.
options:
- - label: I confirm I have checked existing issues, dicussion and documentation.
+ - label: I confirm I have checked existing issues, discussion and documentation.
required: true
diff --git a/.github/actions/get_deps/action.yml b/.github/actions/get_deps/action.yml
index ae9e7bbef..a84db893b 100644
--- a/.github/actions/get_deps/action.yml
+++ b/.github/actions/get_deps/action.yml
@@ -19,11 +19,16 @@ runs:
- name: Linux dependencies
if: runner.os == 'Linux'
run: |
- sudo apt install -y ninja-build
+ NINJA_URL=https://github.com/ninja-build/ninja/releases/download/v1.13.1/ninja-linux.zip
+ wget $NINJA_URL -O ninja-linux.zip
+ unzip ninja-linux.zip -d ninja-bin
+ echo >> $GITHUB_PATH "${{ github.workspace }}/ninja-bin"
shell: bash
- name: Get Dependencies
+ env:
+ ARG: ${{ inputs.arg }}
run: |
- python3 tools/get_deps.py ${{ inputs.arg }}
+ python3 tools/get_deps.py ${ARG}
echo "PICO_SDK_PATH=${{ github.workspace }}/pico-sdk" >> $GITHUB_ENV
shell: bash
diff --git a/.github/actions/setup_toolchain/action.yml b/.github/actions/setup_toolchain/action.yml
index 6fd5c9d4e..d15a29f20 100644
--- a/.github/actions/setup_toolchain/action.yml
+++ b/.github/actions/setup_toolchain/action.yml
@@ -30,8 +30,10 @@ runs:
inputs.toolchain != 'arm-gcc' &&
inputs.toolchain != 'esp-idf'
id: set-toolchain-url
+ env:
+ TOOLCHAIN: ${{ inputs.toolchain }}
run: |
- TOOLCHAIN_URL=$(jq -r '."${{ inputs.toolchain }}"' .github/actions/setup_toolchain/toolchain.json)
+ TOOLCHAIN_URL=$(jq -r --arg tc "$TOOLCHAIN" '.[$tc]' .github/actions/setup_toolchain/toolchain.json)
echo "toolchain_url=$TOOLCHAIN_URL"
echo "toolchain_url=$TOOLCHAIN_URL" >> $GITHUB_OUTPUT
shell: bash
@@ -47,11 +49,13 @@ runs:
- name: Set toolchain option
id: set-toolchain-option
+ env:
+ TOOLCHAIN: ${{ inputs.toolchain }}
run: |
BUILD_OPTION=""
- if [[ "${{ inputs.toolchain }}" == *"clang"* ]]; then
+ if [[ "$TOOLCHAIN" == *"clang"* ]]; then
BUILD_OPTION="--toolchain clang"
- elif [[ "${{ inputs.toolchain }}" == "arm-iar" ]]; then
+ elif [[ "$TOOLCHAIN" == "arm-iar" ]]; then
BUILD_OPTION="--toolchain iar"
fi
echo "build_option=$BUILD_OPTION"
diff --git a/.github/actions/setup_toolchain/download/action.yml b/.github/actions/setup_toolchain/download/action.yml
index ce9643010..af7a9ad4e 100644
--- a/.github/actions/setup_toolchain/download/action.yml
+++ b/.github/actions/setup_toolchain/download/action.yml
@@ -21,27 +21,34 @@ runs:
- name: Install Toolchain
if: steps.cache-toolchain-download.outputs.cache-hit != 'true'
+ env:
+ TOOLCHAIN: ${{ inputs.toolchain }}
+ TOOLCHAIN_URL: ${{ inputs.toolchain_url }}
run: |
- mkdir -p ~/cache/${{ inputs.toolchain }}
+ mkdir -p ~/cache/${TOOLCHAIN}
- if [[ ${{ inputs.toolchain }} == rx-gcc ]]; then
- wget --progress=dot:giga ${{ inputs.toolchain_url }} -O toolchain.run
+ if [[ ${TOOLCHAIN} == rx-gcc ]]; then
+ wget --progress=dot:giga ${TOOLCHAIN_URL} -O toolchain.run
chmod +x toolchain.run
- ./toolchain.run -p ~/cache/${{ inputs.toolchain }}/gnurx -y
- elif [[ ${{ inputs.toolchain }} == arm-iar ]]; then
- wget --progress=dot:giga ${{ inputs.toolchain_url }} -O ~/cache/${{ inputs.toolchain }}/cxarm.deb
+ ./toolchain.run -p ~/cache/${TOOLCHAIN}/gnurx -y
+ elif [[ ${TOOLCHAIN} == arm-iar ]]; then
+ wget --progress=dot:giga https://netstorage.iar.com/FileStore/STANDARD/001/003/926/iar-lmsc-tools_1.8_amd64.deb -O ~/cache/${TOOLCHAIN}/iar-lmsc-tools.deb
+ wget --progress=dot:giga ${TOOLCHAIN_URL} -O ~/cache/${TOOLCHAIN}/cxarm.deb
else
- wget --progress=dot:giga ${{ inputs.toolchain_url }} -O toolchain.tar.gz
- tar -C ~/cache/${{ inputs.toolchain }} -xaf toolchain.tar.gz
+ wget --progress=dot:giga ${TOOLCHAIN_URL} -O toolchain.tar.gz
+ tar -C ~/cache/${TOOLCHAIN} -xaf toolchain.tar.gz
fi
shell: bash
- name: Setup Toolchain
+ env:
+ TOOLCHAIN: ${{ inputs.toolchain }}
run: |
- if [[ ${{ inputs.toolchain }} == arm-iar ]]; then
- sudo apt-get install -y ~/cache/${{ inputs.toolchain }}/cxarm.deb
+ if [[ ${TOOLCHAIN} == arm-iar ]]; then
+ sudo dpkg -i ~/cache/${TOOLCHAIN}/iar-lmsc-tools.deb
+ sudo apt install -y ~/cache/${TOOLCHAIN}/cxarm.deb
echo >> $GITHUB_PATH "/opt/iar/cxarm/arm/bin"
else
- echo >> $GITHUB_PATH `echo ~/cache/${{ inputs.toolchain }}/*/bin`
+ echo >> $GITHUB_PATH `echo ~/cache/${TOOLCHAIN}/*/bin`
fi
shell: bash
diff --git a/.github/actions/setup_toolchain/espressif/action.yml b/.github/actions/setup_toolchain/espressif/action.yml
index b50ffd41d..e9d645ac8 100644
--- a/.github/actions/setup_toolchain/espressif/action.yml
+++ b/.github/actions/setup_toolchain/espressif/action.yml
@@ -13,8 +13,10 @@ runs:
using: "composite"
steps:
- name: Set DOCKER_ESP_IDF
+ env:
+ TOOLCHAIN: ${{ inputs.toolchain }}
run: |
- DOCKER_ESP_IDF=$HOME/cache/${{ inputs.toolchain }}/docker_image.tar
+ DOCKER_ESP_IDF=$HOME/cache/${TOOLCHAIN}/docker_image.tar
echo "DOCKER_ESP_IDF=$DOCKER_ESP_IDF" >> $GITHUB_ENV
shell: bash
@@ -27,10 +29,12 @@ runs:
- name: Pull and Save Docker Image
if: steps.cache-toolchain-espressif.outputs.cache-hit != 'true'
+ env:
+ TOOLCHAIN_VERSION: ${{ inputs.toolchain_version }}
run: |
- docker pull espressif/idf:${{ inputs.toolchain_version }}
+ docker pull espressif/idf:${TOOLCHAIN_VERSION}
mkdir -p $(dirname $DOCKER_ESP_IDF)
- docker save -o $DOCKER_ESP_IDF espressif/idf:${{ inputs.toolchain_version }}
+ docker save -o $DOCKER_ESP_IDF espressif/idf:${TOOLCHAIN_VERSION}
du -sh $DOCKER_ESP_IDF
shell: bash
@@ -42,7 +46,9 @@ runs:
shell: bash
- name: Tag Local Image
+ env:
+ TOOLCHAIN_VERSION: ${{ inputs.toolchain_version }}
run: |
- docker tag espressif/idf:${{ inputs.toolchain_version }} espressif/idf:tinyusb
+ docker tag espressif/idf:${TOOLCHAIN_VERSION} espressif/idf:tinyusb
docker images
shell: bash
diff --git a/.github/actions/setup_toolchain/toolchain.json b/.github/actions/setup_toolchain/toolchain.json
index f7123ef11..8496dcad3 100644
--- a/.github/actions/setup_toolchain/toolchain.json
+++ b/.github/actions/setup_toolchain/toolchain.json
@@ -5,5 +5,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",
"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",
"rx-gcc": "https://github.com/hathach/rx_device/releases/download/0.0.1/gcc-8.3.0.202411-GNURX-ELF.run",
- "arm-iar": "https://netstorage.iar.com/FileStore/STANDARD/001/003/583/cxarm-9.60.4.deb"
+ "arm-iar": "https://netstorage.iar.com/FileStore/STANDARD/001/003/723/cxarm-9.70.1.deb"
}
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
new file mode 100644
index 000000000..9f9ab7e72
--- /dev/null
+++ b/.github/copilot-instructions.md
@@ -0,0 +1,214 @@
+# TinyUSB
+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.
+
+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.
+
+## Working Effectively
+
+### Bootstrap and Build Setup
+- Install ARM GCC toolchain: `sudo apt-get update && sudo apt-get install -y gcc-arm-none-eabi`
+- Fetch core dependencies: `python3 tools/get_deps.py` -- takes <1 second. NEVER CANCEL.
+- For specific board families: `python3 tools/get_deps.py FAMILY_NAME` (e.g., rp2040, stm32f4)
+- Dependencies are cached in `lib/` and `hw/mcu/` directories
+
+### Build Examples
+Choose ONE of these approaches:
+
+**Option 1: Individual Example with CMake (RECOMMENDED)**
+```bash
+cd examples/device/cdc_msc
+mkdir -p build && cd build
+cmake -DBOARD=raspberry_pi_pico -DCMAKE_BUILD_TYPE=MinSizeRel ..
+cmake --build . -j4
+```
+-- takes 1-2 seconds. NEVER CANCEL. Set timeout to 5+ minutes.
+
+**CMake with Ninja (Alternative)**
+```bash
+cd examples/device/cdc_msc
+mkdir build && cd build
+cmake -G Ninja -DBOARD=raspberry_pi_pico ..
+ninja
+```
+
+**Option 2: Individual Example with Make**
+```bash
+cd examples/device/cdc_msc
+make BOARD=raspberry_pi_pico all
+```
+-- takes 2-3 seconds. NEVER CANCEL. Set timeout to 5+ minutes.
+
+**Option 3: All Examples for a Board**
+```bash
+python3 tools/build.py -b BOARD_NAME
+```
+-- takes 15-20 seconds, may have some objcopy failures that are non-critical. NEVER CANCEL. Set timeout to 30+ minutes.
+
+### Build Options
+- **Debug build**:
+ - CMake: `-DCMAKE_BUILD_TYPE=Debug`
+ - Make: `DEBUG=1`
+- **With logging**:
+ - CMake: `-DLOG=2`
+ - Make: `LOG=2`
+- **With RTT logger**:
+ - CMake: `-DLOG=2 -DLOGGER=rtt`
+ - Make: `LOG=2 LOGGER=rtt`
+- **RootHub port selection**:
+ - CMake: `-DRHPORT_DEVICE=1`
+ - Make: `RHPORT_DEVICE=1`
+- **Port speed**:
+ - CMake: `-DRHPORT_DEVICE_SPEED=OPT_MODE_FULL_SPEED`
+ - Make: `RHPORT_DEVICE_SPEED=OPT_MODE_FULL_SPEED`
+
+### Flashing and Deploymen
+- **Flash with JLink**:1
+ - CMake: `ninja cdc_msc-jlink`
+ - Make: `make BOARD=raspberry_pi_pico flash-jlink`
+- **Flash with OpenOCD**:
+ - CMake: `ninja cdc_msc-openocd`
+ - Make: `make BOARD=raspberry_pi_pico flash-openocd`
+- **Generate UF2**:
+ - CMake: `ninja cdc_msc-uf2`
+ - Make: `make BOARD=raspberry_pi_pico all uf2`
+- **List all targets** (CMake/Ninja): `ninja -t targets`
+
+### Unit Testing
+- Install Ceedling: `sudo gem install ceedling`
+- 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.
+- Run specific test: `cd test/unit-test && ceedling test:test_fifo`
+- Tests use Unity framework with CMock for mocking
+
+### Documentation
+- Install requirements: `pip install -r docs/requirements.txt`
+- Build docs: `cd docs && sphinx-build -b html . _build` -- takes 2-3 seconds. NEVER CANCEL. Set timeout to 10+ minutes.
+
+### Code Quality and Validation
+- Format code: `clang-format -i path/to/file.c` (uses `.clang-format` config)
+- Check spelling: `pip install codespell && codespell` (uses `.codespellrc` config)
+- Pre-commit hooks validate unit tests and code quality automatically
+
+### Static Analysis with PVS-Studio
+- **Analyze whole project**:
+ ```bash
+ pvs-studio-analyzer analyze -f examples/cmake-build-raspberry_pi_pico/compile_commands.json -R .PVS-Studio/.pvsconfig -o pvs-report.log -j12 --dump-files --misra-cpp-version 2008 --misra-c-version 2023 --use-old-parser
+ ```
+- **Analyze specific source files**:
+ ```bash
+ pvs-studio-analyzer analyze -f examples/cmake-build-raspberry_pi_pico/compile_commands.json -R .PVS-Studio/.pvsconfig -S path/to/file.c -o pvs-report.log -j12 --dump-files --misra-cpp-version 2008 --misra-c-version 2023 --use-old-parser
+ ```
+- **Multiple specific files**:
+ ```bash
+ pvs-studio-analyzer analyze -f examples/cmake-build-raspberry_pi_pico/compile_commands.json -R .PVS-Studio/.pvsconfig -S src/file1.c -S src/file2.c -o pvs-report.log -j12 --dump-files --misra-cpp-version 2008 --misra-c-version 2023 --use-old-parser
+ ```
+- Requires `compile_commands.json` in the build directory (generated by CMake with `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`)
+- Use `-f` option to specify path to `compile_commands.json`
+- Use `-R .PVS-Studio/.pvsconfig` to specify rule configuration file
+- Use `-j12` for parallel analysis with 12 threads
+- `--dump-files` saves preprocessed files for debugging
+- `--misra-c-version 2023` enables MISRA C:2023 checks
+- `--misra-cpp-version 2008` enables MISRA C++:2008 checks
+- `--use-old-parser` uses legacy parser for compatibility
+- Analysis takes ~10-30 seconds depending on project size. Set timeout to 5+ minutes.
+- View results: `plog-converter -a GA:1,2 -t errorfile pvs-report.log` or open in PVS-Studio GUI
+
+## Validation
+
+### ALWAYS Run These After Making Changes
+1. **Pre-commit validation** (RECOMMENDED): `pre-commit run --all-files`
+ - Install pre-commit: `pip install pre-commit && pre-commit install`
+ - Runs all quality checks, unit tests, spell checking, and formatting
+ - Takes 10-15 seconds. NEVER CANCEL. Set timeout to 15+ minutes.
+2. **Build validation**: Build at least one example that exercises your changes
+ ```bash
+ cd examples/device/cdc_msc
+ make BOARD=raspberry_pi_pico all
+ ```
+
+### Manual Testing Scenarios
+- **Device examples**: Cannot be fully tested without real hardware, but must build successfully
+- **Unit tests**: Exercise core stack functionality - ALL tests must pass
+- **Build system**: Must be able to build examples for multiple board families
+
+### Board Selection for Testing
+- **STM32F4**: `stm32f407disco` - no external SDK required, good for testing
+- **RP2040**: `raspberry_pi_pico` - requires Pico SDK, commonly used
+- **Other families**: Check `hw/bsp/FAMILY/boards/` for available boards
+
+## Common Tasks and Time Expectations
+
+### Repository Structure Quick Reference
+```
+├── src/ # Core TinyUSB stack
+│ ├── class/ # USB device classes (CDC, HID, MSC, Audio, etc.)
+│ ├── portable/ # MCU-specific drivers (organized by vendor)
+│ ├── device/ # USB device stack core
+│ ├── host/ # USB host stack core
+│ └── common/ # Shared utilities (FIFO, etc.)
+├── examples/ # Example applications
+│ ├── device/ # Device examples (cdc_msc, hid_generic, etc.)
+│ ├── host/ # Host examples
+│ └── dual/ # Dual-role examples
+├── hw/bsp/ # Board Support Packages
+│ └── FAMILY/boards/ # Board-specific configurations
+├── test/unit-test/ # Unit tests using Ceedling
+├── tools/ # Build and utility scripts
+└── docs/ # Sphinx documentation
+```
+
+### Build Time Reference
+- **Dependency fetch**: <1 second
+- **Single example build**: 1-3 seconds
+- **Unit tests**: ~4 seconds
+- **Documentation build**: ~2.5 seconds
+- **Full board examples**: 15-20 seconds
+- **Toolchain installation**: 2-5 minutes (one-time)
+
+### Key Files to Know
+- `tools/get_deps.py`: Manages dependencies for MCU families
+- `tools/build.py`: Builds multiple examples, supports make/cmake
+- `src/tusb.h`: Main TinyUSB header file
+- `src/tusb_config.h`: Configuration template
+- `examples/device/cdc_msc/`: Most commonly used example for testing
+- `test/unit-test/project.yml`: Ceedling test configuration
+
+### Debugging Build Issues
+- **Missing compiler**: Install `gcc-arm-none-eabi` package
+- **Missing dependencies**: Run `python3 tools/get_deps.py FAMILY`
+- **Board not found**: Check `hw/bsp/FAMILY/boards/` for valid board names
+- **objcopy errors**: Often non-critical in full builds, try individual example builds
+
+### Working with USB Device Classes
+- **CDC (Serial)**: `src/class/cdc/` - Virtual serial port
+- **HID**: `src/class/hid/` - Human Interface Device (keyboard, mouse, etc.)
+- **MSC**: `src/class/msc/` - Mass Storage Class (USB drive)
+- **Audio**: `src/class/audio/` - USB Audio Class
+- Each class has device (`*_device.c`) and host (`*_host.c`) implementations
+
+### MCU Family Support
+- **STM32**: Largest support (F0, F1, F2, F3, F4, F7, G0, G4, H7, L4, U5, etc.)
+- **Raspberry Pi**: RP2040, RP2350 with PIO-USB host support
+- **NXP**: iMXRT, Kinetis, LPC families
+- **Microchip**: SAM D/E/G/L families
+- Check `hw/bsp/` for complete list and `docs/reference/boards.rst` for details
+
+## Code Style Guidelines
+
+### General Coding Standards
+- Use C99 standard
+- Memory-safe: no dynamic allocation
+- Thread-safe: defer all interrupt events to non-ISR task functions
+- 2-space indentation, no tabs
+- Use snake_case for variables/functions
+- Use UPPER_CASE for macros and constants
+- Follow existing variable naming patterns in files you're modifying
+- Include proper header comments with MIT license
+- Add descriptive comments for non-obvious functions
+
+### Best Practices
+- When including headers, group in order: C stdlib, tusb common, drivers, classes
+- Always check return values from functions that can fail
+- Use TU_ASSERT() for error checking with return statements
+- Follow the existing code patterns in the files you're modifying
+
+Remember: TinyUSB is designed for embedded systems - builds are fast, tests are focused, and the codebase is optimized for resource-constrained environments.
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 28447cc80..0495ba6a9 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -36,11 +36,6 @@ env:
HIL_JSON: test/hil/tinyusb.json
jobs:
- # ---------------------------------------
- #
- # Build
- #
- # ---------------------------------------
set-matrix:
runs-on: ubuntu-latest
outputs:
@@ -63,28 +58,31 @@ jobs:
echo "hil_matrix=$HIL_MATRIX_JSON" >> $GITHUB_OUTPUT
# ---------------------------------------
- # Build CMake
+ # Build CMake: only build on push with one-per-family.
+ # Full built is done by CircleCI in PR
# ---------------------------------------
cmake:
+ if: github.event_name == 'push'
needs: set-matrix
uses: ./.github/workflows/build_util.yml
strategy:
fail-fast: false
matrix:
toolchain:
- # - 'arm-clang' is built by circle-ci in PR
- 'aarch64-gcc'
+ #- 'arm-clang'
- 'arm-gcc'
+ - 'esp-idf'
- 'msp430-gcc'
- 'riscv-gcc'
with:
build-system: 'cmake'
toolchain: ${{ matrix.toolchain }}
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain]) }}
- one-per-family: ${{ github.event_name == 'push' }}
+ one-per-family: true
# ---------------------------------------
- # Build Make (built by circle-ci in PR, only build on push here)
+ # Build Make: only build on push with one-per-family
# ---------------------------------------
make:
if: github.event_name == 'push'
@@ -94,13 +92,12 @@ jobs:
fail-fast: false
matrix:
toolchain:
- # 'arm-clang'
- - 'arm-gcc'
- 'aarch64-gcc'
+ #- 'arm-clang'
+ - 'arm-gcc'
- 'msp430-gcc'
- 'riscv-gcc'
- 'rx-gcc'
- - 'esp-idf'
with:
build-system: 'make'
toolchain: ${{ matrix.toolchain }}
@@ -108,23 +105,6 @@ jobs:
one-per-family: true
# ---------------------------------------
- # Build Make on Windows/MacOS
- # ---------------------------------------
- make-os:
- if: github.event_name == 'pull_request'
- uses: ./.github/workflows/build_util.yml
- strategy:
- fail-fast: false
- matrix:
- os: [windows-latest, macos-latest]
- with:
- os: ${{ matrix.os }}
- build-system: 'make'
- toolchain: 'arm-gcc'
- build-args: '["stm32h7"]'
- one-per-family: true
-
- # ---------------------------------------
# Build IAR
# Since IAR Token secret is not passed to forked PR, only build non-forked PR with make.
# cmake is built by circle-ci. Due to IAR limit capacity, only build oe per family
@@ -147,6 +127,23 @@ jobs:
one-per-family: true
# ---------------------------------------
+ # Build Make on Windows/MacOS
+ # ---------------------------------------
+ make-os:
+ if: github.event_name == 'pull_request'
+ uses: ./.github/workflows/build_util.yml
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [windows-latest, macos-latest]
+ with:
+ os: ${{ matrix.os }}
+ build-system: 'make'
+ toolchain: 'arm-gcc'
+ build-args: '["stm32h7"]'
+ one-per-family: true
+
+ # ---------------------------------------
# Zephyr
# ---------------------------------------
zephyr:
@@ -164,18 +161,13 @@ jobs:
- name: Build
run: |
- west build -b pca10056 -d examples/device/cdc_msc/build examples/device/cdc_msc -- -DRTOS=zephyr
- west build -b pca10056 -d examples/device/msc_dual_lun/build examples/device/msc_dual_lun -- -DRTOS=zephyr
+ west build -b nrf52840dk -d examples/device/cdc_msc/build examples/device/cdc_msc -- -DRTOS=zephyr
+ west build -b nrf52840dk -d examples/device/msc_dual_lun/build examples/device/msc_dual_lun -- -DRTOS=zephyr
# ---------------------------------------
- #
# Hardware in the loop (HIL)
# Run on PR only (hil-tinyusb), hil-hfp only run on non-forked PR
# ---------------------------------------
-
- # ---------------------------------------
- # Build arm-gcc
- # ---------------------------------------
hil-build:
if: |
github.repository_owner == 'hathach' &&
@@ -206,27 +198,35 @@ jobs:
needs: hil-build
runs-on: [self-hosted, X64, hathach, hardware-in-the-loop]
steps:
+ - name: Get Skip Boards from previous run
+ if: github.run_attempt != '1'
+ run: |
+ if [ -f "${{ env.HIL_JSON }}.skip" ]; then
+ SKIP_BOARDS=$(cat "${{ env.HIL_JSON }}.skip")
+ else
+ SKIP_BOARDS=""
+ fi
+ echo "SKIP_BOARDS=$SKIP_BOARDS"
+ echo "SKIP_BOARDS=$SKIP_BOARDS" >> $GITHUB_ENV
+
- name: Clean workspace
run: |
- echo "Cleaning up previous run"
+ echo "Cleaning up for the first run"
rm -rf "${{ github.workspace }}"
mkdir -p "${{ github.workspace }}"
- name: Checkout TinyUSB
uses: actions/checkout@v4
- with:
- sparse-checkout: test/hil
- name: Download Artifacts
- uses: actions/download-artifact@v4
+ uses: actions/download-artifact@v5
with:
path: cmake-build
merge-multiple: true
- name: Test on actual hardware
run: |
- ls cmake-build/
- python3 test/hil/hil_test.py ${{ env.HIL_JSON }}
+ python3 test/hil/hil_test.py ${{ env.HIL_JSON }} $SKIP_BOARDS
# ---------------------------------------
# Hardware in the loop (HIL)
@@ -266,7 +266,7 @@ jobs:
run: python3 tools/get_deps.py $BUILD_ARGS
- name: Build
- run: python3 tools/build.py --toolchain iar $BUILD_ARGS
+ run: python3 tools/build.py -j 4 --toolchain iar $BUILD_ARGS
- name: Test on actual hardware (hardware in the loop)
run: python3 test/hil/hil_test.py hfp.json
diff --git a/.github/workflows/build_util.yml b/.github/workflows/build_util.yml
index a2c96f3c0..55901b838 100644
--- a/.github/workflows/build_util.yml
+++ b/.github/workflows/build_util.yml
@@ -60,8 +60,9 @@ jobs:
- name: Build
env:
IAR_LMS_BEARER_TOKEN: ${{ secrets.IAR_LMS_BEARER_TOKEN }}
+ TOOLCHAIN: ${{ inputs.toolchain }}
run: |
- if [ "${{ inputs.toolchain }}" == "esp-idf" ]; then
+ if [ "$TOOLCHAIN" == "esp-idf" ]; then
docker run --rm -v $PWD:/project -w /project espressif/idf:tinyusb python tools/build.py ${{ matrix.arg }}
else
python tools/build.py -s ${{ inputs.build-system }} ${{ steps.setup-toolchain.outputs.build_option }} ${{ steps.set-one-per-family.outputs.build_option }} ${{ matrix.arg }}
diff --git a/.github/workflows/ci_set_matrix.py b/.github/workflows/ci_set_matrix.py
index fa73dc1b6..3789b4116 100755
--- a/.github/workflows/ci_set_matrix.py
+++ b/.github/workflows/ci_set_matrix.py
@@ -15,34 +15,37 @@ toolchain_list = [
# family: [supported toolchain]
family_list = {
+ "at32f402_405 at32f403a_407 at32f413 at32f415 at32f423 at32f425 at32f435_437": ["arm-gcc"],
"broadcom_32bit": ["arm-gcc"],
"broadcom_64bit": ["aarch64-gcc"],
- "ch32v10x ch32v20x ch32v307 fomu gd32vf103": ["riscv-gcc"],
+ "ch32v10x ch32v20x ch32v30x fomu gd32vf103": ["riscv-gcc"],
"da1469x": ["arm-gcc"],
"imxrt": ["arm-gcc", "arm-clang"],
"kinetis_k kinetis_kl kinetis_k32l2": ["arm-gcc", "arm-clang"],
"lpc11 lpc13 lpc15": ["arm-gcc", "arm-clang"],
"lpc17 lpc18 lpc40 lpc43": ["arm-gcc", "arm-clang"],
"lpc51 lpc54 lpc55": ["arm-gcc", "arm-clang"],
- "max32650 max32666 max32690 max78002": ["arm-gcc"],
+ "maxim": ["arm-gcc"],
"mcx": ["arm-gcc"],
"mm32": ["arm-gcc"],
"msp430": ["msp430-gcc"],
"msp432e4 tm4c": ["arm-gcc"],
"nrf": ["arm-gcc", "arm-clang"],
+ "nuc100_120 nuc121_125 nuc126 nuc505": ["arm-gcc"],
"ra": ["arm-gcc"],
"rp2040": ["arm-gcc"],
"rx": ["rx-gcc"],
- "samd11 saml2x": ["arm-gcc", "arm-clang"],
- "samd21": ["arm-gcc", "arm-clang"],
+ "samd11 samd2x_l2x": ["arm-gcc", "arm-clang"],
"samd5x_e5x samg": ["arm-gcc", "arm-clang"],
"stm32c0 stm32f0 stm32f1 stm32f2 stm32f3": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32f4": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32f7": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32g0 stm32g4 stm32h5": ["arm-gcc", "arm-clang", "arm-iar"],
- "stm32h7": ["arm-gcc", "arm-clang", "arm-iar"],
+ "stm32h7 stm32h7rs": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32l0 stm32l4": ["arm-gcc", "arm-clang", "arm-iar"],
- "stm32u5 stm32wb": ["arm-gcc", "arm-clang", "arm-iar"],
+ "stm32n6": ["arm-gcc"],
+ "stm32u0 stm32u5 stm32wb": ["arm-gcc", "arm-clang", "arm-iar"],
+ "stm32wba": ["arm-gcc", "arm-clang"],
"xmc4000": ["arm-gcc"],
"-bespressif_s2_devkitc": ["esp-idf"],
# S3, P4 will be built by hil test
diff --git a/.github/workflows/codeql-buildscript.sh b/.github/workflows/codeql-buildscript.sh
deleted file mode 100644
index 272b55d22..000000000
--- a/.github/workflows/codeql-buildscript.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/usr/bin/env bash
-
-FAMILY=stm32l4
-pip install click
-python3 tools/get_deps.py $FAMILY
-python3 tools/build.py -s make $FAMILY
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
deleted file mode 100644
index a22c65c79..000000000
--- a/.github/workflows/codeql.yml
+++ /dev/null
@@ -1,137 +0,0 @@
-# For most projects, this workflow file will not need changing; you simply need
-# to commit it to your repository.
-#
-# You may wish to alter this file to override the set of languages analyzed,
-# or to provide custom queries or build logic.
-#
-# ******** NOTE ********
-# We have attempted to detect the languages in your repository. Please check
-# the `language` matrix defined below to confirm you have the correct set of
-# supported CodeQL languages.
-#
-name: "CodeQL"
-
-on:
- push:
- branches: [ 'master' ]
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/codeql.yml'
- pull_request:
- branches: [ 'master' ]
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/codeql.yml'
- schedule:
- - cron: '0 0 * * *'
-
-jobs:
- analyze:
- name: Analyze
- # Runner size impacts CodeQL analysis time. To learn more, please see:
- # - https://gh.io/recommended-hardware-resources-for-running-codeql
- # - https://gh.io/supported-runners-and-hardware-resources
- # - https://gh.io/using-larger-runners
- # Consider using larger runners for possible analysis time improvements.
- runs-on: ubuntu-latest
- timeout-minutes: 360
- permissions:
- actions: read
- contents: read
- security-events: write
-
- strategy:
- fail-fast: false
- matrix:
- language: [ 'c-cpp' ]
- # CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
- # Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
- # Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
- # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v4
-
- - name: Setup Toolchain
- uses: ./.github/actions/setup_toolchain
- with:
- toolchain: 'arm-gcc'
-
- # Initializes the CodeQL tools for scanning.
- - name: Initialize CodeQL
- uses: github/codeql-action/init@v3
- with:
- languages: ${{ matrix.language }}
- # If you wish to specify custom queries, you can do so here or in a config file.
- # By default, queries listed here will override any specified in a config file.
- # Prefix the list here with "+" to use these queries and those in the config file.
-
- # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
- # queries: security-extended,security-and-quality
- queries: security-and-quality
-
-
- # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
- # If this step fails, then you should remove it and run the build manually (see below)
- #- name: Autobuild
- # uses: github/codeql-action/autobuild@v2
-
- # ℹ️ Command-line programs to run using the OS shell.
- # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
-
- # If the Autobuild fails above, remove it and uncomment the following three lines.
- # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
-
- - run: |
- ./.github/workflows/codeql-buildscript.sh
-
- - name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@v3
- with:
- category: "/language:${{matrix.language}}"
- upload: false
- id: step1
-
- # Filter out rules with low severity or high false positive rate
- # Also filter out warnings in third-party code
- - name: Filter out unwanted errors and warnings
- uses: advanced-security/filter-sarif@v1
- with:
- patterns: |
- -**:cpp/path-injection
- -**:cpp/world-writable-file-creation
- -**:cpp/poorly-documented-function
- -**:cpp/potentially-dangerous-function
- -**:cpp/use-of-goto
- -**:cpp/integer-multiplication-cast-to-long
- -**:cpp/comparison-with-wider-type
- -**:cpp/leap-year/*
- -**:cpp/ambiguously-signed-bit-field
- -**:cpp/suspicious-pointer-scaling
- -**:cpp/suspicious-pointer-scaling-void
- -**:cpp/unsigned-comparison-zero
- -**/third*party/**
- -**/3rd*party/**
- -**/external/**
- input: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
- output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
-
- - name: Upload SARIF
- uses: github/codeql-action/upload-sarif@v2
- with:
- sarif_file: ${{ steps.step1.outputs.sarif-output }}
- category: "/language:${{matrix.language}}"
-
- - name: Upload CodeQL results as an artifact
- uses: actions/upload-artifact@v4
- with:
- name: codeql-results
- path: ${{ steps.step1.outputs.sarif-output }}
- retention-days: 5
diff --git a/.github/workflows/fail_on_error.py b/.github/workflows/fail_on_error.py
deleted file mode 100755
index 29791742b..000000000
--- a/.github/workflows/fail_on_error.py
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/env python3
-
-import json
-import sys
-
-# Return whether SARIF file contains error-level results
-def codeql_sarif_contain_error(filename):
- with open(filename, 'r') as f:
- s = json.load(f)
-
- for run in s.get('runs', []):
- rules_metadata = run['tool']['driver']['rules']
- if not rules_metadata:
- rules_metadata = run['tool']['extensions'][0]['rules']
-
- for res in run.get('results', []):
- if 'ruleIndex' in res:
- rule_index = res['ruleIndex']
- elif 'rule' in res and 'index' in res['rule']:
- rule_index = res['rule']['index']
- else:
- continue
- try:
- rule_level = rules_metadata[rule_index]['defaultConfiguration']['level']
- except IndexError as e:
- print(e, rule_index, len(rules_metadata))
- else:
- if rule_level == 'error':
- return True
- return False
-
-if __name__ == "__main__":
- if codeql_sarif_contain_error(sys.argv[1]):
- sys.exit(1)
diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml
new file mode 100644
index 000000000..4db267517
--- /dev/null
+++ b/.github/workflows/static_analysis.yml
@@ -0,0 +1,242 @@
+name: Static Analysis
+on:
+ workflow_dispatch:
+ push:
+ branches: [ master ]
+ paths:
+ - 'src/**'
+ - 'examples/**'
+ - 'hw/bsp/**'
+ - '.github/workflows/static_analysis.yml'
+ pull_request:
+ branches: [ master ]
+ paths:
+ - 'src/**'
+ - 'examples/**'
+ - 'hw/bsp/**'
+ - '.github/workflows/static_analysis.yml'
+
+permissions:
+ actions: read
+ contents: read
+ security-events: write
+# pull-requests: write
+# checks: write
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ CodeQL:
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ board:
+ - 'metro_m4_express'
+ steps:
+ - name: Checkout TinyUSB
+ uses: actions/checkout@v4
+
+ - name: Get Dependencies
+ uses: ./.github/actions/get_deps
+ with:
+ arg: -b${{ matrix.board }}
+
+ - name: Setup Toolchain
+ uses: ./.github/actions/setup_toolchain
+ with:
+ toolchain: 'arm-gcc'
+
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v4
+ with:
+ languages: 'c-cpp'
+ queries: security-and-quality
+
+ - name: Build
+ run: |
+ mkdir -p build
+ cmake examples -B build -G Ninja -DBOARD=${{ matrix.board }} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=MinSizeRel
+ cmake --build build
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v4
+ with:
+ category: CodeQL
+ upload: false
+ id: analyze
+
+ - name: Filter SARIF report
+ uses: advanced-security/filter-sarif@v1
+ with:
+ patterns: |
+ -hw/mcu/**
+ -lib/**
+ input: ${{ steps.analyze.outputs.sarif-output }}/cpp.sarif
+ output: ${{ steps.analyze.outputs.sarif-output }}/cpp.sarif
+
+ - name: Upload SARIF
+ uses: github/codeql-action/upload-sarif@v4
+ with:
+ sarif_file: ${{ steps.analyze.outputs.sarif-output }}
+ category: CodeQL
+
+ - name: Upload artifact
+ uses: actions/upload-artifact@v5
+ with:
+ name: codeql-${{ matrix.board }}
+ path: ${{ steps.analyze.outputs.sarif-output }}
+
+ PVS-Studio:
+ # Only run on non-forked PR since secrets token is required
+ if: github.repository_owner == 'hathach' && github.event.pull_request.head.repo.fork == false
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ board:
+ - 'raspberry_pi_pico'
+ steps:
+ - name: Checkout TinyUSB
+ uses: actions/checkout@v4
+
+ - name: Get Dependencies
+ uses: ./.github/actions/get_deps
+ with:
+ arg: -b${{ matrix.board }}
+
+ - name: Setup Toolchain
+ uses: ./.github/actions/setup_toolchain
+ with:
+ toolchain: 'arm-gcc'
+
+ - name: Install Tools
+ run: |
+ wget -q -O - https://files.pvs-studio.com/etc/pubkey.txt | sudo apt-key add -
+ sudo wget -O /etc/apt/sources.list.d/viva64.list https://files.pvs-studio.com/etc/viva64.list
+ sudo apt update
+ sudo apt install pvs-studio
+ pvs-studio-analyzer credentials ${{ secrets.PVS_STUDIO_CREDENTIALS }}
+ pvs-studio-analyzer --version
+
+ - name: Analyze
+ run: |
+ mkdir -p build
+ cmake examples -B build -G Ninja -DBOARD=${{ matrix.board }} -DCMAKE_BUILD_TYPE=MinSizeRel
+ cmake --build build
+ pvs-studio-analyzer analyze -f build/compile_commands.json -R .PVS-Studio/.pvsconfig -j4 --security-related-issues --misra-cpp-version 2008 --misra-c-version 2023 --use-old-parser -e lib/ -e hw/mcu/ -e */iar/cxarm/ -e pico-sdk/
+ plog-converter -t sarif -o pvs-studio-${{ matrix.board }}.sarif PVS-Studio.log
+
+ - name: Upload SARIF
+ uses: github/codeql-action/upload-sarif@v4
+ with:
+ sarif_file: pvs-studio-${{ matrix.board }}.sarif
+ category: PVS-Studio
+
+ - name: Upload artifact
+ uses: actions/upload-artifact@v5
+ with:
+ name: pvs-studio-${{ matrix.board }}
+ path: pvs-studio-${{ matrix.board }}.sarif
+
+ SonarQube:
+ # Only run on non-forked PR since secrets token is required
+ if: github.repository_owner == 'hathach' && github.event.pull_request.head.repo.fork == false
+ runs-on: ubuntu-latest
+ env:
+ BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
+ strategy:
+ fail-fast: false
+ matrix:
+ board:
+ - 'stm32h743eval'
+ steps:
+ - name: Checkout TinyUSB
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
+
+ - name: Get Dependencies
+ uses: ./.github/actions/get_deps
+ with:
+ arg: -b${{ matrix.board }}
+
+ - name: Setup Toolchain
+ uses: ./.github/actions/setup_toolchain
+ with:
+ toolchain: 'arm-gcc'
+
+ - name: Install Build Wrapper
+ uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v6
+
+ - name: Run Build Wrapper
+ run: |
+ cmake examples -B build -G Ninja -DBOARD=${{ matrix.board }} -DCMAKE_BUILD_TYPE=MinSizeRel
+ build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/
+
+ - name: SonarQube Scan
+ uses: SonarSource/sonarqube-scan-action@v6
+ env:
+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
+ with:
+ # Consult https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/scanners/sonarscanner/ for more information and options
+ args: >
+ --define sonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json
+
+ IAR-CStat:
+ # Only run on non-forked PR since secrets token is required
+ #if: github.repository_owner == 'hathach' && github.event.pull_request.head.repo.fork == false
+ if: false
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ board:
+ - 'b_g474e_dpow1'
+ steps:
+ - name: Checkout TinyUSB
+ uses: actions/checkout@v4
+
+ - name: Get Dependencies
+ uses: ./.github/actions/get_deps
+ with:
+ arg: -b${{ matrix.board }}
+
+ - name: Setup Toolchain
+ uses: ./.github/actions/setup_toolchain
+ with:
+ toolchain: 'arm-iar'
+
+ - name: Install CMake 4.2
+ run: |
+ # IAR CSTAT requires CMake >= 4.1
+ wget -q https://github.com/Kitware/CMake/releases/download/v4.2.0-rc1/cmake-4.2.0-rc1-linux-x86_64.tar.gz
+ tar -xzf cmake-4.2.0-rc1-linux-x86_64.tar.gz
+ echo "${{ github.workspace }}/cmake-4.2.0-rc1-linux-x86_64/bin" >> $GITHUB_PATH
+
+ - name: Build and run IAR C-STAT Analysis
+ env:
+ IAR_LMS_BEARER_TOKEN: ${{ secrets.IAR_LMS_BEARER_TOKEN }}
+ run: |
+ # CMake run post build to generate C-STAT SARIF report
+ cmake --version
+ mkdir -p build
+ cmake examples/device/cdc_msc -B build -G Ninja -DBOARD=${{ matrix.board }} -DTOOLCHAIN=iar -DIAR_CSTAT=1 -DCMAKE_BUILD_TYPE=MinSizeRel
+ cmake --build build
+ # Merge sarif files for codeql upload
+ npm i -g @microsoft/sarif-multitool
+ npx @microsoft/sarif-multitool merge --merge-runs --output-file iar-cstat-${{ matrix.board }}.sarif build/cstat_sarif/*.sarif
+
+ - name: Upload SARIF
+ uses: github/codeql-action/upload-sarif@v4
+ with:
+ sarif_file: iar-cstat-${{ matrix.board }}.sarif
+ category: IAR-CStat
+
+ - name: Upload artifact
+ uses: actions/upload-artifact@v5
+ with:
+ name: iar-cstat-${{ matrix.board }}
+ path: iar-cstat-${{ matrix.board }}.sarif