diff options
Diffstat (limited to 'tinyusb/tools')
-rwxr-xr-x | tinyusb/tools/build_board.py | 125 | ||||
-rwxr-xr-x | tinyusb/tools/build_esp32sx.py | 102 | ||||
-rwxr-xr-x | tinyusb/tools/build_family.py | 144 | ||||
-rwxr-xr-x | tinyusb/tools/top.mk | 30 | ||||
-rwxr-xr-x | tinyusb/tools/usb_drivers/tinyusb_win_usbser.inf | 108 |
5 files changed, 509 insertions, 0 deletions
diff --git a/tinyusb/tools/build_board.py b/tinyusb/tools/build_board.py new file mode 100755 index 00000000..9397c754 --- /dev/null +++ b/tinyusb/tools/build_board.py @@ -0,0 +1,125 @@ +import os +import glob +import sys +import subprocess +import time + +SUCCEEDED = "\033[32msucceeded\033[0m" +FAILED = "\033[31mfailed\033[0m" +SKIPPED = "\033[33mskipped\033[0m" + +success_count = 0 +fail_count = 0 +skip_count = 0 +exit_status = 0 + +total_time = time.monotonic() + +build_format = '| {:29} | {:30} | {:18} | {:7} | {:6} | {:6} |' +build_separator = '-' * 106 + +def filter_with_input(mylist): + if len(sys.argv) > 1: + input_args = list(set(mylist).intersection(sys.argv)) + if len(input_args) > 0: + mylist[:] = input_args + +# If examples are not specified in arguments, build all +all_examples = [] +for entry in os.scandir("examples/device"): + if entry.is_dir(): + all_examples.append("device/" + entry.name) +for entry in os.scandir("examples/host"): + if entry.is_dir(): + all_examples.append("host/" + entry.name) +filter_with_input(all_examples) +all_examples.sort() + +# If boards are not specified in arguments, build all +all_boards = [] +for entry in os.scandir("hw/bsp"): + if entry.is_dir() and os.path.exists(entry.path + "/board.mk"): + all_boards.append(entry.name) +filter_with_input(all_boards) +all_boards.sort() + +def build_board(example, board): + global success_count, fail_count, skip_count, exit_status + start_time = time.monotonic() + flash_size = "-" + sram_size = "-" + + # Check if board is skipped + if skip_example(example, board): + success = SKIPPED + skip_count += 1 + print(build_format.format(example, board, success, '-', flash_size, sram_size)) + else: + subprocess.run("make -C examples/{} BOARD={} clean".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + build_result = subprocess.run("make -j -C examples/{} BOARD={} all".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + + if build_result.returncode == 0: + success = SUCCEEDED + success_count += 1 + (flash_size, sram_size) = build_size(example, board) + else: + exit_status = build_result.returncode + success = FAILED + fail_count += 1 + + build_duration = time.monotonic() - start_time + print(build_format.format(example, board, success, "{:.2f}s".format(build_duration), flash_size, sram_size)) + + if build_result.returncode != 0: + print(build_result.stdout.decode("utf-8")) + +def build_size(example, board): + #elf_file = 'examples/device/{}/_build/{}/{}-firmware.elf'.format(example, board, board) + elf_file = 'examples/{}/_build/{}/*.elf'.format(example, board) + size_output = subprocess.run('size {}'.format(elf_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8") + size_list = size_output.split('\n')[1].split('\t') + flash_size = int(size_list[0]) + sram_size = int(size_list[1]) + int(size_list[2]) + return (flash_size, sram_size) + +def skip_example(example, board): + ex_dir = 'examples/' + example + board_mk = 'hw/bsp/{}/board.mk'.format(board) + with open(board_mk) as mk: + mk_contents = mk.read() + + # Skip all OPT_MCU_NONE these are WIP port + if '-DCFG_TUSB_MCU=OPT_MCU_NONE' in mk_contents: + return 1 + + # Skip if CFG_TUSB_MCU in board.mk to match skip file + for skip_file in glob.iglob(ex_dir + '/.skip.MCU_*'): + mcu_cflag = '-DCFG_TUSB_MCU=OPT_' + os.path.basename(skip_file).split('.')[2] + if mcu_cflag in mk_contents: + return 1 + + # Build only list, if exists only these MCU are built + only_list = list(glob.iglob(ex_dir + '/.only.MCU_*')) + if len(only_list) > 0: + for only_file in only_list: + mcu_cflag = '-DCFG_TUSB_MCU=OPT_' + os.path.basename(only_file).split('.')[2] + if mcu_cflag in mk_contents: + return 0 + return 1 + + return 0 + +print(build_separator) +print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM')) + +for example in all_examples: + print(build_separator) + for board in all_boards: + build_board(example, board) + +total_time = time.monotonic() - total_time +print(build_separator) +print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, skip_count, SKIPPED, total_time)) +print(build_separator) + +sys.exit(exit_status) diff --git a/tinyusb/tools/build_esp32sx.py b/tinyusb/tools/build_esp32sx.py new file mode 100755 index 00000000..91953f08 --- /dev/null +++ b/tinyusb/tools/build_esp32sx.py @@ -0,0 +1,102 @@ +import os +import glob +import sys +import subprocess +import time + +SUCCEEDED = "\033[32msucceeded\033[0m" +FAILED = "\033[31mfailed\033[0m" +SKIPPED = "\033[33mskipped\033[0m" + +success_count = 0 +fail_count = 0 +skip_count = 0 +exit_status = 0 + +total_time = time.monotonic() + +build_format = '| {:23} | {:30} | {:18} | {:7} | {:6} | {:6} |' +build_separator = '-' * 100 + +def filter_with_input(mylist): + if len(sys.argv) > 1: + input_args = list(set(mylist).intersection(sys.argv)) + if len(input_args) > 0: + mylist[:] = input_args + +# Build all examples if not specified +all_examples = [] +for entry in os.scandir("examples/device"): + # Only includes example with CMakeLists.txt for esp32s, and skip board_test to speed up ci + if entry.is_dir() and os.path.exists(entry.path + "/sdkconfig.defaults") and entry.name != 'board_test': + all_examples.append(entry.name) +filter_with_input(all_examples) +all_examples.sort() + +# Build all boards if not specified +all_boards = [] +for entry in os.scandir("hw/bsp/esp32s2/boards"): + if entry.is_dir(): + all_boards.append(entry.name) +for entry in os.scandir("hw/bsp/esp32s3/boards"): + if entry.is_dir(): + all_boards.append(entry.name) +filter_with_input(all_boards) +all_boards.sort() + +def build_board(example, board): + global success_count, fail_count, skip_count, exit_status + start_time = time.monotonic() + flash_size = "-" + sram_size = "-" + + # Check if board is skipped + if skip_example(example, board): + success = SKIPPED + skip_count += 1 + print(build_format.format(example, board, success, '-', flash_size, sram_size)) + else: + subprocess.run("make -C examples/device/{} BOARD={} clean".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + build_result = subprocess.run("make -j -C examples/device/{} BOARD={} all".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + + if build_result.returncode == 0: + success = SUCCEEDED + success_count += 1 + (flash_size, sram_size) = build_size(example, board) + else: + exit_status = build_result.returncode + success = FAILED + fail_count += 1 + + build_duration = time.monotonic() - start_time + print(build_format.format(example, board, success, "{:.2f}s".format(build_duration), flash_size, sram_size)) + + if build_result.returncode != 0: + print(build_result.stdout.decode("utf-8")) + +def build_size(example, board): + #elf_file = 'examples/device/{}/_build/{}/{}-firmware.elf'.format(example, board, board) + elf_file = 'examples/device/{}/_build/{}/*.elf'.format(example, board) + size_output = subprocess.run('size {}'.format(elf_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8") + size_list = size_output.split('\n')[1].split('\t') + flash_size = int(size_list[0]) + sram_size = int(size_list[1]) + int(size_list[2]) + return (flash_size, sram_size) + +def skip_example(example, board): + return 0 + +print(build_separator) +print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM')) +print(build_separator) + +for example in all_examples: + for board in all_boards: + build_board(example, board) + +total_time = time.monotonic() - total_time +print(build_separator) +print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, skip_count, SKIPPED, total_time)) +print(build_separator) + +sys.exit(exit_status) diff --git a/tinyusb/tools/build_family.py b/tinyusb/tools/build_family.py new file mode 100755 index 00000000..c4678190 --- /dev/null +++ b/tinyusb/tools/build_family.py @@ -0,0 +1,144 @@ +import os +import glob +import sys +import subprocess +import time + +SUCCEEDED = "\033[32msucceeded\033[0m" +FAILED = "\033[31mfailed\033[0m" +SKIPPED = "\033[33mskipped\033[0m" + +success_count = 0 +fail_count = 0 +skip_count = 0 +exit_status = 0 + +total_time = time.monotonic() + +build_format = '| {:29} | {:30} | {:18} | {:7} | {:6} | {:6} |' +build_separator = '-' * 106 + +def filter_with_input(mylist): + if len(sys.argv) > 1: + input_args = list(set(mylist).intersection(sys.argv)) + if len(input_args) > 0: + mylist[:] = input_args + +# If examples are not specified in arguments, build all +all_examples = [] +for entry in os.scandir("examples/device"): + if entry.is_dir(): + all_examples.append("device/" + entry.name) +for entry in os.scandir("examples/host"): + if entry.is_dir(): + all_examples.append("host/" + entry.name) +filter_with_input(all_examples) +all_examples.sort() + +# If family are not specified in arguments, build all +all_families = [] +for entry in os.scandir("hw/bsp"): + if entry.is_dir() and os.path.isdir(entry.path + "/boards") and entry.name != "esp32s2" and entry.name != "esp32s3": + all_families.append(entry.name) + +filter_with_input(all_families) +all_families.sort() + +def build_family(example, family): + all_boards = [] + for entry in os.scandir("hw/bsp/{}/boards".format(family)): + if entry.is_dir(): + all_boards.append(entry.name) + filter_with_input(all_boards) + all_boards.sort() + + for board in all_boards: + build_board(example, board) + +def build_board(example, board): + global success_count, fail_count, skip_count, exit_status + start_time = time.monotonic() + flash_size = "-" + sram_size = "-" + + # Check if board is skipped + if skip_example(example, board): + success = SKIPPED + skip_count += 1 + print(build_format.format(example, board, success, '-', flash_size, sram_size)) + else: + #subprocess.run("make -C examples/{} BOARD={} clean".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + build_result = subprocess.run("make -j -C examples/{} BOARD={} all".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + + if build_result.returncode == 0: + success = SUCCEEDED + success_count += 1 + (flash_size, sram_size) = build_size(example, board) + subprocess.run("make -j -C examples/{} BOARD={} copy-artifact".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + else: + exit_status = build_result.returncode + success = FAILED + fail_count += 1 + + build_duration = time.monotonic() - start_time + print(build_format.format(example, board, success, "{:.2f}s".format(build_duration), flash_size, sram_size)) + + if build_result.returncode != 0: + print(build_result.stdout.decode("utf-8")) + +def build_size(example, board): + #elf_file = 'examples/device/{}/_build/{}/{}-firmware.elf'.format(example, board, board) + elf_file = 'examples/{}/_build/{}/*.elf'.format(example, board) + size_output = subprocess.run('size {}'.format(elf_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8") + size_list = size_output.split('\n')[1].split('\t') + flash_size = int(size_list[0]) + sram_size = int(size_list[1]) + int(size_list[2]) + return (flash_size, sram_size) + +def skip_example(example, board): + ex_dir = 'examples/' + example + + # family CMake + board_mk = 'hw/bsp/{}/family.cmake'.format(family) + + # family.mk + if not os.path.exists(board_mk): + board_mk = 'hw/bsp/{}/family.mk'.format(family) + + with open(board_mk) as mk: + mk_contents = mk.read() + + # Skip all OPT_MCU_NONE these are WIP port + if 'CFG_TUSB_MCU=OPT_MCU_NONE' in mk_contents: + return 1 + + # Skip if CFG_TUSB_MCU in board.mk to match skip file + for skip_file in glob.iglob(ex_dir + '/.skip.MCU_*'): + mcu_cflag = 'CFG_TUSB_MCU=OPT_' + os.path.basename(skip_file).split('.')[2] + if mcu_cflag in mk_contents: + return 1 + + # Build only list, if exists only these MCU are built + only_list = list(glob.iglob(ex_dir + '/.only.MCU_*')) + if len(only_list) > 0: + for only_file in only_list: + mcu_cflag = 'CFG_TUSB_MCU=OPT_' + os.path.basename(only_file).split('.')[2] + if mcu_cflag in mk_contents: + return 0 + return 1 + return 0 + +print(build_separator) +print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM')) + +for example in all_examples: + print(build_separator) + for family in all_families: + build_family(example, family) + +total_time = time.monotonic() - total_time +print(build_separator) +print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, skip_count, SKIPPED, total_time)) +print(build_separator) + +sys.exit(exit_status) diff --git a/tinyusb/tools/top.mk b/tinyusb/tools/top.mk new file mode 100755 index 00000000..84523a55 --- /dev/null +++ b/tinyusb/tools/top.mk @@ -0,0 +1,30 @@ +ifneq ($(lastword a b),b) +$(error This Makefile require make 3.81 or newer) +endif + +# Detect whether shell style is windows or not +# https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069 +ifeq '$(findstring ;,$(PATH))' ';' +CMDEXE := 1 +endif + +# Set TOP to be the path to get from the current directory (where make was +# invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns +# the name of this makefile relative to where make was invoked. + +THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) +TOP := $(patsubst %/tools/top.mk,%,$(THIS_MAKEFILE)) + +ifeq ($(CMDEXE),1) +TOP := $(subst \,/,$(shell for %%i in ( $(TOP) ) do echo %%~fi)) +else +TOP := $(shell realpath $(TOP)) +endif +#$(info Top directory is $(TOP)) + +ifeq ($(CMDEXE),1) +CURRENT_PATH := $(subst $(TOP)/,,$(subst \,/,$(shell echo %CD%))) +else +CURRENT_PATH := $(shell realpath --relative-to=$(TOP) `pwd`) +endif +#$(info Path from top is $(CURRENT_PATH)) diff --git a/tinyusb/tools/usb_drivers/tinyusb_win_usbser.inf b/tinyusb/tools/usb_drivers/tinyusb_win_usbser.inf new file mode 100755 index 00000000..e7f7a9b2 --- /dev/null +++ b/tinyusb/tools/usb_drivers/tinyusb_win_usbser.inf @@ -0,0 +1,108 @@ +;************************************************************ +; Windows USB CDC ACM Setup File +; Copyright (c) 2000 Microsoft Corporation + + +[Version] +Signature="$Windows NT$" +Class=Ports +ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} +Provider=%MFGNAME% +LayoutFile=layout.inf +CatalogFile=%MFGFILENAME%.cat +DriverVer=11/15/2007,5.1.2600.0 +DriverPackageDisplayName=%DESCRIPTION% + +[Manufacturer] +%MFGNAME%=DeviceList, NTamd64 + +[DestinationDirs] +DefaultDestDir=12 + + +;------------------------------------------------------------------------------ +; Windows 2000/XP/Vista-32bit Sections +;------------------------------------------------------------------------------ + +[DriverInstall.nt] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles.nt +AddReg=DriverInstall.nt.AddReg + +[DriverCopyFiles.nt] +usbser.sys,,,0x20 + +[DriverInstall.nt.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,%DRIVERFILENAME%.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.nt.Services] +AddService=usbser, 0x00000002, DriverService.nt + +[DriverService.nt] +DisplayName=%SERVICE% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\%DRIVERFILENAME%.sys + +;------------------------------------------------------------------------------ +; Vista-64bit Sections +;------------------------------------------------------------------------------ + +[DriverInstall.NTamd64] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles.NTamd64 +AddReg=DriverInstall.NTamd64.AddReg + +[DriverCopyFiles.NTamd64] +%DRIVERFILENAME%.sys,,,0x20 + +[DriverInstall.NTamd64.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,%DRIVERFILENAME%.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.NTamd64.Services] +AddService=usbser, 0x00000002, DriverService.NTamd64 + +[DriverService.NTamd64] +DisplayName=%SERVICE% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\%DRIVERFILENAME%.sys + + +;------------------------------------------------------------------------------ +; Vendor and Product ID Definitions +;------------------------------------------------------------------------------ +; When developing your USB device, the VID and PID used in the PC side +; application program and the firmware on the microcontroller must match. +; Modify the below line to use your VID and PID. Use the format as shown below. +; Note: One INF file can be used for multiple devices with different VID and PIDs. +; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. +;------------------------------------------------------------------------------ +[SourceDisksFiles] +[SourceDisksNames] +[DeviceList] + +%DESCRIPTION%=DriverInstall, USB\VID_CAFE&PID_4001&MI_00, USB\VID_CAFE&PID_4003&MI_00, USB\VID_CAFE&PID_4005&MI_00, USB\VID_CAFE&PID_4007&MI_00, USB\VID_CAFE&PID_4009&MI_00, USB\VID_CAFE&PID_400b&MI_00, USB\VID_CAFE&PID_400d&MI_00, USB\VID_CAFE&PID_400f&MI_00, USB\VID_CAFE&PID_4011&MI_00, USB\VID_CAFE&PID_4013&MI_00, USB\VID_CAFE&PID_4015&MI_00, USB\VID_CAFE&PID_4017&MI_00, USB\VID_CAFE&PID_4019&MI_00, USB\VID_CAFE&PID_401b&MI_00, USB\VID_CAFE&PID_401d&MI_00, USB\VID_CAFE&PID_401f&MI_00, USB\VID_CAFE&PID_4021&MI_00, USB\VID_CAFE&PID_4023&MI_00, USB\VID_CAFE&PID_4025&MI_00, USB\VID_CAFE&PID_4027&MI_00, USB\VID_CAFE&PID_4029&MI_00, USB\VID_CAFE&PID_402b&MI_00, USB\VID_CAFE&PID_402d&MI_00, USB\VID_CAFE&PID_402f&MI_00, USB\VID_CAFE&PID_4031&MI_00, USB\VID_CAFE&PID_4033&MI_00, USB\VID_CAFE&PID_4035&MI_00, USB\VID_CAFE&PID_4037&MI_00, USB\VID_CAFE&PID_4039&MI_00, USB\VID_CAFE&PID_403b&MI_00, USB\VID_CAFE&PID_403d&MI_00, USB\VID_CAFE&PID_403f&MI_00 + + +[DeviceList.NTamd64] +%DESCRIPTION%=DriverInstall, USB\VID_CAFE&PID_4001&MI_00, USB\VID_CAFE&PID_4003&MI_00, USB\VID_CAFE&PID_4005&MI_00, USB\VID_CAFE&PID_4007&MI_00, USB\VID_CAFE&PID_4009&MI_00, USB\VID_CAFE&PID_400b&MI_00, USB\VID_CAFE&PID_400d&MI_00, USB\VID_CAFE&PID_400f&MI_00, USB\VID_CAFE&PID_4011&MI_00, USB\VID_CAFE&PID_4013&MI_00, USB\VID_CAFE&PID_4015&MI_00, USB\VID_CAFE&PID_4017&MI_00, USB\VID_CAFE&PID_4019&MI_00, USB\VID_CAFE&PID_401b&MI_00, USB\VID_CAFE&PID_401d&MI_00, USB\VID_CAFE&PID_401f&MI_00, USB\VID_CAFE&PID_4021&MI_00, USB\VID_CAFE&PID_4023&MI_00, USB\VID_CAFE&PID_4025&MI_00, USB\VID_CAFE&PID_4027&MI_00, USB\VID_CAFE&PID_4029&MI_00, USB\VID_CAFE&PID_402b&MI_00, USB\VID_CAFE&PID_402d&MI_00, USB\VID_CAFE&PID_402f&MI_00, USB\VID_CAFE&PID_4031&MI_00, USB\VID_CAFE&PID_4033&MI_00, USB\VID_CAFE&PID_4035&MI_00, USB\VID_CAFE&PID_4037&MI_00, USB\VID_CAFE&PID_4039&MI_00, USB\VID_CAFE&PID_403b&MI_00, USB\VID_CAFE&PID_403d&MI_00, USB\VID_CAFE&PID_403f&MI_00 + +;------------------------------------------------------------------------------ +; String Definitions +;------------------------------------------------------------------------------ +;Modify these strings to customize your device +;------------------------------------------------------------------------------ +[Strings] +MFGFILENAME="tinyusb_usbser" +DRIVERFILENAME ="usbser" +MFGNAME="tinyusb.org" +INSTDISK="tinyusb CDC Driver" +DESCRIPTION="tinyusb Serial" +SERVICE="USB RS-232 Emulation Driver"
\ No newline at end of file |