Skip to content

Commit 19d7d62

Browse files
committed
try to add samd51 to hil pool using doublereset (rpi gpio) and bossac
1 parent 59ecdb7 commit 19d7d62

File tree

9 files changed

+84
-15
lines changed

9 files changed

+84
-15
lines changed

.github/workflows/cmake_arm.yml

Lines changed: 9 additions & 1 deletion
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: |

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: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,19 @@
3434
import json
3535
import glob
3636

37+
# for RPI double reset: install sudo apt install python3-gpiozero or sudo pip install gpiozero
38+
from gpiozero import LED
39+
40+
3741
ENUM_TIMEOUT = 10
3842

3943

4044
# get usb serial by id
4145
def get_serial_dev(id, vendor_str, product_str, ifnum):
4246
if vendor_str and product_str:
4347
# known vendor and product
48+
vendor_str = vendor_str.replace(' ', '_')
49+
product_str = product_str.replace(' ', '_')
4450
return f'/dev/serial/by-id/usb-{vendor_str}_{product_str}_{id}-if{ifnum:02d}'
4551
else:
4652
# just use id: mostly for cp210x/ftdi flasher
@@ -115,7 +121,7 @@ def flash_jlink(board, firmware):
115121

116122
def flash_openocd(board, firmware):
117123
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"',
124+
f'openocd -c "adapter serial {board["flasher_sn"]}" {board["flasher_args"]} -c "program {firmware} reset exit"',
119125
shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
120126
return ret
121127

@@ -133,6 +139,35 @@ def flash_esptool(board, firmware):
133139
return ret
134140

135141

142+
def doublereset_with_rpi_gpio(board):
143+
# Off = 0 = Reset
144+
led = LED(board["flasher_reset_pin"])
145+
146+
led.off()
147+
time.sleep(0.1)
148+
led.on()
149+
time.sleep(0.1)
150+
led.off()
151+
time.sleep(0.1)
152+
led.on()
153+
154+
def flash_bossac(board, firmware):
155+
# double reset to enter bootloader
156+
doublereset_with_rpi_gpio(board)
157+
158+
port = get_serial_dev(board["uid"], board["flashser_vendor"], board["flasher_product"], 0)
159+
timeout = ENUM_TIMEOUT
160+
while timeout:
161+
if os.path.exists(port):
162+
time.sleep(0.5)
163+
break
164+
else:
165+
time.sleep(0.5)
166+
timeout = timeout - 0.5
167+
ret = subprocess.run(f'bossac --port {port} {board["flasher_args"]} -U -i -R -e -w {firmware}', shell=True, stdout=subprocess.PIPE,
168+
stderr=subprocess.STDOUT)
169+
return ret
170+
136171
# -------------------------------------------------------------
137172
# Tests
138173
# -------------------------------------------------------------
@@ -305,7 +340,7 @@ def main(config_file, board):
305340

306341
for test in test_list:
307342
fw_list = [
308-
# cmake: esp32 use .bin file
343+
# cmake: esp32 & samd51 use .bin file
309344
f'cmake-build/cmake-build-{item["name"]}/device/{test}/{test}.elf',
310345
f'cmake-build/cmake-build-{item["name"]}/device/{test}/{test}.bin',
311346
# make

0 commit comments

Comments
 (0)