summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2023-12-15 17:42:25 +0700
committerhathach <[email protected]>2023-12-15 17:42:25 +0700
commit17a0ce655bab4413928404ce7dc4f968738bfcf6 (patch)
tree26efd78e70fd01b0c819104b1c86d85b6f685f9b
parentf3d713ac7336913a68326eae5a7e146ec2cd22c3 (diff)
parent9474db8b0fc3e96d654ed49529b82bbd329f2f56 (diff)
Merge branch 'master' into h5
-rw-r--r--.github/workflows/build_esp.yml17
-rw-r--r--.github/workflows/cmake_arm.yml27
-rw-r--r--docs/reference/getting_started.rst23
-rw-r--r--examples/build_system/cmake/cpu/cortex-m4.cmake2
-rw-r--r--examples/build_system/cmake/toolchain/arm_iar.cmake1
-rw-r--r--hw/bsp/family_support.cmake20
-rw-r--r--hw/bsp/samd21/family.cmake3
-rw-r--r--hw/bsp/samd51/family.c14
-rw-r--r--hw/bsp/samd51/family.cmake4
-rw-r--r--src/device/usbd_pvt.h5
-rw-r--r--src/host/usbh_pvt.h5
-rw-r--r--src/tusb_option.h10
-rw-r--r--test/hil/hil_pi4.json9
-rw-r--r--test/hil/hil_test.py44
14 files changed, 141 insertions, 43 deletions
diff --git a/.github/workflows/build_esp.yml b/.github/workflows/build_esp.yml
index 51df644a5..57cf9a4a6 100644
--- a/.github/workflows/build_esp.yml
+++ b/.github/workflows/build_esp.yml
@@ -81,6 +81,15 @@ jobs:
rm -rf "${{ github.workspace }}"
mkdir -p "${{ github.workspace }}"
+ # USB bus on rpi4 is not stable, reset it before testing
+ - name: Reset USB bus
+ run: |
+ for port in $(lspci | grep USB | cut -d' ' -f1); do
+ echo -n "0000:${port}"| sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind;
+ sleep 0.1;
+ echo -n "0000:${port}" | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind;
+ done
+
- name: Checkout test/hil
uses: actions/checkout@v3
with:
@@ -95,11 +104,3 @@ jobs:
- name: Test on actual hardware
run: |
python3 test/hil/hil_test.py --board ${{ matrix.board }} hil_pi4.json
-
- - name: Reset USB bus
- run: |
- for port in $(lspci | grep USB | cut -d' ' -f1); do
- echo -n "0000:${port}"| sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind;
- sleep 1;
- echo -n "0000:${port}" | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind;
- done
diff --git a/.github/workflows/cmake_arm.yml b/.github/workflows/cmake_arm.yml
index f760ca3ca..1a99d407f 100644
--- a/.github/workflows/cmake_arm.yml
+++ b/.github/workflows/cmake_arm.yml
@@ -102,6 +102,13 @@ jobs:
path: |
cmake-build/cmake-build-feather_nrf52840_express/*/*/*.elf
+ - name: Upload Artifacts for Hardware Testing (samd51)
+ if: matrix.family == 'samd51' && github.repository_owner == 'hathach'
+ uses: actions/upload-artifact@v3
+ with:
+ name: itsybitsy_m4
+ path: |
+ cmake-build/cmake-build-itsybitsy_m4/*/*/*.bin
# ---------------------------------------
# Hardware in the loop (HIL)
@@ -116,8 +123,9 @@ jobs:
fail-fast: false
matrix:
board:
- - 'raspberry_pi_pico'
- 'feather_nrf52840_express'
+ - 'itsybitsy_m4'
+ - 'raspberry_pi_pico'
steps:
- name: Clean workspace
run: |
@@ -125,6 +133,15 @@ jobs:
rm -rf "${{ github.workspace }}"
mkdir -p "${{ github.workspace }}"
+ # USB bus on rpi4 is not stable, reset it before testing
+ - name: Reset USB bus
+ run: |
+ for port in $(lspci | grep USB | cut -d' ' -f1); do
+ echo -n "0000:${port}"| sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind;
+ sleep 0.1;
+ echo -n "0000:${port}" | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind;
+ done
+
- name: Checkout test/hil
uses: actions/checkout@v3
with:
@@ -139,11 +156,3 @@ jobs:
- name: Test on actual hardware
run: |
python3 test/hil/hil_test.py --board ${{ matrix.board }} hil_pi4.json
-
- - name: Reset USB bus
- run: |
- for port in $(lspci | grep USB | cut -d' ' -f1); do
- echo -n "0000:${port}"| sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind;
- sleep 1;
- echo -n "0000:${port}" | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind;
- done
diff --git a/docs/reference/getting_started.rst b/docs/reference/getting_started.rst
index f2a3e7e2a..3db3fa206 100644
--- a/docs/reference/getting_started.rst
+++ b/docs/reference/getting_started.rst
@@ -178,7 +178,10 @@ Some board use uf2 bootloader for drag & drop in to mass storage device, uf2 can
$ make BOARD=feather_nrf52840_express all uf2
IAR Support
-^^^^^^^^^^^
+-----------
+
+Use project connection
+^^^^^^^^^^^^^^^^^^^^^^
IAR Project Connection files are provided to import TinyUSB stack into your project.
@@ -191,19 +194,19 @@ IAR Project Connection files are provided to import TinyUSB stack into your proj
- `STM32L0xx_HAL_Driver` is only needed to run examples, TinyUSB stack itself doesn't rely on MCU's SDKs.
-* Open `Tools -> Configure Custom Argument Variables` (Switch to `Global` tab if you want to do it for all your projects)
+* Open ``Tools -> Configure Custom Argument Variables`` (Switch to `Global` tab if you want to do it for all your projects)
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,
for example `C:\\tinyusb`
Import stack only
~~~~~~~~~~~~~~~~~
-1. Open `Project -> Add project Connection ...`, click `OK`, choose `tinyusb\\tools\\iar_template.ipcf`.
+1. Open ``Project -> Add project Connection ...``, click `OK`, choose `tinyusb\\tools\\iar_template.ipcf`.
Run examples
~~~~~~~~~~~~
-1. (Python3 is needed) Run `iar_gen.py` to generate .ipcf files of examples:
+1. (Python3 is needed) Run ``iar_gen.py`` to generate .ipcf files of examples:
.. code-block::
@@ -212,3 +215,15 @@ Run examples
2. 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`
+
+Native CMake support (9.50.1+)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+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:
+
+1. Add IAR compiler binary path to system ``PATH`` environment variable, such as ``C:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin``.
+2. Create new project in IAR, in Tool chain dropdown menu, choose CMake for Arm then Import ``CMakeLists.txt`` from chosen example directory.
+3. Set up board option in ``Option - CMake/CMSIS-TOOLBOX - CMake``, for example :code:`-DBOARD=stm32f439nucleo -DTOOLCHAIN=iar`, **Uncheck 'Override tools in env'**.
+4. (For debug only) Choose correct CPU model in ``Option - General Options - Target``, to profit register and memory view.
diff --git a/examples/build_system/cmake/cpu/cortex-m4.cmake b/examples/build_system/cmake/cpu/cortex-m4.cmake
index 4e9bc242d..db308aa83 100644
--- a/examples/build_system/cmake/cpu/cortex-m4.cmake
+++ b/examples/build_system/cmake/cpu/cortex-m4.cmake
@@ -13,7 +13,7 @@ if (TOOLCHAIN STREQUAL "gcc")
elseif (TOOLCHAIN STREQUAL "iar")
set(TOOLCHAIN_COMMON_FLAGS
--cpu cortex-m4
- --fpu VFPv4
+ --fpu VFPv4_sp
)
if (NOT DEFINED FREERTOS_PORT)
diff --git a/examples/build_system/cmake/toolchain/arm_iar.cmake b/examples/build_system/cmake/toolchain/arm_iar.cmake
index a487e5b9f..1482624e5 100644
--- a/examples/build_system/cmake/toolchain/arm_iar.cmake
+++ b/examples/build_system/cmake/toolchain/arm_iar.cmake
@@ -26,6 +26,7 @@ list(APPEND TOOLCHAIN_COMMON_FLAGS
)
list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
+ --diag_suppress=Li065
)
include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake)
diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake
index bd072e89d..539a776a6 100644
--- a/hw/bsp/family_support.cmake
+++ b/hw/bsp/family_support.cmake
@@ -72,7 +72,7 @@ set(WARNING_FLAGS_GNU
-Wredundant-decls
)
-set(WARNINGS_FLAGS_IAR "")
+set(WARNING_FLAGS_IAR "")
# Filter example based on only.txt and skip.txt
@@ -191,10 +191,12 @@ function(family_configure_common TARGET RTOS)
)
# run size after build
- add_custom_command(TARGET ${TARGET} POST_BUILD
- COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${TARGET}>
- )
-
+ find_program(SIZE_EXE ${CMAKE_SIZE})
+ if(NOT ${SIZE_EXE} STREQUAL SIZE_EXE-NOTFOUND)
+ add_custom_command(TARGET ${TARGET} POST_BUILD
+ COMMAND ${SIZE_EXE} $<TARGET_FILE:${TARGET}>
+ )
+ endif ()
# Add warnings flags
target_compile_options(${TARGET} PUBLIC ${WARNING_FLAGS_${CMAKE_C_COMPILER_ID}})
@@ -205,6 +207,10 @@ function(family_configure_common TARGET RTOS)
target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
endif ()
endif()
+ if (CMAKE_C_COMPILER_ID STREQUAL "IAR")
+ target_link_options(${TARGET} PUBLIC "LINKER:--map=$<TARGET_FILE:${TARGET}>.map")
+ endif()
+
# ETM Trace option
if (TRACE_ETM STREQUAL "1")
@@ -367,7 +373,7 @@ function(family_flash_jlink TARGET)
endif ()
file(GENERATE
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
+ OUTPUT $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.jlink
CONTENT "halt
loadfile $<TARGET_FILE:${TARGET}>
r
@@ -377,7 +383,7 @@ exit"
add_custom_target(${TARGET}-jlink
DEPENDS ${TARGET}
- COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
+ COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.jlink
)
endfunction()
diff --git a/hw/bsp/samd21/family.cmake b/hw/bsp/samd21/family.cmake
index 44aad6ecb..a79a25b54 100644
--- a/hw/bsp/samd21/family.cmake
+++ b/hw/bsp/samd21/family.cmake
@@ -10,7 +10,7 @@ set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus CACHE INTERNAL "System Processor")
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
set(FAMILY_MCUS SAMD21 CACHE INTERNAL "")
-
+set(OPENOCD_OPTION "-f interface/cmsis-dap.cfg -c \"transport select swd\" -f target/at91samdXX.cfg")
#------------------------------------
# BOARD_TARGET
@@ -102,4 +102,5 @@ function(family_configure_example TARGET RTOS)
# Flashing
family_flash_jlink(${TARGET})
+ #family_flash_openocd(${TARGET} ${OPENOCD_OPTION})
endfunction()
diff --git a/hw/bsp/samd51/family.c b/hw/bsp/samd51/family.c
index 009a0d290..170c88191 100644
--- a/hw/bsp/samd51/family.c
+++ b/hw/bsp/samd51/family.c
@@ -157,6 +157,20 @@ uint32_t board_button_read(void) {
return gpio_get_pin_level(BUTTON_PIN) ? 0 : 1;
}
+size_t board_get_unique_id(uint8_t id[], size_t max_len) {
+ (void) max_len;
+
+ uint32_t did_addr[4] = {0x008061FC, 0x00806010, 0x00806014, 0x00806018};
+
+ for (int i = 0; i < 4; i++) {
+ uint32_t did = *((uint32_t const*) did_addr[i]);
+ did = TU_BSWAP32(did); // swap endian to match samd51 uf2 bootloader
+ memcpy(id + i * 4, &did, 4);
+ }
+
+ return 16;
+}
+
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) len;
diff --git a/hw/bsp/samd51/family.cmake b/hw/bsp/samd51/family.cmake
index 7591f3b1b..4d91bf1a6 100644
--- a/hw/bsp/samd51/family.cmake
+++ b/hw/bsp/samd51/family.cmake
@@ -10,7 +10,7 @@ set(CMAKE_SYSTEM_PROCESSOR cortex-m4 CACHE INTERNAL "System Processor")
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
set(FAMILY_MCUS SAMD51 CACHE INTERNAL "")
-
+set(OPENOCD_OPTION "-f interface/cmsis-dap.cfg -c \"transport select swd\" -c \"set CHIPNAME samd51\" -f target/atsame5x.cfg")
#------------------------------------
# BOARD_TARGET
@@ -100,5 +100,7 @@ function(family_configure_example TARGET RTOS)
target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb)
# Flashing
+ family_add_bin_hex(${TARGET})
family_flash_jlink(${TARGET})
+ #family_flash_openocd(${TARGET} ${OPENOCD_OPTION})
endfunction()
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h
index 153be7cee..9039bc9d6 100644
--- a/src/device/usbd_pvt.h
+++ b/src/device/usbd_pvt.h
@@ -33,11 +33,6 @@
extern "C" {
#endif
-// Level where CFG_TUSB_DEBUG must be at least for USBD is logged
-#ifndef CFG_TUD_LOG_LEVEL
-#define CFG_TUD_LOG_LEVEL 2
-#endif
-
#define TU_LOG_USBD(...) TU_LOG(CFG_TUD_LOG_LEVEL, __VA_ARGS__)
//--------------------------------------------------------------------+
diff --git a/src/host/usbh_pvt.h b/src/host/usbh_pvt.h
index 3363ab9eb..4a97a1c18 100644
--- a/src/host/usbh_pvt.h
+++ b/src/host/usbh_pvt.h
@@ -35,11 +35,6 @@
extern "C" {
#endif
-// Level where CFG_TUSB_DEBUG must be at least for USBH is logged
-#ifndef CFG_TUH_LOG_LEVEL
- #define CFG_TUH_LOG_LEVEL 2
-#endif
-
#define TU_LOG_USBH(...) TU_LOG(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
enum {
diff --git a/src/tusb_option.h b/src/tusb_option.h
index 699691b53..a76281c0c 100644
--- a/src/tusb_option.h
+++ b/src/tusb_option.h
@@ -300,6 +300,16 @@
#define CFG_TUSB_DEBUG 0
#endif
+// Level where CFG_TUSB_DEBUG must be at least for USBH is logged
+#ifndef CFG_TUH_LOG_LEVEL
+ #define CFG_TUH_LOG_LEVEL 2
+#endif
+
+// Level where CFG_TUSB_DEBUG must be at least for USBD is logged
+#ifndef CFG_TUD_LOG_LEVEL
+ #define CFG_TUD_LOG_LEVEL 2
+#endif
+
// Memory section for placing buffer used for usb transferring. If MEM_SECTION is different for
// host and device use: CFG_TUD_MEM_SECTION, CFG_TUH_MEM_SECTION instead
#ifndef CFG_TUSB_MEM_SECTION
diff --git a/test/hil/hil_pi4.json b/test/hil/hil_pi4.json
index 560c3964e..17d9ff1fa 100644
--- a/test/hil/hil_pi4.json
+++ b/test/hil/hil_pi4.json
@@ -23,6 +23,15 @@
"flasher": "jlink",
"flasher_sn": "000682804350",
"flasher_args": "-device nrf52840_xxaa"
+ },
+ {
+ "name": "itsybitsy_m4",
+ "uid": "D784B28C5338533335202020FF044726",
+ "flasher": "bossac",
+ "flashser_vendor": "Adafruit Industries",
+ "flasher_product": "ItsyBitsy M4 Express",
+ "flasher_reset_pin": "2",
+ "flasher_args": "--offset 0x4000"
}
]
}
diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py
index 8f8a3aa65..7c662aeea 100644
--- a/test/hil/hil_test.py
+++ b/test/hil/hil_test.py
@@ -34,6 +34,13 @@ import subprocess
import json
import glob
+# for RPI double reset
+try:
+ import gpiozero
+except ImportError:
+ pass
+
+
ENUM_TIMEOUT = 10
@@ -41,6 +48,8 @@ ENUM_TIMEOUT = 10
def get_serial_dev(id, vendor_str, product_str, ifnum):
if vendor_str and product_str:
# known vendor and product
+ vendor_str = vendor_str.replace(' ', '_')
+ product_str = product_str.replace(' ', '_')
return f'/dev/serial/by-id/usb-{vendor_str}_{product_str}_{id}-if{ifnum:02d}'
else:
# just use id: mostly for cp210x/ftdi flasher
@@ -115,7 +124,7 @@ def flash_jlink(board, firmware):
def flash_openocd(board, firmware):
ret = subprocess.run(
- f'openocd -c "adapter serial {board["flasher_sn"]}" {board["flasher_args"]} -c "program {firmware}" -c "reset init" -c "resume" -c "exit"',
+ f'openocd -c "adapter serial {board["flasher_sn"]}" {board["flasher_args"]} -c "program {firmware} reset exit"',
shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return ret
@@ -133,6 +142,37 @@ def flash_esptool(board, firmware):
return ret
+def doublereset_with_rpi_gpio(board):
+ # Off = 0 = Reset
+ led = gpiozero.LED(board["flasher_reset_pin"])
+
+ led.off()
+ time.sleep(0.1)
+ led.on()
+ time.sleep(0.1)
+ led.off()
+ time.sleep(0.1)
+ led.on()
+
+def flash_bossac(board, firmware):
+ # double reset to enter bootloader
+ doublereset_with_rpi_gpio(board)
+
+ port = get_serial_dev(board["uid"], board["flashser_vendor"], board["flasher_product"], 0)
+ timeout = ENUM_TIMEOUT
+ while timeout:
+ if os.path.exists(port):
+ break
+ else:
+ time.sleep(0.5)
+ timeout = timeout - 0.5
+ assert timeout, 'bossac bootloader is not available'
+ # sleep a bit more for bootloader to be ready
+ time.sleep(0.5)
+ ret = subprocess.run(f'bossac --port {port} {board["flasher_args"]} -U -i -R -e -w {firmware}', shell=True, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ return ret
+
# -------------------------------------------------------------
# Tests
# -------------------------------------------------------------
@@ -305,7 +345,7 @@ def main(config_file, board):
for test in test_list:
fw_list = [
- # cmake: esp32 use .bin file
+ # cmake: esp32 & samd51 use .bin file
f'cmake-build/cmake-build-{item["name"]}/device/{test}/{test}.elf',
f'cmake-build/cmake-build-{item["name"]}/device/{test}/{test}.bin',
# make