Update bootloader.c

This commit is contained in:
2026-08-19 18:07:15 +10:00
parent 4d7681a053
commit c13e2fa475
+20 -20
View File
@@ -1,7 +1,7 @@
// CH32V UF2 bootloader, size-optimized (target: <= 4096 bytes) // CH32V UF2 bootloader, size-optimized (target: <= 4096 bytes)
#include <stdint.h> #include <stdint.h>
#include "usbDesc.h"
typedef struct USBD_descriptor { typedef struct USBD_descriptor {
uint32_t addr_tx; uint32_t addr_tx;
uint32_t count_tx; uint32_t count_tx;
@@ -47,11 +47,11 @@ typedef struct USBD_descriptor {
// Device descriptor // Device descriptor
const uint8_t USB_DEV_DESC[18] __attribute__((aligned(2))) = { const uint8_t USB_DEV_DESC[18] __attribute__((aligned(2))) = {
18, // bLength 18, // bLength
1, // bDescriptorType DESCRIPTOR_DEVICE, // bDescriptorType
0x00, 0x02, // bcdUSB (uint_8)USB20, (uint_8)(USB20 << 8), // bcdUSB
0, // bDeviceClass USB_CLASS_PER_INTERFACE, // bDeviceClass
0, // bDeviceSubClass USB_CLASS_PER_INTERFACE, // bDeviceSubClass
0, // bDeviceProtocol USB_CLASS_PER_INTERFACE, // bDeviceProtocol
8, // bMaxPacketSize0 8, // bMaxPacketSize0
0x55, 0xf0, // idVendor 0x55, 0xf0, // idVendor
0x00, 0x00, // idProduct 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))) = { const uint8_t USB_CONF_DESC[0x20] __attribute__((aligned(2))) = {
// Configuration descriptor // Configuration descriptor
9, // bLength 9, // bLength
2, // bDescriptorType DESCRIPTOR_CONFIGURATION, // bDescriptorType
0x20, 0x00, // wTotalLength 0x20, 0x00, // wTotalLength
1, // bNumInterfaces 1, // bNumInterfaces
1, // bConfigurationValue 1, // bConfigurationValue
0, // iConfiguration 0, // iConfiguration
0x80, // bmAttributes 0x80, // bmAttributes // Too lazy to enum
250, // bMaxPower 250, // bMaxPower
// Interface descriptor // Interface descriptor
9, // bLength 9, // bLength
4, // bDescriptorType DESCRIPTOR_INTERFACE, // bDescriptorType
0, // bInterfaceNumber 0, // bInterfaceNumber
0, // bAlternateSetting 0, // bAlternateSetting
2, // bNumEndpoints 2, // bNumEndpoints
0x08, // bInterfaceClass USB_CLASS_MASS_STORAGE, // bInterfaceClass
0x05, // bInterfaceSubClass MSC_SUBCLASS_SFF8070I, // bInterfaceSubClass
0x50, // bInterfaceProtocol MSC_PROTO_BBB, // bInterfaceProtocol
0, // iInterface 0, // iInterface
// EP1 IN endpoint descriptor // EP1 IN endpoint descriptor
7, // bLength 7, // bLength
5, // bDescriptorType DESCRIPTOR_ENDPOINT, // bDescriptorType
0x81, // bEndpointAddress 0x81, // bEndpointAddress
2, // bmAttributes TRANSFER_BULK, // bmAttributes
0x40, 0x00, // wMaxPacketSize 0x40, 0x00, // wMaxPacketSize
0, // bInterval 0, // bInterval
// EP1 OUT endpoint descriptor // EP1 OUT endpoint descriptor
7, // bLength 7, // bLength
5, // bDescriptorType DESCRIPTOR_ENDPOINT, // bDescriptorType
0x01, // bEndpointAddress 0x01, // bEndpointAddress
2, // bmAttributes TRANSFER_BULK, // bmAttributes
0x40, 0x00, // wMaxPacketSize 0x40, 0x00, // wMaxPacketSize
0, // bInterval 0, // bInterval
}; };
@@ -112,12 +112,12 @@ const uint8_t HEXLUT[16] = "0123456789ABCDEF";
// SCSI INQUIRY standard response // SCSI INQUIRY standard response
const uint8_t INQUIRY_RESPONSE[36] __attribute__((aligned(2))) = { const uint8_t INQUIRY_RESPONSE[36] __attribute__((aligned(2))) = {
0x00, // direct access block device SCSI_INQ_DEV_TYPE_DIRECT_ACCESS, // direct access block device
0x80, // RMB removable media SCSI_INQ_RMB_REMOVABLE, // RMB removable media
// (if you don't set the RMB flag, macOS will show an orange drive // (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) // instead of a grey drive, contrary to expectations of flash drives)
0x04, // SPC-2 SCSI_INQ_VER_SPC_2, // SPC-2
0x02, // fixed, response data format SCSI_INQ_FMT_SCSI2, // fixed, response data format
0x1F, // additional length 0x1F, // additional length
0x00, // xxx mostly obsolete junk 0x00, // xxx mostly obsolete junk
0x00, 0x00,