Skip to content

Commit ac1fd32

Browse files
authored
Merge pull request #2761 from hathach/hil-readd-v203
readd v203 to hil pool
2 parents 9ee7d1b + a621c4b commit ac1fd32

File tree

4 files changed

+77
-51
lines changed

4 files changed

+77
-51
lines changed

src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,14 @@ static void handle_ctr_rx(uint32_t ep_id) {
345345

346346
if ((rx_count < xfer->max_packet_size) || (xfer->queued_len >= xfer->total_len)) {
347347
// all bytes received or short packet
348-
dcd_event_xfer_complete(0, ep_num, xfer->queued_len, XFER_RESULT_SUCCESS, true);
349348

350349
// For ch32v203: reset rx bufsize to mps to prevent race condition to cause PMAOVR (occurs with msc write10)
351-
// also ch32 seems to unconditionally accept ZLP on EP0 OUT, which can incorrectly use queued_len of previous
352-
// transfer. So reset total_len and queued_len to 0.
353350
btable_set_rx_bufsize(ep_id, BTABLE_BUF_RX, xfer->max_packet_size);
351+
352+
dcd_event_xfer_complete(0, ep_num, xfer->queued_len, XFER_RESULT_SUCCESS, true);
353+
354+
// ch32 seems to unconditionally accept ZLP on EP0 OUT, which can incorrectly use queued_len of previous
355+
// transfer. So reset total_len and queued_len to 0.
354356
xfer->total_len = xfer->queued_len = 0;
355357
} else {
356358
// Set endpoint active again for receiving more data. Note that isochronous endpoints stay active always
@@ -412,11 +414,6 @@ void dcd_int_handler(uint8_t rhport) {
412414
FSDEV_REG->ISTR = (fsdev_bus_t)~USB_ISTR_ESOF;
413415
}
414416

415-
if (int_status & USB_ISTR_PMAOVR) {
416-
TU_BREAKPOINT();
417-
FSDEV_REG->ISTR = (fsdev_bus_t)~USB_ISTR_PMAOVR;
418-
}
419-
420417
// loop to handle all pending CTR interrupts
421418
while (FSDEV_REG->ISTR & USB_ISTR_CTR) {
422419
// skip DIR bit, and use CTR TX/RX instead, since there is chance we have both TX/RX completed in one interrupt
@@ -459,6 +456,11 @@ void dcd_int_handler(uint8_t rhport) {
459456
handle_ctr_tx(ep_id);
460457
}
461458
}
459+
460+
if (int_status & USB_ISTR_PMAOVR) {
461+
TU_BREAKPOINT();
462+
FSDEV_REG->ISTR = (fsdev_bus_t)~USB_ISTR_PMAOVR;
463+
}
462464
}
463465

464466
//--------------------------------------------------------------------+
@@ -806,6 +808,10 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) {
806808
ep_write(ep_idx, ep_reg, true);
807809
}
808810

811+
//--------------------------------------------------------------------+
812+
// PMA read/write
813+
//--------------------------------------------------------------------+
814+
809815
// Write to packet memory area (PMA) from user memory
810816
// - Packet memory must be either strictly 16-bit or 32-bit depending on FSDEV_BUS_32BIT
811817
// - Uses unaligned for RAM (since M0 cannot access unaligned address)

src/portable/st/stm32_fsdev/fsdev_type.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,9 @@ TU_ATTR_ALWAYS_INLINE static inline void btable_set_rx_bufsize(uint32_t ep_id, u
285285
/* Encode into register. When BLSIZE==1, we need to subtract 1 block count */
286286
uint16_t bl_nb = (blsize << 15) | ((num_block - blsize) << 10);
287287
if (bl_nb == 0) {
288-
// zlp but 0 is invalid value, set num_block to 1 (2 bytes)
289-
bl_nb = 1 << 10;
288+
// zlp but 0 is invalid value, set blsize to 1 (32 bytes)
289+
// Note: lower value can cause PMAOVR on setup with ch32v203
290+
bl_nb = 1 << 15;
290291
}
291292

292293
#ifdef FSDEV_BUS_32BIT

test/hil/hil_test.py

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import platform
3737
from multiprocessing import Pool
3838

39-
ENUM_TIMEOUT = 30
39+
ENUM_TIMEOUT = 20
4040

4141

4242
# get usb serial by id
@@ -110,7 +110,8 @@ def run_cmd(cmd):
110110
#print(cmd)
111111
r = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
112112
if r.returncode != 0:
113-
title = 'command error'
113+
title = f'COMMAND FAILED: {cmd}'
114+
print()
114115
if os.getenv('CI'):
115116
print(f"::group::{title}")
116117
print(r.stdout.decode("utf-8"))
@@ -198,14 +199,15 @@ def flash_esptool(board, firmware):
198199
# -------------------------------------------------------------
199200
# Tests
200201
# -------------------------------------------------------------
201-
def test_board_test(id):
202+
def test_board_test(board):
202203
# Dummy test
203204
pass
204205

205206

206-
def test_cdc_dual_ports(id):
207-
port1 = get_serial_dev(id, 'TinyUSB', "TinyUSB_Device", 0)
208-
port2 = get_serial_dev(id, 'TinyUSB', "TinyUSB_Device", 2)
207+
def test_cdc_dual_ports(board):
208+
uid = board['uid']
209+
port1 = get_serial_dev(uid, 'TinyUSB', "TinyUSB_Device", 0)
210+
port2 = get_serial_dev(uid, 'TinyUSB', "TinyUSB_Device", 2)
209211

210212
ser1 = open_serial_dev(port1)
211213
ser2 = open_serial_dev(port2)
@@ -224,9 +226,10 @@ def test_cdc_dual_ports(id):
224226
assert ser2.read(100) == str2.upper(), 'Port2 wrong data'
225227

226228

227-
def test_cdc_msc(id):
229+
def test_cdc_msc(board):
230+
uid = board['uid']
228231
# Echo test
229-
port = get_serial_dev(id, 'TinyUSB', "TinyUSB_Device", 0)
232+
port = get_serial_dev(uid, 'TinyUSB', "TinyUSB_Device", 0)
230233
ser = open_serial_dev(port)
231234

232235
str = b"test_str"
@@ -235,7 +238,7 @@ def test_cdc_msc(id):
235238
assert ser.read(100) == str, 'CDC wrong data'
236239

237240
# Block test
238-
data = read_disk_file(id, 'README.TXT')
241+
data = read_disk_file(uid, 'README.TXT')
239242
readme = \
240243
b"This is tinyusb's MassStorage Class demo.\r\n\r\n\
241244
If you find any bugs or get any questions, feel free to file an\r\n\
@@ -244,26 +247,28 @@ def test_cdc_msc(id):
244247
assert data == readme, 'MSC wrong data'
245248

246249

247-
def test_cdc_msc_freertos(id):
248-
test_cdc_msc(id)
250+
def test_cdc_msc_freertos(board):
251+
test_cdc_msc(board)
249252

250253

251-
def test_dfu(id):
254+
def test_dfu(board):
255+
uid = board['uid']
256+
252257
# Wait device enum
253258
timeout = ENUM_TIMEOUT
254259
while timeout:
255260
ret = subprocess.run(f'dfu-util -l',
256261
shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
257262
stdout = ret.stdout.decode()
258-
if f'serial="{id}"' in stdout and 'Found DFU: [cafe:4000]' in stdout:
263+
if f'serial="{uid}"' in stdout and 'Found DFU: [cafe:4000]' in stdout:
259264
break
260265
time.sleep(1)
261266
timeout = timeout - 1
262267

263268
assert timeout, 'Device not available'
264269

265-
f_dfu0 = f'dfu0_{id}'
266-
f_dfu1 = f'dfu1_{id}'
270+
f_dfu0 = f'dfu0_{uid}'
271+
f_dfu1 = f'dfu1_{uid}'
267272

268273
# Test upload
269274
try:
@@ -272,10 +277,10 @@ def test_dfu(id):
272277
except OSError:
273278
pass
274279

275-
ret = run_cmd(f'dfu-util -S {id} -a 0 -U {f_dfu0}')
280+
ret = run_cmd(f'dfu-util -S {uid} -a 0 -U {f_dfu0}')
276281
assert ret.returncode == 0, 'Upload failed'
277282

278-
ret = run_cmd(f'dfu-util -S {id} -a 1 -U {f_dfu1}')
283+
ret = run_cmd(f'dfu-util -S {uid} -a 1 -U {f_dfu1}')
279284
assert ret.returncode == 0, 'Upload failed'
280285

281286
with open(f_dfu0) as f:
@@ -288,25 +293,28 @@ def test_dfu(id):
288293
os.remove(f_dfu1)
289294

290295

291-
def test_dfu_runtime(id):
296+
def test_dfu_runtime(board):
297+
uid = board['uid']
298+
292299
# Wait device enum
293300
timeout = ENUM_TIMEOUT
294301
while timeout:
295302
ret = subprocess.run(f'dfu-util -l',
296303
shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
297304
stdout = ret.stdout.decode()
298-
if f'serial="{id}"' in stdout and 'Found Runtime: [cafe:4000]' in stdout:
305+
if f'serial="{uid}"' in stdout and 'Found Runtime: [cafe:4000]' in stdout:
299306
break
300307
time.sleep(1)
301308
timeout = timeout - 1
302309

303310
assert timeout, 'Device not available'
304311

305312

306-
def test_hid_boot_interface(id):
307-
kbd = get_hid_dev(id, 'TinyUSB', 'TinyUSB_Device', 'event-kbd')
308-
mouse1 = get_hid_dev(id, 'TinyUSB', 'TinyUSB_Device', 'if01-event-mouse')
309-
mouse2 = get_hid_dev(id, 'TinyUSB', 'TinyUSB_Device', 'if01-mouse')
313+
def test_hid_boot_interface(board):
314+
uid = board['uid']
315+
kbd = get_hid_dev(uid, 'TinyUSB', 'TinyUSB_Device', 'event-kbd')
316+
mouse1 = get_hid_dev(uid, 'TinyUSB', 'TinyUSB_Device', 'if01-event-mouse')
317+
mouse2 = get_hid_dev(uid, 'TinyUSB', 'TinyUSB_Device', 'if01-mouse')
310318
# Wait device enum
311319
timeout = ENUM_TIMEOUT
312320
while timeout:
@@ -338,22 +346,23 @@ def test_hid_composite_freertos(id):
338346
]
339347

340348

341-
def test_board(item):
342-
name = item['name']
343-
flasher = item['flasher'].lower()
349+
def test_board(board):
350+
name = board['name']
351+
flasher = board['flasher'].lower()
344352

345353
# default to all tests
346-
if 'tests' in item:
347-
test_list = item['tests'] + ['board_test']
354+
if 'tests' in board:
355+
test_list = board['tests'] + ['board_test']
348356
else:
349357
test_list = list(all_tests)
350358

351359
# remove skip_tests
352-
if 'tests_skip' in item:
353-
for skip in item['tests_skip']:
360+
if 'tests_skip' in board:
361+
for skip in board['tests_skip']:
354362
if skip in test_list:
355363
test_list.remove(skip)
356364

365+
err_count = 0
357366
for test in test_list:
358367
fw_dir = f'cmake-build/cmake-build-{name}/device/{test}'
359368
if not os.path.exists(fw_dir):
@@ -367,19 +376,26 @@ def test_board(item):
367376

368377
# flash firmware. It may fail randomly, retry a few times
369378
for i in range(3):
370-
ret = globals()[f'flash_{flasher}'](item, fw_name)
379+
ret = globals()[f'flash_{flasher}'](board, fw_name)
371380
if ret.returncode == 0:
372381
break
373382
else:
374383
print(f'Flashing failed, retry {i+1}')
375384
time.sleep(1)
376385

377-
assert ret.returncode == 0, 'Flash failed\n' + ret.stdout.decode()
378-
379-
# run test
380-
globals()[f'test_{test}'](item['uid'])
381-
print('OK')
386+
if ret.returncode == 0:
387+
try:
388+
ret = globals()[f'test_{test}'](board)
389+
print('OK')
390+
except AssertionError as e:
391+
err_count += 1
392+
print('Failed')
393+
print(f' {e}')
394+
else:
395+
err_count += 1
396+
print('Flash failed')
382397

398+
return err_count
383399

384400
def main():
385401
"""
@@ -404,8 +420,11 @@ def main():
404420
else:
405421
config_boards = [e for e in config['boards'] if e['name'] in boards]
406422

423+
err_count_list = 0
407424
with Pool(processes=os.cpu_count()) as pool:
408-
pool.map(test_board, config_boards)
425+
err_count_list = pool.map(test_board, config_boards)
426+
427+
sys.exit(sum(err_count_list))
409428

410429

411430
if __name__ == '__main__':

test/hil/rpi.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@
5757
"flasher": "openocd",
5858
"flasher_sn": "066FFF495087534867063844",
5959
"flasher_args": "-f interface/stlink.cfg -f target/stm32g0x.cfg"
60-
}
61-
],
62-
"boards-skip": [
60+
},
6361
{
6462
"name": "nanoch32v203",
6563
"uid": "CDAB277B0FBC03E339E339E3",
6664
"flasher": "openocd_wch",
6765
"flasher_sn": "EBCA8F0670AF",
6866
"flasher_args": ""
69-
},
67+
}
68+
],
69+
"boards-skip": [
7070
{
7171
"name": "espressif_s3_devkitm",
7272
"uid": "84F703C084E4",

0 commit comments

Comments
 (0)