From f6d338c1b192a2e5dc81dfcbfe07423c36c20648 Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Tue, 11 Mar 2025 15:23:47 +0100 Subject: [PATCH] usb: host: fix set/clear feature shell commands Implement Set/Clear Feature endpoint halt request and fix the corresponding commands in the shell. Signed-off-by: Johann Fischer --- subsys/usb/host/usbh_ch9.c | 24 ++++++++++++++++++++++++ subsys/usb/host/usbh_ch9.h | 4 ++++ subsys/usb/host/usbh_shell.c | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/subsys/usb/host/usbh_ch9.c b/subsys/usb/host/usbh_ch9.c index 5091947b791..29b01ea1624 100644 --- a/subsys/usb/host/usbh_ch9.c +++ b/subsys/usb/host/usbh_ch9.c @@ -247,6 +247,30 @@ int usbh_req_clear_sfs_rwup(struct usb_device *const udev) NULL); } +int usbh_req_set_sfs_halt(struct usb_device *const udev, const uint8_t ep) +{ + const uint8_t bmRequestType = USB_REQTYPE_RECIPIENT_ENDPOINT; + const uint8_t bRequest = USB_SREQ_SET_FEATURE; + const uint16_t wValue = USB_SFS_ENDPOINT_HALT; + const uint16_t wIndex = ep; + + return usbh_req_setup(udev, + bmRequestType, bRequest, wValue, wIndex, 0, + NULL); +} + +int usbh_req_clear_sfs_halt(struct usb_device *const udev, const uint8_t ep) +{ + const uint8_t bmRequestType = USB_REQTYPE_RECIPIENT_ENDPOINT; + const uint8_t bRequest = USB_SREQ_CLEAR_FEATURE; + const uint16_t wValue = USB_SFS_ENDPOINT_HALT; + const uint16_t wIndex = ep; + + return usbh_req_setup(udev, + bmRequestType, bRequest, wValue, wIndex, 0, + NULL); +} + int usbh_req_set_hcfs_ppwr(struct usb_device *const udev, const uint8_t port) { diff --git a/subsys/usb/host/usbh_ch9.h b/subsys/usb/host/usbh_ch9.h index ff7f49bc96b..9e585c8dab6 100644 --- a/subsys/usb/host/usbh_ch9.h +++ b/subsys/usb/host/usbh_ch9.h @@ -52,6 +52,10 @@ int usbh_req_set_sfs_rwup(struct usb_device *const udev); int usbh_req_clear_sfs_rwup(struct usb_device *const udev); +int usbh_req_set_sfs_halt(struct usb_device *const udev, const uint8_t ep); + +int usbh_req_clear_sfs_halt(struct usb_device *const udev, const uint8_t ep); + int usbh_req_set_hcfs_ppwr(const struct usb_device *udev, const uint8_t port); diff --git a/subsys/usb/host/usbh_shell.c b/subsys/usb/host/usbh_shell.c index ee1685e34c6..2832e644d08 100644 --- a/subsys/usb/host/usbh_shell.c +++ b/subsys/usb/host/usbh_shell.c @@ -300,6 +300,34 @@ static int cmd_desc_string(const struct shell *sh, return err; } +static int cmd_feature_clear_halt(const struct shell *sh, + size_t argc, char **argv) +{ + static struct usb_device *udev; + uint8_t addr; + uint8_t ep; + int err; + + addr = strtol(argv[1], NULL, 10); + udev = usbh_device_get(&uhs_ctx, addr); + if (udev == NULL) { + shell_error(sh, "host: No USB device with address %u", addr); + return -ENOMEM; + } + + ep = strtol(argv[2], NULL, 16); + + err = usbh_req_clear_sfs_halt(udev, ep); + if (err) { + shell_error(sh, "host: Failed to clear halt feature"); + } else { + shell_print(sh, "host: Device 0x%02x, ep 0x%02x halt feature cleared", + udev->addr, ep); + } + + return err; +} + static int cmd_feature_set_halt(const struct shell *sh, size_t argc, char **argv) { @@ -317,8 +345,7 @@ static int cmd_feature_set_halt(const struct shell *sh, ep = strtol(argv[2], NULL, 16); - /* TODO: add usbh_req_set_sfs_halt(&uhs_ctx, NULL, 0); */ - err = usbh_req_set_sfs_rwup(udev); + err = usbh_req_set_sfs_halt(udev, ep); if (err) { shell_error(sh, "host: Failed to set halt feature"); } else { @@ -684,7 +711,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(feature_clear_cmds, SHELL_CMD_ARG(rwup, NULL, "", cmd_feature_clear_rwup, 2, 0), SHELL_CMD_ARG(halt, NULL, " ", - cmd_feature_set_halt, 3, 0), + cmd_feature_clear_halt, 3, 0), SHELL_SUBCMD_SET_END );