stm32/usbd_msc_interface: Allow configuring the MSC inquiry response.

This was previously hard-coded to "MicroPy" / "pyboard Flash" / "1.00".

Now allow it to be overridden by a board.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2023-09-01 16:02:29 +10:00 committed by Damien George
parent d7f63f994f
commit 61f331374d
2 changed files with 31 additions and 14 deletions

View File

@ -256,6 +256,21 @@
#define MICROPY_HW_USB_INTERFACE_FS_STRING "Pyboard Interface"
#endif
// Must be 8 bytes.
#ifndef MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING
#define MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING "MicroPy "
#endif
// Must be 16 bytes.
#ifndef MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING
#define MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING "pyboard Flash "
#endif
// Must be 4 bytes.
#ifndef MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING
#define MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING "1.00"
#endif
// Amount of incoming buffer space for each CDC instance.
// This must be 2 or greater, and a power of 2.
#ifndef MICROPY_HW_USB_CDC_RX_DATA_SIZE

View File

@ -90,20 +90,17 @@ STATIC const uint8_t usbd_msc_vpd83[4] = {
0x00, 0x00, // page length (additional bytes beyond this entry)
};
STATIC const int8_t usbd_msc_inquiry_data[36] = {
0x00, // peripheral qualifier; peripheral device type
0x80, // 0x00 for a fixed drive, 0x80 for a removable drive
0x02, // version
0x02, // response data format
(STANDARD_INQUIRY_DATA_LEN - 5), // additional length
0x00, // various flags
0x00, // various flags
0x00, // various flags
'M', 'i', 'c', 'r', 'o', 'P', 'y', ' ', // Manufacturer : 8 bytes
'p', 'y', 'b', 'o', 'a', 'r', 'd', ' ', // Product : 16 Bytes
'F', 'l', 'a', 's', 'h', ' ', ' ', ' ',
'1', '.', '0', '0', // Version : 4 Bytes
};
STATIC const int8_t usbd_msc_inquiry_data[STANDARD_INQUIRY_DATA_LEN] = \
"\x00" // peripheral qualifier; peripheral device type
"\x80" // 0x00 for a fixed drive, 0x80 for a removable drive
"\x02" // version
"\x02" // response data format
"\x1f" // 0x1f = (STANDARD_INQUIRY_DATA_LEN - 5) = 0x24 - 5
"\x00\x00\x00" // various flags
MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING // 8 bytes
MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING // 16 bytes
MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING // 4 bytes
;
// Set the logical units that will be exposed over MSC
void usbd_msc_init_lu(size_t lu_n, const void *lu_data) {
@ -210,6 +207,11 @@ STATIC int usbd_msc_Inquiry(uint8_t lun, const uint8_t *params, uint8_t *data_ou
return -1;
}
// These strings must be padded to the expected length. (+1 here for null terminator).
MP_STATIC_ASSERT(sizeof(MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING) == 8 + 1);
MP_STATIC_ASSERT(sizeof(MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING) == 16 + 1);
MP_STATIC_ASSERT(sizeof(MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING) == 4 + 1);
uint8_t alloc_len = params[3] << 8 | params[4];
int len = MIN(sizeof(usbd_msc_inquiry_data), alloc_len);
memcpy(data_out, usbd_msc_inquiry_data, len);