Skip to content

Commit 963971c

Browse files
authored
Merge pull request #3157 from hathach/update-buildsystem
Update buildsystem
2 parents 0d6cb38 + a52e5ce commit 963971c

File tree

77 files changed

+219
-302
lines changed

Some content is hidden

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

77 files changed

+219
-302
lines changed

.circleci/config.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ 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
@@ -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/workflows/build.yml

Lines changed: 26 additions & 34 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' &&

docs/reference/getting_started.rst

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ Getting Started
55
Add TinyUSB to your project
66
---------------------------
77

8-
It is relatively simple to incorporate tinyusb to your project
8+
To incorporate tinyusb to your project
99

1010
* Copy or ``git submodule`` this repo into your project in a subfolder. Let's say it is ``your_project/tinyusb``
1111
* Add all the ``.c`` in the ``tinyusb/src`` folder to your project
1212
* Add ``your_project/tinyusb/src`` to your include path. Also make sure your current include path also contains the configuration file ``tusb_config.h``.
13-
* Make sure all required macros are all defined properly in ``tusb_config.h`` (configure file in demo application is sufficient, but you need to add a few more such as ``CFG_TUSB_MCU``, ``CFG_TUSB_OS`` since they are passed by IDE/compiler to maintain a unique configure for all boards).
13+
* Make sure all required macros are all defined properly in ``tusb_config.h`` (configure file in demo application is sufficient, but you need to add a few more such as ``CFG_TUSB_MCU``, ``CFG_TUSB_OS`` since they are passed by make/cmake to maintain a unique configure for all boards).
1414
* If you use the device stack, make sure you have created/modified usb descriptors for your own need. Ultimately you need to implement all **tud descriptor** callbacks for the stack to work.
1515
* Add ``tusb_init(rhport, role)`` call to your reset initialization code.
1616
* Call ``tusb_int_handler(rhport, in_isr)`` in your USB IRQ Handler
@@ -75,24 +75,36 @@ The hardware code is located in ``hw/bsp`` folder, and is organized by family/bo
7575
.. code-block:: bash
7676
7777
$ cd examples/device/cdc_msc
78-
$ make BOARD=raspberry_pi_pico get-deps
78+
$ make BOARD=feather_nrf52840_express get-deps
7979
8080
You only need to do this once per family. Check out `complete list of dependencies and their designated path here <dependencies.rst>`_
8181

82-
Build
83-
^^^^^
82+
Build Examples
83+
^^^^^^^^^^^^^^
8484

85-
To build example, first change directory to an example folder.
85+
Examples support make and cmake build system for most MCUs, however some MCU families such as espressif or rp2040 only support cmake. First change directory to an example folder.
8686

8787
.. code-block:: bash
8888
8989
$ cd examples/device/cdc_msc
9090
91-
Then compile with ``make BOARD={board_name} all`` , for example
91+
Then compile with make or cmake
92+
93+
.. code-block:: bash
94+
95+
$ # make
96+
$ make BOARD=feather_nrf52840_express all
97+
98+
$ # cmake
99+
$ mkdir build && cd build
100+
$ cmake -DBOARD=raspberry_pi_pico ..
101+
$ make
102+
103+
To list all available targets with cmake
92104

93105
.. code-block:: bash
94106
95-
$ make BOARD=raspberry_pi_pico all
107+
$ cmake --build . --target help
96108
97109
Note: some examples especially those that uses Vendor class (e.g webUSB) may requires udev permission on Linux (and/or macOS) to access usb device. It depends on your OS distro, typically copy ``99-tinyusb.rules`` and reload your udev is good to go
98110

@@ -104,20 +116,24 @@ Note: some examples especially those that uses Vendor class (e.g webUSB) may req
104116
RootHub Port Selection
105117
~~~~~~~~~~~~~~~~~~~~~~
106118

107-
If a board has several ports, one port is chosen by default in the individual board.mk file. Use option ``PORT=x`` To choose another port. For example to select the HS port of a STM32F746Disco board, use:
119+
If a board has several ports, one port is chosen by default in the individual board.mk file. Use option ``RHPORT_DEVICE=x`` or ``RHPORT_HOST=x`` To choose another port. For example to select the HS port of a STM32F746Disco board, use:
108120

109121
.. code-block:: bash
110122
111-
$ make BOARD=stm32f746disco PORT=1 all
123+
$ make BOARD=stm32f746disco RHPORT_DEVICE=1 all
124+
125+
$ cmake -DBOARD=stm32f746disco -DRHPORT_DEVICE=1 ..
112126
113127
Port Speed
114128
~~~~~~~~~~
115129

116-
A MCU can support multiple operational speed. By default, the example build system will use the fastest supported on the board. Use option ``SPEED=full/high`` e.g To force F723 operate at full instead of default high speed
130+
A MCU can support multiple operational speed. By default, the example build system will use the fastest supported on the board. Use option ``RHPORT_DEVICE_SPEED=OPT_MODE_FULL/HIGH_SPEED/`` or ``RHPORT_HOST_SPEED=OPT_MODE_FULL/HIGH_SPEED/`` e.g To force F723 operate at full instead of default high speed
117131

118132
.. code-block:: bash
119133
120-
$ make BOARD=stm32f746disco SPEED=full all
134+
$ make BOARD=stm32f746disco RHPORT_DEVICE_SPEED=OPT_MODE_FULL_SPEED all
135+
136+
$ cmake -DBOARD=stm32f746disco -DRHPORT_DEVICE_SPEED=OPT_MODE_FULL_SPEED ..
121137
122138
Size Analysis
123139
~~~~~~~~~~~~~
@@ -137,6 +153,8 @@ To compile for debugging add ``DEBUG=1``\ , for example
137153
138154
$ make BOARD=feather_nrf52840_express DEBUG=1 all
139155
156+
$ cmake -DBOARD=feather_nrf52840_express -DCMAKE_BUILD_TYPE=Debug ..
157+
140158
Log
141159
~~~
142160

@@ -146,6 +164,8 @@ Should you have an issue running example and/or submitting an bug report. You co
146164
147165
$ make BOARD=feather_nrf52840_express LOG=2 all
148166
167+
$ cmake -DBOARD=feather_nrf52840_express -DLOG=2 ..
168+
149169
Logger
150170
~~~~~~
151171

@@ -169,6 +189,9 @@ By default log message is printed via on-board UART which is slow and take lots
169189
$ make BOARD=feather_nrf52840_express LOG=2 LOGGER=rtt all
170190
$ make BOARD=feather_nrf52840_express LOG=2 LOGGER=swo all
171191
192+
$ cmake -DBOARD=feather_nrf52840_express -DLOG=2 -DLOGGER=rtt ..
193+
$ cmake -DBOARD=feather_nrf52840_express -DLOG=2 -DLOGGER=swo ..
194+
172195
Flash
173196
^^^^^
174197

@@ -179,29 +202,34 @@ Flash
179202
$ make BOARD=feather_nrf52840_express flash
180203
$ make SERIAL=/dev/ttyACM0 BOARD=feather_nrf52840_express flash
181204
182-
Since jlink can be used with most of the boards, there is also ``flash-jlink`` target for your convenience.
205+
Since jlink/openocd can be used with most of the boards, there is also ``flash-jlink/openocd`` (make) and ``EXAMPLE-jlink/openocd`` target for your convenience. Note for stm32 board with stlink, you can use ``flash-stlink`` target as well.
183206

184207
.. code-block:: bash
185208
186209
$ make BOARD=feather_nrf52840_express flash-jlink
210+
$ make BOARD=feather_nrf52840_express flash-openocd
211+
212+
$ cmake --build . --target cdc_msc-jlink
213+
$ cmake --build . --target cdc_msc-openocd
187214
188215
Some board use uf2 bootloader for drag & drop in to mass storage device, uf2 can be generated with ``uf2`` target
189216

190217
.. code-block:: bash
191218
192219
$ make BOARD=feather_nrf52840_express all uf2
193220
221+
$ cmake --build . --target cdc_msc-uf2
222+
194223
IAR Support
195-
-----------
224+
^^^^^^^^^^^
196225

197226
Use project connection
198-
^^^^^^^^^^^^^^^^^^^^^^
227+
~~~~~~~~~~~~~~~~~~~~~~
199228

200229
IAR Project Connection files are provided to import TinyUSB stack into your project.
201230

202231
* A buildable project of your MCU need to be created in advance.
203232

204-
205233
* Take example of STM32F0:
206234

207235
- You need ``stm32l0xx.h``, ``startup_stm32f0xx.s``, ``system_stm32f0xx.c``.
@@ -212,15 +240,13 @@ IAR Project Connection files are provided to import TinyUSB stack into your proj
212240
Click ``New Group ...``, name it to ``TUSB``, Click ``Add Variable ...``, name it to ``TUSB_DIR``, change it's value to the path of your TinyUSB stack,
213241
for example ``C:\\tinyusb``
214242

215-
Import stack only
216-
~~~~~~~~~~~~~~~~~
243+
**Import stack only**
217244

218-
1. Open ``Project -> Add project Connection ...``, click ``OK``, choose ``tinyusb\\tools\\iar_template.ipcf``.
245+
Open ``Project -> Add project Connection ...``, click ``OK``, choose ``tinyusb\\tools\\iar_template.ipcf``.
219246

220-
Run examples
221-
~~~~~~~~~~~~
247+
**Run examples**
222248

223-
1. (Python3 is needed) Run ``iar_gen.py`` to generate .ipcf files of examples:
249+
1. Run ``iar_gen.py`` to generate .ipcf files of examples:
224250

225251
.. code-block::
226252
@@ -230,8 +256,8 @@ Run examples
230256
2. Open ``Project -> Add project Connection ...``, click ``OK``, choose ``tinyusb\\examples\\(.ipcf of example)``.
231257
For example ``C:\\tinyusb\\examples\\device\\cdc_msc\\iar_cdc_msc.ipcf``
232258

233-
Native CMake support (9.50.1+)
234-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
259+
Native CMake support
260+
~~~~~~~~~~~~~~~~~~~~
235261

236262
With 9.50.1 release, IAR added experimental native CMake support (strangely not mentioned in public release note). Now it's possible to import CMakeLists.txt then build and debug as a normal project.
237263

examples/build_system/make/make.mk

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,27 +123,24 @@ endif
123123
ifeq (${MAX3421_HOST},1)
124124
SRC_C += src/portable/analog/max3421/hcd_max3421.c
125125
CFLAGS += -DCFG_TUH_MAX3421=1
126-
CMAKE_DEFSYM += -DMAX3421_HOST=1
127126
endif
128127

129128
# Log level is mapped to TUSB DEBUG option
130129
ifneq ($(LOG),)
131-
CMAKE_DEFSYM += -DLOG=$(LOG)
132130
CFLAGS += -DCFG_TUSB_DEBUG=$(LOG)
133131
endif
134132

135133
# Logger: default is uart, can be set to rtt or swo
136-
ifneq ($(LOGGER),)
137-
CMAKE_DEFSYM += -DLOGGER=$(LOGGER)
138-
endif
139-
140134
ifeq ($(LOGGER),rtt)
141-
CFLAGS += -DLOGGER_RTT -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
142-
RTT_SRC = lib/SEGGER_RTT
143-
INC += $(TOP)/$(RTT_SRC)/RTT
144-
SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT.c
145-
else ifeq ($(LOGGER),swo)
135+
CFLAGS += -DLOGGER_RTT
136+
#CFLAGS += -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
137+
INC += $(TOP)/$(lib/SEGGER_RTT)/RTT
138+
SRC_C += $(lib/SEGGER_RTT)/RTT/SEGGER_RTT.c
139+
endif
140+
ifeq ($(LOGGER),swo)
146141
CFLAGS += -DLOGGER_SWO
142+
else
143+
CFLAGS += -DLOGGER_UART
147144
endif
148145

149146
# CPU specific flags

0 commit comments

Comments
 (0)