summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2025-08-01 21:27:27 +0800
committersakumisu <[email protected]>2025-08-01 21:38:47 +0800
commit20ceaced928ea5959d05c37296907e1e85e7336d (patch)
tree9e124d2e52faed7e0a8e2160689b5adb4c1e26d0
parent9ddcbf58caab13b7b4bcfaa19d2a9f4d5072c658 (diff)
update(core/usbh_core): check string support and then get string desc
Signed-off-by: sakumisu <[email protected]>
-rw-r--r--core/usbh_core.c56
1 files changed, 34 insertions, 22 deletions
diff --git a/core/usbh_core.c b/core/usbh_core.c
index 097cd9c8..dc292e13 100644
--- a/core/usbh_core.c
+++ b/core/usbh_core.c
@@ -530,35 +530,47 @@ int usbh_enumerate(struct usbh_hubport *hport)
#ifdef CONFIG_USBHOST_GET_STRING_DESC
uint8_t string_buffer[128];
- /* Get Manufacturer string */
- memset(string_buffer, 0, 128);
- ret = usbh_get_string_desc(hport, USB_STRING_MFC_INDEX, string_buffer, 128);
- if (ret < 0) {
- USB_LOG_ERR("Failed to get Manufacturer string,errorcode:%d\r\n", ret);
- goto errout;
+ if (hport->device_desc.iManufacturer > 0) {
+ /* Get Manufacturer string */
+ memset(string_buffer, 0, 128);
+ ret = usbh_get_string_desc(hport, USB_STRING_MFC_INDEX, string_buffer, 128);
+ if (ret < 0) {
+ USB_LOG_ERR("Failed to get Manufacturer string,errorcode:%d\r\n", ret);
+ goto errout;
+ }
+
+ USB_LOG_INFO("Manufacturer: %s\r\n", string_buffer);
+ } else {
+ USB_LOG_WRN("Do not support Manufacturer string\r\n");
}
- USB_LOG_INFO("Manufacturer: %s\r\n", string_buffer);
+ if (hport->device_desc.iProduct > 0) {
+ /* Get Product string */
+ memset(string_buffer, 0, 128);
+ ret = usbh_get_string_desc(hport, USB_STRING_PRODUCT_INDEX, string_buffer, 128);
+ if (ret < 0) {
+ USB_LOG_ERR("Failed to get Product string,errorcode:%d\r\n", ret);
+ goto errout;
+ }
- /* Get Product string */
- memset(string_buffer, 0, 128);
- ret = usbh_get_string_desc(hport, USB_STRING_PRODUCT_INDEX, string_buffer, 128);
- if (ret < 0) {
- USB_LOG_ERR("Failed to get get Product string,errorcode:%d\r\n", ret);
- goto errout;
+ USB_LOG_INFO("Product: %s\r\n", string_buffer);
+ } else {
+ USB_LOG_WRN("Do not support Product string\r\n");
}
- USB_LOG_INFO("Product: %s\r\n", string_buffer);
+ if (hport->device_desc.iSerialNumber > 0) {
+ /* Get SerialNumber string */
+ memset(string_buffer, 0, 128);
+ ret = usbh_get_string_desc(hport, USB_STRING_SERIAL_INDEX, string_buffer, 128);
+ if (ret < 0) {
+ USB_LOG_ERR("Failed to get SerialNumber string,errorcode:%d\r\n", ret);
+ goto errout;
+ }
- /* Get SerialNumber string */
- memset(string_buffer, 0, 128);
- ret = usbh_get_string_desc(hport, USB_STRING_SERIAL_INDEX, string_buffer, 128);
- if (ret < 0) {
- USB_LOG_ERR("Failed to get get SerialNumber string,errorcode:%d\r\n", ret);
- goto errout;
+ USB_LOG_INFO("SerialNumber: %s\r\n", string_buffer);
+ } else {
+ USB_LOG_WRN("Do not support SerialNumber string\r\n");
}
-
- USB_LOG_INFO("SerialNumber: %s\r\n", string_buffer);
#endif
/* Select device configuration 1 */
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_STANDARD | USB_REQUEST_RECIPIENT_DEVICE;