同步操作将从 Gitee 极速下载/TinyUSB 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
It is relatively simple to incorporate tinyusb to your project
git submodule
this repo into your project in a subfolder. Let's say it is your_project/tinyusb
tinyusb/src
folder to your projecttud_int_handler()
(device) and/or tuh_int_handler()
(host) in your USB IRQ Handlerint main(void) { your_init_code(); tusb_init(); // initialize tinyusb stack while(1) // the mainloop { your_application_code(); tud_task(); // device task tuh_task(); // host task } }
For your convenience, TinyUSB contains a handful of examples for both host and device with/without RTOS to quickly test the functionality as well as demonstrate how API() should be used. Most examples will work on most of the supported boards. Firstly we need to git clone
if not already
$ git clone https://github.com/hathach/tinyusb tinyusb $ cd tinyusb
Some ports will also require a port-specific SDK (e.g. RP2040) or binary (e.g. Sony Spresense) to build examples. They are out of scope for tinyusb, you should download/install it first according to its manufacturer guide.
The hardware code is located in hw/bsp
folder, and is organized by family/boards. e.g raspberry_pi_pico is located in hw/bsp/rp2040/boards/raspberry_pi_pico
where FAMILY=rp2040 and BOARD=raspberry_pi_pico. Before building, we firstly need to download dependencies such as: MCU low-level peripheral driver and external libraries e.g FreeRTOS (required by some examples). We can do that by either ways:
tools/get_deps.py {FAMILY}
script to download all dependencies for a family as follow. Note: For TinyUSB developer to download all dependencies, use FAMILY=all.$ python tools/get_deps.py rp2040
get-deps
target in one of the example folder as follow.$ cd examples/device/cdc_msc $ make BOARD=raspberry_pi_pico get-deps
You only need to do this once per family. Check out complete list of dependencies and their designated path here
To build example, first change directory to an example folder.
$ cd examples/device/cdc_msc
Then compile with make BOARD={board_name} all
, for example
$ make BOARD=raspberry_pi_pico all
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
$ cp examples/device/99-tinyusb.rules /etc/udev/rules.d/ $ sudo udevadm control --reload-rules && sudo udevadm trigger
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:
$ make BOARD=stm32f746disco PORT=1 all
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
$ make BOARD=stm32f746disco SPEED=full all
First install linkermap tool then linkermap
target can be used to analyze code size. You may want to compile with NO_LTO=1
since -flto merges code across .o files and make it difficult to analyze.
$ make BOARD=feather_nrf52840_express NO_LTO=1 all linkermap
To compile for debugging add DEBUG=1
, for example
$ make BOARD=feather_nrf52840_express DEBUG=1 all
Should you have an issue running example and/or submitting an bug report. You could enable TinyUSB built-in debug logging with optional LOG=
. LOG=1 will only print out error message, LOG=2 print more information with on-going events. LOG=3 or higher is not used yet.
$ make BOARD=feather_nrf52840_express LOG=2 all
By default log message is printed via on-board UART which is slow and take lots of CPU time comparing to USB speed. If your board support on-board/external debugger, it would be more efficient to use it for logging. There are 2 protocols:
LOGGER=swo
: Use dedicated SWO pin of ARM Cortex SWD debug header.$ make BOARD=feather_nrf52840_express LOG=2 LOGGER=rtt all $ make BOARD=feather_nrf52840_express LOG=2 LOGGER=swo all
flash
target will use the default on-board debugger (jlink/cmsisdap/stlink/dfu) to flash the binary, please install those support software in advance. Some board use bootloader/DFU via serial which is required to pass to make command
$ make BOARD=feather_nrf52840_express flash $ make SERIAL=/dev/ttyACM0 BOARD=feather_nrf52840_express flash
Since jlink can be used with most of the boards, there is also flash-jlink
target for your convenience.
$ make BOARD=feather_nrf52840_express flash-jlink
Some board use uf2 bootloader for drag & drop in to mass storage device, uf2 can be generated with uf2
target
$ make BOARD=feather_nrf52840_express all uf2
IAR Project Connection files are provided to import TinyUSB stack into your project.
Tools -> Configure Custom Argument Variables
(Switch to Global tab if you want to do it for all your projects)Project -> Add project Connection ...
, click OK, choose tinyusb\tools\iar_template.ipcf.(Python3 is needed) Run iar_gen.py
to generate .ipcf files of examples:
cd C:\tinyusb\tools python iar_gen.py
Open Project -> Add project Connection ..., click OK, choose tinyusb\examples\(.ipcf of example). For example C:\tinyusb\examples\device\cdc_msc\iar_cdc_msc.ipcf
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.
Following these steps:
PATH
environment variable, such as C:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin
.CMakeLists.txt
from chosen example directory.Option - CMake/CMSIS-TOOLBOX - CMake
, for example -DBOARD=stm32f439nucleo -DTOOLCHAIN=iar
, Uncheck 'Override tools in env'.Option - General Options - Target
, to profit register and memory view.此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。