Skip to content

Commit e787582

Browse files
koendvdpgeorge
authored andcommitted
stm32/usbd_desc: Support USB strings on CDC interface descriptors.
A board can now name the CDC ports, eg: #define MICROPY_HW_USB_CDC_NUM (3) #define MICROPY_HW_USB_INTERFACE_CDC0_STRING "REPL" #define MICROPY_HW_USB_INTERFACE_CDC1_STRING "GDB Server" #define MICROPY_HW_USB_INTERFACE_CDC2_STRING "UART Port" Signed-off-by: Damien George <damien@micropython.org>
1 parent d9bca30 commit e787582

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

ports/stm32/usbd_desc.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,24 @@ STATIC uint8_t *USBD_StrDescriptor(USBD_HandleTypeDef *pdev, uint8_t idx, uint16
156156
}
157157
break;
158158

159+
#ifdef MICROPY_HW_USB_INTERFACE_CDC0_STRING
160+
case USBD_IDX_INTERFACE_CDC0_STR:
161+
str = MICROPY_HW_USB_INTERFACE_CDC0_STRING;
162+
break;
163+
#endif
164+
165+
#ifdef MICROPY_HW_USB_INTERFACE_CDC1_STRING
166+
case USBD_IDX_INTERFACE_CDC1_STR:
167+
str = MICROPY_HW_USB_INTERFACE_CDC1_STRING;
168+
break;
169+
#endif
170+
171+
#ifdef MICROPY_HW_USB_INTERFACE_CDC2_STRING
172+
case USBD_IDX_INTERFACE_CDC2_STR:
173+
str = MICROPY_HW_USB_INTERFACE_CDC2_STRING;
174+
break;
175+
#endif
176+
159177
default:
160178
// invalid string index
161179
return NULL;

ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,23 @@ static size_t make_cdc_desc(uint8_t *dest, int need_iad, uint8_t iface_num) {
438438
memcpy(dest, cdc_class_desc_data + 8, sizeof(cdc_class_desc_data) - 8);
439439
}
440440
dest[2] = iface_num; // bInterfaceNumber, main class
441+
442+
#ifdef MICROPY_HW_USB_INTERFACE_CDC0_STRING
443+
if (iface_num == CDC_IFACE_NUM_ALONE || iface_num == CDC_IFACE_NUM_WITH_MSC || iface_num == CDC_IFACE_NUM_WITH_HID) {
444+
dest[8] = USBD_IDX_INTERFACE_CDC0_STR; // iInterface
445+
}
446+
#endif
447+
#ifdef MICROPY_HW_USB_INTERFACE_CDC1_STRING
448+
if (iface_num == CDC2_IFACE_NUM_WITH_CDC || iface_num == CDC2_IFACE_NUM_WITH_MSC) {
449+
dest[8] = USBD_IDX_INTERFACE_CDC1_STR; // iInterface
450+
}
451+
#endif
452+
#ifdef MICROPY_HW_USB_INTERFACE_CDC2_STRING
453+
if (iface_num == CDC3_IFACE_NUM_WITH_CDC || iface_num == CDC3_IFACE_NUM_WITH_MSC) {
454+
dest[8] = USBD_IDX_INTERFACE_CDC2_STR; // iInterface
455+
}
456+
#endif
457+
441458
dest[18] = iface_num + 1; // bDataInterface
442459
dest[26] = iface_num + 0; // bMasterInterface
443460
dest[27] = iface_num + 1; // bSlaveInterface

ports/stm32/usbdev/core/inc/usbd_def.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
#define USBD_IDX_SERIAL_STR 0x03
6767
#define USBD_IDX_CONFIG_STR 0x04
6868
#define USBD_IDX_INTERFACE_STR 0x05
69+
#define USBD_IDX_INTERFACE_CDC0_STR 0x06
70+
#define USBD_IDX_INTERFACE_CDC1_STR 0x07
71+
#define USBD_IDX_INTERFACE_CDC2_STR 0x08
6972

7073
#define USB_REQ_TYPE_STANDARD 0x00
7174
#define USB_REQ_TYPE_CLASS 0x20

0 commit comments

Comments
 (0)