Skip to content

Commit ccc59e8

Browse files
authored
Merge pull request #2375 from hathach/hil-add-samd51
add samd51 (itsybitsy_m4) to hardware test loop
2 parents 59ecdb7 + 3da0d78 commit ccc59e8

File tree

10 files changed

+101
-25
lines changed

10 files changed

+101
-25
lines changed

.github/workflows/build_esp.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@ jobs:
9292
name: ${{ matrix.board }}
9393
path: cmake-build/cmake-build-${{ matrix.board }}
9494

95-
- name: Test on actual hardware
96-
run: |
97-
python3 test/hil/hil_test.py --board ${{ matrix.board }} hil_pi4.json
98-
9995
- name: Reset USB bus
10096
run: |
10197
for port in $(lspci | grep USB | cut -d' ' -f1); do
10298
echo -n "0000:${port}"| sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind;
103-
sleep 1;
99+
sleep 0.5;
104100
echo -n "0000:${port}" | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind;
101+
sleep 3;
105102
done
103+
104+
- name: Test on actual hardware
105+
run: |
106+
python3 test/hil/hil_test.py --board ${{ matrix.board }} hil_pi4.json

.github/workflows/cmake_arm.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ jobs:
102102
path: |
103103
cmake-build/cmake-build-feather_nrf52840_express/*/*/*.elf
104104
105+
- name: Upload Artifacts for Hardware Testing (samd51)
106+
if: matrix.family == 'samd51' && github.repository_owner == 'hathach'
107+
uses: actions/upload-artifact@v3
108+
with:
109+
name: itsybitsy_m4
110+
path: |
111+
cmake-build/cmake-build-itsybitsy_m4/*/*/*.bin
105112
106113
# ---------------------------------------
107114
# Hardware in the loop (HIL)
@@ -116,8 +123,9 @@ jobs:
116123
fail-fast: false
117124
matrix:
118125
board:
119-
- 'raspberry_pi_pico'
120126
- 'feather_nrf52840_express'
127+
- 'itsybitsy_m4'
128+
- 'raspberry_pi_pico'
121129
steps:
122130
- name: Clean workspace
123131
run: |
@@ -136,14 +144,15 @@ jobs:
136144
name: ${{ matrix.board }}
137145
path: cmake-build/cmake-build-${{ matrix.board }}
138146

139-
- name: Test on actual hardware
140-
run: |
141-
python3 test/hil/hil_test.py --board ${{ matrix.board }} hil_pi4.json
142-
143147
- name: Reset USB bus
144148
run: |
145149
for port in $(lspci | grep USB | cut -d' ' -f1); do
146150
echo -n "0000:${port}"| sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind;
147-
sleep 1;
151+
sleep 0.5;
148152
echo -n "0000:${port}" | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind;
153+
sleep 3;
149154
done
155+
156+
- name: Test on actual hardware
157+
run: |
158+
python3 test/hil/hil_test.py --board ${{ matrix.board }} hil_pi4.json

hw/bsp/samd21/family.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus CACHE INTERNAL "System Processor")
1010
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
1111

1212
set(FAMILY_MCUS SAMD21 CACHE INTERNAL "")
13-
13+
set(OPENOCD_OPTION "-f interface/cmsis-dap.cfg -c \"transport select swd\" -f target/at91samdXX.cfg")
1414

1515
#------------------------------------
1616
# BOARD_TARGET
@@ -102,4 +102,5 @@ function(family_configure_example TARGET RTOS)
102102

103103
# Flashing
104104
family_flash_jlink(${TARGET})
105+
#family_flash_openocd(${TARGET} ${OPENOCD_OPTION})
105106
endfunction()

hw/bsp/samd51/family.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ uint32_t board_button_read(void) {
157157
return gpio_get_pin_level(BUTTON_PIN) ? 0 : 1;
158158
}
159159

160+
size_t board_get_unique_id(uint8_t id[], size_t max_len) {
161+
(void) max_len;
162+
163+
uint32_t did_addr[4] = {0x008061FC, 0x00806010, 0x00806014, 0x00806018};
164+
165+
for (int i = 0; i < 4; i++) {
166+
uint32_t did = *((uint32_t const*) did_addr[i]);
167+
did = TU_BSWAP32(did); // swap endian to match samd51 uf2 bootloader
168+
memcpy(id + i * 4, &did, 4);
169+
}
170+
171+
return 16;
172+
}
173+
160174
int board_uart_read(uint8_t* buf, int len) {
161175
(void) buf;
162176
(void) len;

hw/bsp/samd51/family.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set(CMAKE_SYSTEM_PROCESSOR cortex-m4 CACHE INTERNAL "System Processor")
1010
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
1111

1212
set(FAMILY_MCUS SAMD51 CACHE INTERNAL "")
13-
13+
set(OPENOCD_OPTION "-f interface/cmsis-dap.cfg -c \"transport select swd\" -c \"set CHIPNAME samd51\" -f target/atsame5x.cfg")
1414

1515
#------------------------------------
1616
# BOARD_TARGET
@@ -100,5 +100,7 @@ function(family_configure_example TARGET RTOS)
100100
target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb)
101101

102102
# Flashing
103+
family_add_bin_hex(${TARGET})
103104
family_flash_jlink(${TARGET})
105+
#family_flash_openocd(${TARGET} ${OPENOCD_OPTION})
104106
endfunction()

src/device/usbd_pvt.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@
3333
extern "C" {
3434
#endif
3535

36-
// Level where CFG_TUSB_DEBUG must be at least for USBD is logged
37-
#ifndef CFG_TUD_LOG_LEVEL
38-
#define CFG_TUD_LOG_LEVEL 2
39-
#endif
40-
4136
#define TU_LOG_USBD(...) TU_LOG(CFG_TUD_LOG_LEVEL, __VA_ARGS__)
4237

4338
//--------------------------------------------------------------------+

src/host/usbh_pvt.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@
3535
extern "C" {
3636
#endif
3737

38-
// Level where CFG_TUSB_DEBUG must be at least for USBH is logged
39-
#ifndef CFG_TUH_LOG_LEVEL
40-
#define CFG_TUH_LOG_LEVEL 2
41-
#endif
42-
4338
#define TU_LOG_USBH(...) TU_LOG(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
4439

4540
enum {

src/tusb_option.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,16 @@
299299
#define CFG_TUSB_DEBUG 0
300300
#endif
301301

302+
// Level where CFG_TUSB_DEBUG must be at least for USBH is logged
303+
#ifndef CFG_TUH_LOG_LEVEL
304+
#define CFG_TUH_LOG_LEVEL 2
305+
#endif
306+
307+
// Level where CFG_TUSB_DEBUG must be at least for USBD is logged
308+
#ifndef CFG_TUD_LOG_LEVEL
309+
#define CFG_TUD_LOG_LEVEL 2
310+
#endif
311+
302312
// Memory section for placing buffer used for usb transferring. If MEM_SECTION is different for
303313
// host and device use: CFG_TUD_MEM_SECTION, CFG_TUH_MEM_SECTION instead
304314
#ifndef CFG_TUSB_MEM_SECTION

test/hil/hil_pi4.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
"flasher": "jlink",
2424
"flasher_sn": "000682804350",
2525
"flasher_args": "-device nrf52840_xxaa"
26+
},
27+
{
28+
"name": "itsybitsy_m4",
29+
"uid": "D784B28C5338533335202020FF044726",
30+
"flasher": "bossac",
31+
"flashser_vendor": "Adafruit Industries",
32+
"flasher_product": "ItsyBitsy M4 Express",
33+
"flasher_reset_pin": "2",
34+
"flasher_args": "--offset 0x4000"
2635
}
2736
]
2837
}

test/hil/hil_test.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,22 @@
3434
import json
3535
import glob
3636

37+
# for RPI double reset
38+
try:
39+
import gpiozero
40+
except ImportError:
41+
pass
42+
43+
3744
ENUM_TIMEOUT = 10
3845

3946

4047
# get usb serial by id
4148
def get_serial_dev(id, vendor_str, product_str, ifnum):
4249
if vendor_str and product_str:
4350
# known vendor and product
51+
vendor_str = vendor_str.replace(' ', '_')
52+
product_str = product_str.replace(' ', '_')
4453
return f'/dev/serial/by-id/usb-{vendor_str}_{product_str}_{id}-if{ifnum:02d}'
4554
else:
4655
# just use id: mostly for cp210x/ftdi flasher
@@ -115,7 +124,7 @@ def flash_jlink(board, firmware):
115124

116125
def flash_openocd(board, firmware):
117126
ret = subprocess.run(
118-
f'openocd -c "adapter serial {board["flasher_sn"]}" {board["flasher_args"]} -c "program {firmware}" -c "reset init" -c "resume" -c "exit"',
127+
f'openocd -c "adapter serial {board["flasher_sn"]}" {board["flasher_args"]} -c "program {firmware} reset exit"',
119128
shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
120129
return ret
121130

@@ -133,6 +142,37 @@ def flash_esptool(board, firmware):
133142
return ret
134143

135144

145+
def doublereset_with_rpi_gpio(board):
146+
# Off = 0 = Reset
147+
led = gpiozero.LED(board["flasher_reset_pin"])
148+
149+
led.off()
150+
time.sleep(0.1)
151+
led.on()
152+
time.sleep(0.1)
153+
led.off()
154+
time.sleep(0.1)
155+
led.on()
156+
157+
def flash_bossac(board, firmware):
158+
# double reset to enter bootloader
159+
doublereset_with_rpi_gpio(board)
160+
161+
port = get_serial_dev(board["uid"], board["flashser_vendor"], board["flasher_product"], 0)
162+
timeout = ENUM_TIMEOUT
163+
while timeout:
164+
if os.path.exists(port):
165+
break
166+
else:
167+
time.sleep(0.5)
168+
timeout = timeout - 0.5
169+
assert timeout, 'bossac bootloader is not available'
170+
# sleep a bit more for bootloader to be ready
171+
time.sleep(0.5)
172+
ret = subprocess.run(f'bossac --port {port} {board["flasher_args"]} -U -i -R -e -w {firmware}', shell=True, stdout=subprocess.PIPE,
173+
stderr=subprocess.STDOUT)
174+
return ret
175+
136176
# -------------------------------------------------------------
137177
# Tests
138178
# -------------------------------------------------------------
@@ -305,7 +345,7 @@ def main(config_file, board):
305345

306346
for test in test_list:
307347
fw_list = [
308-
# cmake: esp32 use .bin file
348+
# cmake: esp32 & samd51 use .bin file
309349
f'cmake-build/cmake-build-{item["name"]}/device/{test}/{test}.elf',
310350
f'cmake-build/cmake-build-{item["name"]}/device/{test}/{test}.bin',
311351
# make

0 commit comments

Comments
 (0)