Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions drivers/usb/uhc/uhc_renesas_ra.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ static int uhc_renesas_ra_event_xfer_complete(const struct device *dev, usbh_eve

switch (hal_evt->complete.result) {
case USB_XFER_RESULT_STALLED:
uhc_xfer_return(dev, priv->last_xfer, -ENOTSUP);
ret = -EAGAIN;
break;
case USB_XFER_RESULT_TIMEOUT:
case USB_XFER_RESULT_FAILED:
uhc_xfer_return(dev, priv->last_xfer, -EPIPE);
Expand Down Expand Up @@ -428,6 +431,11 @@ static int uhc_renesas_ra_ep_dequeue(const struct device *dev, struct uhc_transf
uhc_xfer_free(dev, xfer);
}

if (last_xfer == NULL) {
/* The previous transfer has already been fired */
return -EALREADY;
}

err = R_USBH_XferAbort(&priv->uhc_ctrl, last_xfer->udev->addr, last_xfer->ep);
if (err != FSP_SUCCESS) {
return -EIO;
Expand Down
11 changes: 11 additions & 0 deletions include/zephyr/drivers/usb/uhc.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ struct usb_device {
struct usb_host_ep ep_out[16];
/** Pointers to device IN endpoints */
struct usb_host_ep ep_in[16];
/** Pointer to the hub to which this device is connected */
struct usb_device *hub;
/** Device's hub Think Time */
uint16_t tt;
/** Device's hub port */
uint8_t hub_port;
/** Device's level (root device = 0) */
uint8_t level;
};

/**
Expand Down Expand Up @@ -334,6 +342,9 @@ static inline int uhc_bus_reset(const struct device *dev)

api->lock(dev);
ret = api->bus_reset(dev);
if (ret == 0) {
k_sleep(K_MSEC(10));
}
api->unlock(dev);

return ret;
Expand Down
2 changes: 1 addition & 1 deletion subsys/usb/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: Copyright Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

if(CONFIG_USBD_VIDEO_CLASS OR CONFIG_USBH_VIDEO_CLASS)
if(CONFIG_USBD_VIDEO_CLASS OR CONFIG_USBH_VIDEO_CLASS OR CONFIG_USBD_MSC_CLASS OR CONFIG_USBH_MSC_CLASS)
zephyr_include_directories(.)
zephyr_sources(uvc.c)
endif()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain why the MSC class build includes uvc.c?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MSC drivers doesn't strictly need uvc.c, just the directory inclusion to access subsus/usb/common and include msc.h. I'll update the file reflect this.

52 changes: 52 additions & 0 deletions subsys/usb/common/msc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* SPDX-FileCopyrightText: Copyright 2026 Renesas, Embedd
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief USB Mass Storage Class private header
*
* Header follows below documentation:
* - USB Device Class Definition for Mass Storage Class Devices (Revision 1.4)
* - SCSI Primary Commands 7
* - SCSI Block Commands 7
*/

#ifndef ZEPHYR_SUBSYS_USB_COMMON_MSC_H
#define ZEPHYR_SUBSYS_USB_COMMON_MSC_H

/* Subclass and Protocol codes */
#define SCSI_TRANSPARENT_COMMAND_SET 0x06
#define BULK_ONLY_TRANSPORT 0x50

/* Control requests */
#define GET_MAX_LUN 0xFE
#define BULK_ONLY_MASS_STORAGE_RESET 0xFF

/* Command wrapper */
#define CBW_SIGNATURE 0x43425355u
#define CSW_SIGNATURE 0x53425355u

#define CBW_FLAGS_DIRECTION_IN 0x80
#define CBW_FLAGS_RESERVED_MASK 0x3F

/* Used to determine if a device is ready to transfer data */
#define SCSI_COMMAND_TEST_UNIT_READY 0x00u
/* Requests that the device server transfer sense data to the application client */
#define SCSI_COMMAND_REQUEST_SENSE 0x03u
/* Requests that the device server transfer mode data */
#define SCSI_COMMAND_MODE_SENSE_6 0x1Au
/* Requests that the device server transfer capacity and medium format information */
#define SCSI_COMMAND_READ_CAPACITY_10 0x25u
/* Requests that the device server read the specified logical blocks */
#define SCSI_COMMAND_READ_10 0x28u
/* Requests that the device server write the specified logical blocks */
#define SCSI_COMMAND_WRITE_10 0x2Au
/* Requests that the device server ensure that the specified logical blocks have their most recent
data values recorded in non-volatile cache and/or on the medium */
#define SCSI_COMMAND_SYNCHRONIZE_CACHE_10 0x35u
/* Requests that the device server transfer mode data */
#define SCSI_COMMAND_MODE_SENSE_10 0x5Au

#endif /* ZEPHYR_SUBSYS_USB_COMMON_MSC_H */
5 changes: 5 additions & 0 deletions subsys/usb/host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ zephyr_library_sources_ifdef(
class/usbh_uvc.c
)

zephyr_library_sources_ifdef(
CONFIG_USBH_MSC_CLASS
class/usbh_msc.c
)

zephyr_library_sources_ifdef(
CONFIG_USBIP
usbip.c
Expand Down
1 change: 1 addition & 0 deletions subsys/usb/host/class/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# SPDX-License-Identifier: Apache-2.0

rsource "Kconfig.uvc"
rsource "Kconfig.msc"
55 changes: 55 additions & 0 deletions subsys/usb/host/class/Kconfig.msc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SPDX-FileCopyrightText: Copyright 2026 Renesas, Embedd
# SPDX-License-Identifier: Apache-2.0

config USBH_MSC_CLASS
bool "USB host Mass Storage Class support [EXPERIMENTAL]"
select EXPERIMENTAL
Comment on lines +4 to +6

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing select DISK_ACCESS

help
USB Mass Storage Class (MSC) implementation.

if USBH_MSC_CLASS

config USBH_MSC_INSTANCES_COUNT
int "Number of HOST MSC instances"
default 4
help
Number of instances of this USB class

config USBH_MSC_TEST_UNIT_READY_ATTEMPTS
int "Number of attempts for unit ready command"
default 5
help
Before an MSC device can be used it must be tested for readyness. It may respond
negatively, and this is the amount of attempts the test is repeated for before failing.

config USBH_MSC_RECOVERY_ATTEMPTS
int "Number of recovery attempts in case of error"
default 5
help
A SCSI transaction may fail due to USB protocol issues (hardware disturbances, device
refuses to comply); in this case a reset is required. This is the number of times the host
driver attempts to reset communication and retry the transaction before failing.

config USBH_MSC_MAX_SUPPORTED_LUN
int "Maximum number of logical units supported by the driver"
default 4
help
An MSC device may expose more than one drive in its interface. They are advertised as LUN
(Logical UNits) when the device is first connected and each one should result in a
different mount point. This configuration parameter specifies how many the driver can
handle for each device.

config USBH_MSC_IGNORE_SYNC
bool "Do not attempt to sync data from the device's caches"
default y
help
A lot of cheap MSC devices don't support the SYNCHRONIZE CACHE command; this option skips
it.

module = USBH_MSC
module-str = usbh msc
default-count = 1
source "subsys/logging/Kconfig.template.log_config"
source "subsys/usb/common/Kconfig.template.instances_count"

endif # USBH_MSC_CLASS
Loading