Skip to content

Commit

Permalink
Merge pull request #2762 from hathach/fsdev_iso_fix
Browse files Browse the repository at this point in the history
Fsdev iso fix
  • Loading branch information
hathach authored Aug 13, 2024
2 parents ac1fd32 + 86419df commit 9d8052b
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 111 deletions.
114 changes: 57 additions & 57 deletions .idea/cmake.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions hw/bsp/ch32v20x/boards/nanoch32v203/board.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set(MCU_VARIANT D6)

# 64KB zero-wait, 224KB total flash
#set(LD_FLASH_SIZE 64K)
set(LD_FLASH_SIZE 224K)
set(LD_FLASH_SIZE 64K)
#set(LD_FLASH_SIZE 224K)
set(LD_RAM_SIZE 20K)

function(update_board TARGET)
Expand Down
1 change: 1 addition & 0 deletions hw/bsp/stm32f1/boards/stm32f103ze_iar/board.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(MCU_VARIANT stm32f103xe)
set(JLINK_DEVICE stm32f103ze)
#set(JLINK_OPTION "-USB 320000338")

string(TOUPPER ${MCU_VARIANT} MCU_VARIANT_UPPER)

Expand Down
9 changes: 5 additions & 4 deletions hw/bsp/stm32l0/boards/stm32l052dap52/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,17 @@
//--------------------------------------------------------------------+
static inline void board_stm32l0_clock_init(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
static RCC_CRSInitTypeDef RCC_CRSInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
RCC_CRSInitTypeDef RCC_CRSInitStruct = {0};

/* Enable HSI Oscillator to be used as System clock source
Enable HSI48 Oscillator to be used as USB clock source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

/* Select HSI48 as USB clock source */
Expand Down
1 change: 1 addition & 0 deletions hw/bsp/stm32l0/boards/stm32l0538disco/board.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(MCU_VARIANT stm32l053xx)
set(JLINK_DEVICE stm32l053r8)
#set(JLINK_OPTION "-USB 778921770")

set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32L053C8Tx_FLASH.ld)

Expand Down
9 changes: 5 additions & 4 deletions hw/bsp/stm32l0/boards/stm32l0538disco/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,17 @@
//--------------------------------------------------------------------+
static inline void board_stm32l0_clock_init(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
static RCC_CRSInitTypeDef RCC_CRSInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
RCC_CRSInitTypeDef RCC_CRSInitStruct = {0};

/* Enable HSI Oscillator to be used as System clock source
Enable HSI48 Oscillator to be used as USB clock source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

/* Select HSI48 as USB clock source */
Expand Down
24 changes: 12 additions & 12 deletions src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static uint8_t remoteWakeCountdown; // When wake is requested
// into the stack.
static void handle_bus_reset(uint8_t rhport);
static void dcd_transmit_packet(xfer_ctl_t *xfer, uint16_t ep_ix);
static bool edpt_xfer(uint8_t rhport, uint8_t ep_num, uint8_t dir);
static bool edpt_xfer(uint8_t rhport, uint8_t ep_num, tusb_dir_t dir);

// PMA allocation/access
static uint16_t ep_buf_ptr; ///< Points to first free memory location
Expand Down Expand Up @@ -275,7 +275,6 @@ static void handle_bus_reset(uint8_t rhport) {
// Handle CTR interrupt for the TX/IN direction
static void handle_ctr_tx(uint32_t ep_id) {
uint32_t ep_reg = ep_read(ep_id) | USB_EP_CTR_TX | USB_EP_CTR_RX;
ep_reg &= USB_EPREG_MASK;

uint8_t const ep_num = ep_reg & USB_EPADDR_FIELD;
xfer_ctl_t *xfer = xfer_ctl_ptr(ep_num, TUSB_DIR_IN);
Expand Down Expand Up @@ -578,7 +577,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_ep) {
(void)rhport;
uint8_t const ep_addr = desc_ep->bEndpointAddress;
uint8_t const ep_num = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
tusb_dir_t const dir = tu_edpt_dir(ep_addr);
const uint16_t packet_size = tu_edpt_packet_size(desc_ep);
uint8_t const ep_idx = dcd_ep_alloc(ep_addr, desc_ep->bmAttributes.xfer);
TU_ASSERT(ep_idx < FSDEV_EP_COUNT);
Expand Down Expand Up @@ -651,10 +650,11 @@ bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet

/* Create a packet memory buffer area. Enable double buffering for devices with 2048 bytes PMA,
for smaller devices double buffering occupy too much space. */
uint32_t pma_addr = dcd_pma_alloc(largest_packet_size, true);
#if FSDEV_PMA_SIZE > 1024u
uint32_t pma_addr = dcd_pma_alloc(largest_packet_size, true);
uint16_t pma_addr2 = pma_addr >> 16;
#else
uint32_t pma_addr = dcd_pma_alloc(largest_packet_size, false);
uint16_t pma_addr2 = pma_addr;
#endif

Expand All @@ -671,7 +671,7 @@ bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const *desc_ep)
(void)rhport;
uint8_t const ep_addr = desc_ep->bEndpointAddress;
uint8_t const ep_num = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
tusb_dir_t const dir = tu_edpt_dir(ep_addr);
xfer_ctl_t* xfer = xfer_ctl_ptr(ep_num, dir);

uint8_t const ep_idx = xfer->ep_idx;
Expand All @@ -683,7 +683,7 @@ bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const *desc_ep)
ep_change_status(&ep_reg, TUSB_DIR_IN, EP_STAT_DISABLED);
ep_change_status(&ep_reg, TUSB_DIR_OUT, EP_STAT_DISABLED);
ep_change_dtog(&ep_reg, dir, 0);
ep_change_dtog(&ep_reg, 1 - dir, 1);
ep_change_dtog(&ep_reg, (tusb_dir_t)(1 - dir), 1);

ep_write(ep_idx, ep_reg, true);

Expand All @@ -694,7 +694,6 @@ bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const *desc_ep)
static void dcd_transmit_packet(xfer_ctl_t *xfer, uint16_t ep_ix) {
uint16_t len = tu_min16(xfer->total_len - xfer->queued_len, xfer->max_packet_size);
uint32_t ep_reg = ep_read(ep_ix) | USB_EP_CTR_TX | USB_EP_CTR_RX; // reserve CTR
ep_reg &= USB_EPREG_MASK | EP_STAT_MASK(TUSB_DIR_IN); // only change TX Status, reserve other toggle bits

bool const is_iso = ep_is_iso(ep_reg);

Expand All @@ -719,10 +718,11 @@ static void dcd_transmit_packet(xfer_ctl_t *xfer, uint16_t ep_ix) {
if (is_iso) {
xfer->iso_in_sending = true;
}
ep_reg &= USB_EPREG_MASK | EP_STAT_MASK(TUSB_DIR_IN); // only change TX Status, reserve other toggle bits
ep_write(ep_ix, ep_reg, true);
}

static bool edpt_xfer(uint8_t rhport, uint8_t ep_num, uint8_t dir) {
static bool edpt_xfer(uint8_t rhport, uint8_t ep_num, tusb_dir_t dir) {
(void) rhport;

xfer_ctl_t *xfer = xfer_ctl_ptr(ep_num, dir);
Expand Down Expand Up @@ -752,7 +752,7 @@ static bool edpt_xfer(uint8_t rhport, uint8_t ep_num, uint8_t dir) {

bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes) {
uint8_t const ep_num = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
tusb_dir_t const dir = tu_edpt_dir(ep_addr);
xfer_ctl_t *xfer = xfer_ctl_ptr(ep_num, dir);

xfer->buffer = buffer;
Expand All @@ -765,7 +765,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to

bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t *ff, uint16_t total_bytes) {
uint8_t const ep_num = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
tusb_dir_t const dir = tu_edpt_dir(ep_addr);
xfer_ctl_t *xfer = xfer_ctl_ptr(ep_num, dir);

xfer->buffer = NULL;
Expand All @@ -779,7 +779,7 @@ bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t *ff, uint16_t
void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) {
(void)rhport;
uint8_t const ep_num = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
tusb_dir_t const dir = tu_edpt_dir(ep_addr);
xfer_ctl_t *xfer = xfer_ctl_ptr(ep_num, dir);
uint8_t const ep_idx = xfer->ep_idx;

Expand All @@ -794,7 +794,7 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) {
(void)rhport;

uint8_t const ep_num = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
tusb_dir_t const dir = tu_edpt_dir(ep_addr);
xfer_ctl_t *xfer = xfer_ctl_ptr(ep_num, dir);
uint8_t const ep_idx = xfer->ep_idx;

Expand Down
47 changes: 24 additions & 23 deletions test/hil/hil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import subprocess
import json
import glob
import platform
from multiprocessing import Pool
import fs

ENUM_TIMEOUT = 20
ENUM_TIMEOUT = 30


# get usb serial by id
Expand All @@ -53,9 +53,8 @@ def get_serial_dev(id, vendor_str, product_str, ifnum):
return port_list[0]


# Currently not used, left as reference
# get usb disk by id
def get_disk_dev(id, vendor_str, lun):
# get usb disk by id
return f'/dev/disk/by-id/usb-{vendor_str}_Mass_Storage_{id}-0:{lun}'


Expand All @@ -72,34 +71,35 @@ def open_serial_dev(port):
# slight delay since kernel may occupy the port briefly
time.sleep(0.5)
timeout = timeout - 0.5
ser = serial.Serial(port, timeout=1)
ser = serial.Serial(port, timeout=5)
break
except serial.SerialException:
pass
time.sleep(0.5)
timeout = timeout - 0.5
assert timeout, 'Device not available or Cannot open port'

assert timeout, f'Cannot open port f{port}' if os.path.exists(port) else f'Port {port} not existed'
return ser


def read_disk_file(id, fname):
# on different self-hosted, the mount point is different
file_list = [
f'/media/blkUSB_{id[-8:]}.02/{fname}',
f'/media/{os.getenv("USER")}/TinyUSB MSC/{fname}'
]
def read_disk_file(uid, lun, fname):
# open_fs("fat://{dev}) require 'pip install pyfatfs'
dev = get_disk_dev(uid, 'TinyUSB', lun)
timeout = ENUM_TIMEOUT
while timeout:
for file in file_list:
if os.path.isfile(file):
with open(file, 'rb') as f:
if os.path.exists(dev):
fat = fs.open_fs(f'fat://{dev}?read_only=true')
try:
with fat.open(fname, 'rb') as f:
data = f.read()
return data

finally:
fat.close()
assert data, f'Cannot read file {fname} from {dev}'
return data
time.sleep(1)
timeout = timeout - 1
timeout -= 1

assert timeout, 'Device not available'
assert timeout, f'Storage {dev} not existed'
return None


Expand Down Expand Up @@ -238,7 +238,7 @@ def test_cdc_msc(board):
assert ser.read(100) == str, 'CDC wrong data'

# Block test
data = read_disk_file(uid, 'README.TXT')
data = read_disk_file(uid,0,'README.TXT')
readme = \
b"This is tinyusb's MassStorage Class demo.\r\n\r\n\
If you find any bugs or get any questions, feel free to file an\r\n\
Expand Down Expand Up @@ -323,7 +323,7 @@ def test_hid_boot_interface(board):
time.sleep(1)
timeout = timeout - 1

assert timeout, 'Device not available'
assert timeout, 'HID device not available'


def test_hid_composite_freertos(id):
Expand All @@ -338,8 +338,8 @@ def test_hid_composite_freertos(id):
all_tests = [
'cdc_dual_ports',
'cdc_msc',
'cdc_msc_freertos',
'dfu',
'cdc_msc_freertos', # dont test 2 cdc_msc next to each other, since they have same vid/pid. Can be confused by host
'dfu_runtime',
'hid_boot_interface',
'board_test'
Expand Down Expand Up @@ -387,7 +387,7 @@ def test_board(board):
try:
ret = globals()[f'test_{test}'](board)
print('OK')
except AssertionError as e:
except Exception as e:
err_count += 1
print('Failed')
print(f' {e}')
Expand All @@ -397,6 +397,7 @@ def test_board(board):

return err_count


def main():
"""
Hardware test on specified boards
Expand Down
15 changes: 8 additions & 7 deletions test/hil/rpi.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
"flasher_sn": "E6614C311B597D32",
"flasher_args": "-f interface/cmsis-dap.cfg -f target/atsame5x.cfg -c \"adapter speed 5000\""
},
{
"name": "metro_m7_1011",
"uid": "9CE8715DD71137363E00005002004200",
"flasher": "jlink",
"flasher_sn": "000611000000",
"flasher_args": "-device MIMXRT1011xxx5A"
},
{
"name": "lpcxpresso11u37",
"uid": "17121919",
Expand Down Expand Up @@ -67,6 +60,14 @@
}
],
"boards-skip": [
{
"name": "metro_m7_1011",
"uid": "9CE8715DD71137363E00005002004200",
"flasher": "jlink",
"flasher_sn": "000611000000",
"flasher_args": "-device MIMXRT1011xxx5A",
"comment": "not running reliably in bulk with other boards, probably power, flashing etc .."
},
{
"name": "espressif_s3_devkitm",
"uid": "84F703C084E4",
Expand Down
4 changes: 2 additions & 2 deletions tools/get_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
'hw/mcu/nxp/mcux-sdk': ['https://github.com/hathach/mcux-sdk.git',
'144f1eb7ea8c06512e12f12b27383601c0272410',
'kinetis_k kinetis_k32l2 kinetis_kl lpc51 lpc54 lpc55 mcx imxrt'],
'hw/mcu/raspberry_pi/Pico-PIO-USB': ['https://github.com/adafruit/Pico-PIO-USB.git',
'770e3b2e4af14dd202f062f850f9f14820ecbb1e',
'hw/mcu/raspberry_pi/Pico-PIO-USB': ['https://github.com/sekigon-gonnoc/Pico-PIO-USB.git',
'7902e9fa8ed4a271d8d1d5e7e50516c2292b7bc2',
'rp2040'],
'hw/mcu/renesas/fsp': ['https://github.com/renesas/fsp.git',
'd52e5a6a59b7c638da860c2bb309b6e78e752ff8',
Expand Down

0 comments on commit 9d8052b

Please sign in to comment.