Skip to content

Commit ac903db

Browse files
committed
Merge remote-tracking branch 'tinyusb/master' into embedded-ideas/master
Signed-off-by: Mengsk <[email protected]>
2 parents 6b3970d + fc5415b commit ac903db

File tree

152 files changed

+7800
-5074
lines changed

Some content is hidden

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

152 files changed

+7800
-5074
lines changed

.PVS-Studio/.pvsconfig

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
//-V::2506,2514
1+
//V_EXCLUDE_PATH */iar/cxarm*
2+
//V_EXCLUDE_PATH */pico-sdk/*
3+
//V_EXCLUDE_PATH */esp-idf/*
4+
//V_EXCLUDE_PATH */hw/mcu/*
5+
//V_EXCLUDE_PATH */hw/bsp/espressif/components/*
6+
//V_EXCLUDE_PATH */lib/*
7+
8+
//-V::2506 MISRA. A function should have a single point of exit at the end.
9+
//-V::2514 MISRA. Unions should not be used.
10+
//-V::2520 [MISRA-C-16.3] Every switch-clause should be terminated by an unconditional 'break' statement
11+
//-V:memcpy:2547 [MISRA-C-17.7] The return value of non-void function 'memcpy' should be used.
12+
//-V:memmove:2547 [MISRA-C-17.7] The return value of non-void function 'memmove' should be used.
13+
//-V:printf:2547 [MISRA-C-17.7]
14+
//-V::2584::{gintsts} dwc2
15+
//-V::2600 [MISRA-C-21.6] The function with the 'printf' name should not be used.
16+
//+V2614 DISABLE_LENGHT_LIMIT_CHECK:YES
17+
//-V:memcpy:2628 Pointer arguments to the 'memcpy' function should be pointers to qualified or unqualified versions of compatible types.
18+
//-V::2659 [MISRA-C-16.1] Switch statements should be well-formed. Every switch-clause should be terminated by an unconditional 'break' statement

.clang-format

Lines changed: 70 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,99 @@
1-
# Generated from CLion C/C++ Code Style settings
1+
---
2+
Language: Cpp
23
BasedOnStyle: LLVM
3-
AccessModifierOffset: -2
44
AlignAfterOpenBracket: Align
5-
AlignConsecutiveAssignments: None
6-
AlignOperands: Align
5+
AlignConsecutiveAssignments:
6+
Enabled: true
7+
AcrossEmptyLines: false
8+
AcrossComments: false
9+
AlignConsecutiveBitFields:
10+
Enabled: true
11+
AcrossEmptyLines: false
12+
AcrossComments: false
13+
AlignConsecutiveDeclarations:
14+
Enabled: true
15+
AcrossEmptyLines: false
16+
AcrossComments: false
17+
AlignConsecutiveMacros:
18+
Enabled: true
19+
AcrossEmptyLines: true
20+
AcrossComments: false
21+
AlignConsecutiveShortCaseStatements:
22+
Enabled: true
23+
AcrossEmptyLines: true
24+
AcrossComments: true
25+
AlignCaseColons: false
26+
AlignEscapedNewlines: LeftWithLastLine
27+
AlignOperands: true
28+
AlignTrailingComments:
29+
Kind: Always
30+
OverEmptyLines: 2
731
AllowAllArgumentsOnNextLine: false
832
AllowAllConstructorInitializersOnNextLine: false
933
AllowAllParametersOfDeclarationOnNextLine: false
10-
AllowShortBlocksOnASingleLine: Always
34+
AllowShortBlocksOnASingleLine: Empty
35+
AllowShortCaseExpressionOnASingleLine: true
1136
AllowShortCaseLabelsOnASingleLine: false
12-
AllowShortFunctionsOnASingleLine: All
13-
AllowShortIfStatementsOnASingleLine: Always
14-
AllowShortLambdasOnASingleLine: All
15-
AllowShortLoopsOnASingleLine: true
16-
AlwaysBreakAfterReturnType: None
37+
AllowShortEnumsOnASingleLine: false
38+
AllowShortFunctionsOnASingleLine: None
39+
AllowShortIfStatementsOnASingleLine: Never
1740
AlwaysBreakTemplateDeclarations: Yes
41+
BinPackArguments: true
1842
BreakBeforeBraces: Custom
1943
BraceWrapping:
2044
AfterCaseLabel: false
2145
AfterClass: false
22-
AfterControlStatement: Never
46+
AfterControlStatement: false
2347
AfterEnum: false
2448
AfterFunction: false
2549
AfterNamespace: false
50+
AfterStruct: false
2651
AfterUnion: false
27-
BeforeCatch: false
52+
AfterExternBlock: false
53+
BeforeCatch: true
2854
BeforeElse: false
29-
IndentBraces: false
30-
SplitEmptyFunction: false
55+
BeforeLambdaBody: false
56+
BeforeWhile: false
57+
SplitEmptyFunction: true
3158
SplitEmptyRecord: true
59+
SplitEmptyNamespace: true
60+
BracedInitializerIndentWidth: 2
3261
BreakBeforeBinaryOperators: None
33-
BreakBeforeTernaryOperators: true
34-
BreakConstructorInitializers: BeforeColon
35-
BreakInheritanceList: BeforeColon
36-
ColumnLimit: 0
37-
CompactNamespaces: false
38-
ContinuationIndentWidth: 4
39-
IndentCaseLabels: true
62+
BreakConstructorInitializers: AfterColon
63+
BreakConstructorInitializersBeforeComma: false
64+
ContinuationIndentWidth: 2
65+
ColumnLimit: 120
66+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
67+
Cpp11BracedListStyle: true
68+
IncludeBlocks: Preserve
69+
IncludeCategories:
70+
- Regex: '^<.*'
71+
Priority: 1
72+
- Regex: '^".*'
73+
Priority: 2
74+
- Regex: '.*'
75+
Priority: 3
76+
IncludeIsMainRegex: '([-_](test|unittest))?$'
4077
IndentPPDirectives: BeforeHash
41-
IndentWidth: 2
42-
KeepEmptyLinesAtTheStartOfBlocks: true
78+
InsertBraces: true
79+
IndentCaseLabels: true
80+
InsertNewlineAtEOF: true
81+
MacroBlockBegin: ''
82+
MacroBlockEnd: ''
4383
MaxEmptyLinesToKeep: 2
4484
NamespaceIndentation: All
45-
ObjCSpaceAfterProperty: false
46-
ObjCSpaceBeforeProtocolList: true
47-
PointerAlignment: Right
85+
PenaltyBreakBeforeFirstCallParameter: 1000000
86+
PenaltyBreakOpenParenthesis: 1000000
87+
QualifierAlignment: Custom
88+
QualifierOrder: ['static', 'const', 'volatile', 'restrict', 'type']
4889
ReflowComments: false
49-
SpaceAfterCStyleCast: true
50-
SpaceAfterLogicalNot: false
5190
SpaceAfterTemplateKeyword: false
52-
SpaceBeforeAssignmentOperators: true
53-
SpaceBeforeCpp11BracedList: false
54-
SpaceBeforeCtorInitializerColon: true
55-
SpaceBeforeInheritanceColon: true
56-
SpaceBeforeParens: ControlStatements
5791
SpaceBeforeRangeBasedForLoopColon: false
5892
SpaceInEmptyParentheses: false
59-
SpacesBeforeTrailingComments: 0
6093
SpacesInAngles: false
94+
SpacesInConditionalStatement: false
6195
SpacesInCStyleCastParentheses: false
62-
SpacesInContainerLiterals: true
6396
SpacesInParentheses: false
64-
SpacesInSquareBrackets: false
97+
SortIncludes: false
6598
TabWidth: 2
66-
UseTab: Never
99+
...

.github/copilot-instructions.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,30 @@ python3 tools/build.py -b BOARD_NAME
8888
- Check spelling: `pip install codespell && codespell` (uses `.codespellrc` config)
8989
- Pre-commit hooks validate unit tests and code quality automatically
9090

91+
### Static Analysis with PVS-Studio
92+
- **Analyze whole project**:
93+
```bash
94+
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
95+
```
96+
- **Analyze specific source files**:
97+
```bash
98+
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
99+
```
100+
- **Multiple specific files**:
101+
```bash
102+
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
103+
```
104+
- Requires `compile_commands.json` in the build directory (generated by CMake with `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`)
105+
- Use `-f` option to specify path to `compile_commands.json`
106+
- Use `-R .PVS-Studio/.pvsconfig` to specify rule configuration file
107+
- Use `-j12` for parallel analysis with 12 threads
108+
- `--dump-files` saves preprocessed files for debugging
109+
- `--misra-c-version 2023` enables MISRA C:2023 checks
110+
- `--misra-cpp-version 2008` enables MISRA C++:2008 checks
111+
- `--use-old-parser` uses legacy parser for compatibility
112+
- Analysis takes ~10-30 seconds depending on project size. Set timeout to 5+ minutes.
113+
- View results: `plog-converter -a GA:1,2 -t errorfile pvs-report.log` or open in PVS-Studio GUI
114+
91115
## Validation
92116

93117
### ALWAYS Run These After Making Changes

.github/workflows/build_util.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ jobs:
6060
- name: Build
6161
env:
6262
IAR_LMS_BEARER_TOKEN: ${{ secrets.IAR_LMS_BEARER_TOKEN }}
63+
TOOLCHAIN: ${{ inputs.toolchain }}
6364
run: |
64-
if [ "${{ inputs.toolchain }}" == "esp-idf" ]; then
65+
if [ "$TOOLCHAIN" == "esp-idf" ]; then
6566
docker run --rm -v $PWD:/project -w /project espressif/idf:tinyusb python tools/build.py ${{ matrix.arg }}
6667
else
6768
python tools/build.py -s ${{ inputs.build-system }} ${{ steps.setup-toolchain.outputs.build_option }} ${{ steps.set-one-per-family.outputs.build_option }} ${{ matrix.arg }}

.github/workflows/static_analysis.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ jobs:
9090
path: ${{ steps.analyze.outputs.sarif-output }}
9191

9292
PVS-Studio:
93-
if: github.repository_owner == 'hathach'
93+
# Only run on non-forked PR since secrets token is required
94+
if: github.repository_owner == 'hathach' && github.event.pull_request.head.repo.fork == false
9495
runs-on: ubuntu-latest
9596
strategy:
9697
fail-fast: false
@@ -118,13 +119,14 @@ jobs:
118119
sudo apt update
119120
sudo apt install pvs-studio
120121
pvs-studio-analyzer credentials ${{ secrets.PVS_STUDIO_CREDENTIALS }}
122+
pvs-studio-analyzer --version
121123
122124
- name: Analyze
123125
run: |
124126
mkdir -p build
125127
cmake examples -B build -G Ninja -DBOARD=${{ matrix.board }} -DCMAKE_BUILD_TYPE=MinSizeRel
126128
cmake --build build
127-
pvs-studio-analyzer analyze -R .PVS-Studio/.pvsconfig -f build/compile_commands.json --exclude-path hw/mcu/ --exclude-path lib/ -j
129+
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/
128130
plog-converter -t sarif -o pvs-studio-${{ matrix.board }}.sarif PVS-Studio.log
129131
130132
- name: Upload SARIF
@@ -140,7 +142,8 @@ jobs:
140142
path: pvs-studio-${{ matrix.board }}.sarif
141143

142144
SonarQube:
143-
if: github.repository_owner == 'hathach'
145+
# Only run on non-forked PR since secrets token is required
146+
if: github.repository_owner == 'hathach' && github.event.pull_request.head.repo.fork == false
144147
runs-on: ubuntu-latest
145148
env:
146149
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
@@ -183,7 +186,9 @@ jobs:
183186
--define sonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json
184187
185188
IAR-CStat:
186-
if: github.repository_owner == 'hathach'
189+
# Only run on non-forked PR since secrets token is required
190+
#if: github.repository_owner == 'hathach' && github.event.pull_request.head.repo.fork == false
191+
if: false
187192
runs-on: ubuntu-latest
188193
strategy:
189194
fail-fast: false

0 commit comments

Comments
 (0)