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>
This commit is contained in:
Koen De Vleeschauwer 2020-06-27 12:23:38 +02:00 committed by Damien George
parent d9bca305e5
commit e7875829c2
3 changed files with 38 additions and 0 deletions

View File

@ -156,6 +156,24 @@ STATIC uint8_t *USBD_StrDescriptor(USBD_HandleTypeDef *pdev, uint8_t idx, uint16
}
break;
#ifdef MICROPY_HW_USB_INTERFACE_CDC0_STRING
case USBD_IDX_INTERFACE_CDC0_STR:
str = MICROPY_HW_USB_INTERFACE_CDC0_STRING;
break;
#endif
#ifdef MICROPY_HW_USB_INTERFACE_CDC1_STRING
case USBD_IDX_INTERFACE_CDC1_STR:
str = MICROPY_HW_USB_INTERFACE_CDC1_STRING;
break;
#endif
#ifdef MICROPY_HW_USB_INTERFACE_CDC2_STRING
case USBD_IDX_INTERFACE_CDC2_STR:
str = MICROPY_HW_USB_INTERFACE_CDC2_STRING;
break;
#endif
default:
// invalid string index
return NULL;

View File

@ -438,6 +438,23 @@ static size_t make_cdc_desc(uint8_t *dest, int need_iad, uint8_t iface_num) {
memcpy(dest, cdc_class_desc_data + 8, sizeof(cdc_class_desc_data) - 8);
}
dest[2] = iface_num; // bInterfaceNumber, main class
#ifdef MICROPY_HW_USB_INTERFACE_CDC0_STRING
if (iface_num == CDC_IFACE_NUM_ALONE || iface_num == CDC_IFACE_NUM_WITH_MSC || iface_num == CDC_IFACE_NUM_WITH_HID) {
dest[8] = USBD_IDX_INTERFACE_CDC0_STR; // iInterface
}
#endif
#ifdef MICROPY_HW_USB_INTERFACE_CDC1_STRING
if (iface_num == CDC2_IFACE_NUM_WITH_CDC || iface_num == CDC2_IFACE_NUM_WITH_MSC) {
dest[8] = USBD_IDX_INTERFACE_CDC1_STR; // iInterface
}
#endif
#ifdef MICROPY_HW_USB_INTERFACE_CDC2_STRING
if (iface_num == CDC3_IFACE_NUM_WITH_CDC || iface_num == CDC3_IFACE_NUM_WITH_MSC) {
dest[8] = USBD_IDX_INTERFACE_CDC2_STR; // iInterface
}
#endif
dest[18] = iface_num + 1; // bDataInterface
dest[26] = iface_num + 0; // bMasterInterface
dest[27] = iface_num + 1; // bSlaveInterface

View File

@ -66,6 +66,9 @@
#define USBD_IDX_SERIAL_STR 0x03
#define USBD_IDX_CONFIG_STR 0x04
#define USBD_IDX_INTERFACE_STR 0x05
#define USBD_IDX_INTERFACE_CDC0_STR 0x06
#define USBD_IDX_INTERFACE_CDC1_STR 0x07
#define USBD_IDX_INTERFACE_CDC2_STR 0x08
#define USB_REQ_TYPE_STANDARD 0x00
#define USB_REQ_TYPE_CLASS 0x20