From c13e2fa47561858730e8b73bf4fe4ccc28cc630d Mon Sep 17 00:00:00 2001 From: bstanwell Date: Wed, 19 Aug 2026 18:07:15 +1000 Subject: [PATCH] Update bootloader.c --- bootloader.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/bootloader.c b/bootloader.c index 36c0c42..d11ef9b 100644 --- a/bootloader.c +++ b/bootloader.c @@ -1,7 +1,7 @@ // CH32V UF2 bootloader, size-optimized (target: <= 4096 bytes) #include - +#include "usbDesc.h" typedef struct USBD_descriptor { uint32_t addr_tx; uint32_t count_tx; @@ -47,11 +47,11 @@ typedef struct USBD_descriptor { // Device descriptor const uint8_t USB_DEV_DESC[18] __attribute__((aligned(2))) = { 18, // bLength - 1, // bDescriptorType - 0x00, 0x02, // bcdUSB - 0, // bDeviceClass - 0, // bDeviceSubClass - 0, // bDeviceProtocol + DESCRIPTOR_DEVICE, // bDescriptorType + (uint_8)USB20, (uint_8)(USB20 << 8), // bcdUSB + USB_CLASS_PER_INTERFACE, // bDeviceClass + USB_CLASS_PER_INTERFACE, // bDeviceSubClass + USB_CLASS_PER_INTERFACE, // bDeviceProtocol 8, // bMaxPacketSize0 0x55, 0xf0, // idVendor 0x00, 0x00, // idProduct @@ -65,38 +65,38 @@ const uint8_t USB_DEV_DESC[18] __attribute__((aligned(2))) = { const uint8_t USB_CONF_DESC[0x20] __attribute__((aligned(2))) = { // Configuration descriptor 9, // bLength - 2, // bDescriptorType + DESCRIPTOR_CONFIGURATION, // bDescriptorType 0x20, 0x00, // wTotalLength 1, // bNumInterfaces 1, // bConfigurationValue 0, // iConfiguration - 0x80, // bmAttributes + 0x80, // bmAttributes // Too lazy to enum 250, // bMaxPower // Interface descriptor 9, // bLength - 4, // bDescriptorType + DESCRIPTOR_INTERFACE, // bDescriptorType 0, // bInterfaceNumber 0, // bAlternateSetting 2, // bNumEndpoints - 0x08, // bInterfaceClass - 0x05, // bInterfaceSubClass - 0x50, // bInterfaceProtocol + USB_CLASS_MASS_STORAGE, // bInterfaceClass + MSC_SUBCLASS_SFF8070I, // bInterfaceSubClass + MSC_PROTO_BBB, // bInterfaceProtocol 0, // iInterface // EP1 IN endpoint descriptor 7, // bLength - 5, // bDescriptorType + DESCRIPTOR_ENDPOINT, // bDescriptorType 0x81, // bEndpointAddress - 2, // bmAttributes + TRANSFER_BULK, // bmAttributes 0x40, 0x00, // wMaxPacketSize 0, // bInterval // EP1 OUT endpoint descriptor 7, // bLength - 5, // bDescriptorType + DESCRIPTOR_ENDPOINT, // bDescriptorType 0x01, // bEndpointAddress - 2, // bmAttributes + TRANSFER_BULK, // bmAttributes 0x40, 0x00, // wMaxPacketSize 0, // bInterval }; @@ -112,12 +112,12 @@ const uint8_t HEXLUT[16] = "0123456789ABCDEF"; // SCSI INQUIRY standard response const uint8_t INQUIRY_RESPONSE[36] __attribute__((aligned(2))) = { - 0x00, // direct access block device - 0x80, // RMB removable media + SCSI_INQ_DEV_TYPE_DIRECT_ACCESS, // direct access block device + SCSI_INQ_RMB_REMOVABLE, // RMB removable media // (if you don't set the RMB flag, macOS will show an orange drive // instead of a grey drive, contrary to expectations of flash drives) - 0x04, // SPC-2 - 0x02, // fixed, response data format + SCSI_INQ_VER_SPC_2, // SPC-2 + SCSI_INQ_FMT_SCSI2, // fixed, response data format 0x1F, // additional length 0x00, // xxx mostly obsolete junk 0x00,