mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-10 09:58:28 -04:00
AP_HAL_ChibiOS: add block filesystem access support when using MSD USB
This commit is contained in:
parent
414606ba31
commit
c6631bce57
@ -35,47 +35,45 @@
|
||||
SerialUSBDriver SDU1;
|
||||
|
||||
static cdc_linecoding_t linecoding = {
|
||||
{0x00, 0x96, 0x00, 0x00}, /* 38400. */
|
||||
LC_STOP_1, LC_PARITY_NONE, 8
|
||||
{0x00, 0x96, 0x00, 0x00}, /* 38400. */
|
||||
LC_STOP_1, LC_PARITY_NONE, 8
|
||||
};
|
||||
|
||||
/*
|
||||
* USB Device Descriptor.
|
||||
*/
|
||||
static const uint8_t vcom_device_descriptor_data[18] = {
|
||||
USB_DESC_DEVICE(
|
||||
0x0110, /* bcdUSB (1.1). */
|
||||
0x02, /* bDeviceClass (CDC). */
|
||||
0x00, /* bDeviceSubClass. */
|
||||
0x00, /* bDeviceProtocol. */
|
||||
0x40, /* bMaxPacketSize. */
|
||||
HAL_USB_VENDOR_ID, /* idVendor (ST). */
|
||||
HAL_USB_PRODUCT_ID, /* idProduct. */
|
||||
0x0200, /* bcdDevice. */
|
||||
1, /* iManufacturer. */
|
||||
2, /* iProduct. */
|
||||
3, /* iSerialNumber. */
|
||||
1) /* bNumConfigurations. */
|
||||
USB_DESC_DEVICE (0x0200, /* bcdUSB (2.0). */
|
||||
0xEF, /* bDeviceClass (MISC). ef */
|
||||
0x02, /* bDeviceSubClass. 02 */
|
||||
0x01, /* bDeviceProtocol. 01 */
|
||||
0x40, /* bMaxPacketSize. */
|
||||
HAL_USB_VENDOR_ID, /* idVendor (ST). */
|
||||
HAL_USB_PRODUCT_ID, /* idProduct. */
|
||||
0x0200, /* bcdDevice. */
|
||||
1, /* iManufacturer. */
|
||||
2, /* iProduct. */
|
||||
3, /* iSerialNumber. */
|
||||
1) /* bNumConfigurations. */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Device Descriptor wrapper.
|
||||
*/
|
||||
static const USBDescriptor vcom_device_descriptor = {
|
||||
sizeof vcom_device_descriptor_data,
|
||||
vcom_device_descriptor_data
|
||||
sizeof vcom_device_descriptor_data,
|
||||
vcom_device_descriptor_data
|
||||
};
|
||||
|
||||
/* Configuration Descriptor tree for a CDC.*/
|
||||
static const uint8_t vcom_configuration_descriptor_data[] = {
|
||||
/* Configuration Descriptor.*/
|
||||
USB_DESC_CONFIGURATION(0x0020, /* wTotalLength. */
|
||||
0x01, /* bNumInterfaces. */
|
||||
USB_DESC_CONFIGURATION(0x0062, /* wTotalLength. */
|
||||
0x03, /* bNumInterfaces. */
|
||||
0x01, /* bConfigurationValue. */
|
||||
0, /* iConfiguration. */
|
||||
0xC0, /* bmAttributes (self powered). */
|
||||
0x32), /* bMaxPower (100mA). */
|
||||
250), /* bMaxPower (100mA). */
|
||||
/* Interface Descriptor.*/
|
||||
USB_DESC_INTERFACE (0x00, /* bInterfaceNumber. */
|
||||
0x00, /* bAlternateSetting. */
|
||||
@ -95,97 +93,97 @@ static const uint8_t vcom_configuration_descriptor_data[] = {
|
||||
0x02, /* bmAttributes (Bulk). */
|
||||
USB_MSD_EP_SIZE, /* wMaxPacketSize. */
|
||||
0x00), /* bInterval. 1ms */
|
||||
// CDC
|
||||
/* IAD Descriptor */
|
||||
USB_DESC_INTERFACE_ASSOCIATION(0x01, /* bFirstInterface. */
|
||||
0x02, /* bInterfaceCount. */
|
||||
0x02, /* bFunctionClass (CDC). */
|
||||
0x00, /* bFunctionSubClass. (2) */
|
||||
0x00, /* bFunctionProtocol (1) */
|
||||
2), /* iInterface. */
|
||||
/* Interface Descriptor.*/
|
||||
USB_DESC_INTERFACE (0x01, /* bInterfaceNumber. */
|
||||
0x00, /* bAlternateSetting. */
|
||||
0x01, /* bNumEndpoints. */
|
||||
0x02, /* bInterfaceClass (Communications
|
||||
// CDC
|
||||
/* IAD Descriptor */
|
||||
USB_DESC_INTERFACE_ASSOCIATION(0x01, /* bFirstInterface. */
|
||||
0x02, /* bInterfaceCount. */
|
||||
0x02, /* bFunctionClass (CDC). */
|
||||
0x02, /* bFunctionSubClass. (2) */
|
||||
0x01, /* bFunctionProtocol (1) */
|
||||
2), /* iInterface. */
|
||||
/* Interface Descriptor.*/
|
||||
USB_DESC_INTERFACE (0x01, /* bInterfaceNumber. */
|
||||
0x00, /* bAlternateSetting. */
|
||||
0x01, /* bNumEndpoints. */
|
||||
0x02, /* bInterfaceClass (Communications
|
||||
Interface Class, CDC section
|
||||
4.2). */
|
||||
0x02, /* bInterfaceSubClass (Abstract
|
||||
0x02, /* bInterfaceSubClass (Abstract
|
||||
Control Model, CDC section 4.3). */
|
||||
0x01, /* bInterfaceProtocol (AT commands,
|
||||
0x01, /* bInterfaceProtocol (AT commands,
|
||||
CDC section 4.4). */
|
||||
0), /* iInterface. */
|
||||
/* Header Functional Descriptor (CDC section 5.2.3).*/
|
||||
USB_DESC_BYTE (5), /* bLength. */
|
||||
USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */
|
||||
USB_DESC_BYTE (0x00), /* bDescriptorSubtype (Header
|
||||
0), /* iInterface. */
|
||||
/* Header Functional Descriptor (CDC section 5.2.3).*/
|
||||
USB_DESC_BYTE (5), /* bLength. */
|
||||
USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */
|
||||
USB_DESC_BYTE (0x00), /* bDescriptorSubtype (Header
|
||||
Functional Descriptor. */
|
||||
USB_DESC_BCD (0x0110), /* bcdCDC. */
|
||||
/* Call Management Functional Descriptor. */
|
||||
USB_DESC_BYTE (5), /* bFunctionLength. */
|
||||
USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */
|
||||
USB_DESC_BYTE (0x01), /* bDescriptorSubtype (Call Management
|
||||
USB_DESC_BCD (0x0110), /* bcdCDC. */
|
||||
/* Call Management Functional Descriptor. */
|
||||
USB_DESC_BYTE (5), /* bFunctionLength. */
|
||||
USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */
|
||||
USB_DESC_BYTE (0x01), /* bDescriptorSubtype (Call Management
|
||||
Functional Descriptor). */
|
||||
USB_DESC_BYTE (0x00), /* bmCapabilities (D0+D1). */
|
||||
USB_DESC_BYTE (0x02), /* bDataInterface. */
|
||||
/* ACM Functional Descriptor.*/
|
||||
USB_DESC_BYTE (4), /* bFunctionLength. */
|
||||
USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */
|
||||
USB_DESC_BYTE (0x02), /* bDescriptorSubtype (Abstract
|
||||
USB_DESC_BYTE (0x00), /* bmCapabilities (D0+D1). */
|
||||
USB_DESC_BYTE (0x02), /* bDataInterface. */
|
||||
/* ACM Functional Descriptor.*/
|
||||
USB_DESC_BYTE (4), /* bFunctionLength. */
|
||||
USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */
|
||||
USB_DESC_BYTE (0x02), /* bDescriptorSubtype (Abstract
|
||||
Control Management Descriptor). */
|
||||
USB_DESC_BYTE (0x02), /* bmCapabilities. */
|
||||
/* Union Functional Descriptor.*/
|
||||
USB_DESC_BYTE (5), /* bFunctionLength. */
|
||||
USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */
|
||||
USB_DESC_BYTE (0x06), /* bDescriptorSubtype (Union
|
||||
USB_DESC_BYTE (0x02), /* bmCapabilities. */
|
||||
/* Union Functional Descriptor.*/
|
||||
USB_DESC_BYTE (5), /* bFunctionLength. */
|
||||
USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */
|
||||
USB_DESC_BYTE (0x06), /* bDescriptorSubtype (Union
|
||||
Functional Descriptor). */
|
||||
USB_DESC_BYTE (0x01), /* bMasterInterface (Communication
|
||||
USB_DESC_BYTE (0x01), /* bMasterInterface (Communication
|
||||
Class Interface). */
|
||||
USB_DESC_BYTE (0x02), /* bSlaveInterface0 (Data Class
|
||||
USB_DESC_BYTE (0x02), /* bSlaveInterface0 (Data Class
|
||||
Interface). */
|
||||
/* Endpoint 5 Descriptor.*/
|
||||
USB_DESC_ENDPOINT (USB_INTERRUPT_REQUEST_EP|0x80,
|
||||
0x03, /* bmAttributes (Interrupt). */
|
||||
0x0008, /* wMaxPacketSize. */
|
||||
0xFF), /* bInterval. */
|
||||
/* Interface Descriptor.*/
|
||||
USB_DESC_INTERFACE (0x02, /* bInterfaceNumber. */
|
||||
0x00, /* bAlternateSetting. */
|
||||
0x02, /* bNumEndpoints. */
|
||||
0x0A, /* bInterfaceClass (Data Class
|
||||
/* Endpoint 5 Descriptor.*/
|
||||
USB_DESC_ENDPOINT (USB_INTERRUPT_REQUEST_EP|0x80,
|
||||
0x03, /* bmAttributes (Interrupt). */
|
||||
0x0008, /* wMaxPacketSize. */
|
||||
0xFF), /* bInterval. */
|
||||
/* Interface Descriptor.*/
|
||||
USB_DESC_INTERFACE (0x02, /* bInterfaceNumber. */
|
||||
0x00, /* bAlternateSetting. */
|
||||
0x02, /* bNumEndpoints. */
|
||||
0x0A, /* bInterfaceClass (Data Class
|
||||
Interface, CDC section 4.5). */
|
||||
0x00, /* bInterfaceSubClass (CDC section
|
||||
0x00, /* bInterfaceSubClass (CDC section
|
||||
4.6). */
|
||||
0x00, /* bInterfaceProtocol (CDC section
|
||||
0x00, /* bInterfaceProtocol (CDC section
|
||||
4.7). */
|
||||
0x00), /* iInterface. */
|
||||
/* Endpoint 4 Descriptor.*/
|
||||
USB_DESC_ENDPOINT (USB_DATA_AVAILABLE_EP, /* bEndpointAddress.*/
|
||||
0x02, /* bmAttributes (Bulk). */
|
||||
0x0040, /* wMaxPacketSize. */
|
||||
0x00), /* bInterval. */
|
||||
/* Endpoint 4 Descriptor.*/
|
||||
USB_DESC_ENDPOINT (USB_DATA_REQUEST_EP|0x80, /* bEndpointAddress.*/
|
||||
0x02, /* bmAttributes (Bulk). */
|
||||
0x0040, /* wMaxPacketSize. */
|
||||
0x00) /* bInterval. */
|
||||
0x00), /* iInterface. */
|
||||
/* Endpoint 4 Descriptor.*/
|
||||
USB_DESC_ENDPOINT (USB_DATA_AVAILABLE_EP, /* bEndpointAddress.*/
|
||||
0x02, /* bmAttributes (Bulk). */
|
||||
0x0040, /* wMaxPacketSize. */
|
||||
0x00), /* bInterval. */
|
||||
/* Endpoint 4 Descriptor.*/
|
||||
USB_DESC_ENDPOINT (USB_DATA_REQUEST_EP|0x80, /* bEndpointAddress.*/
|
||||
0x02, /* bmAttributes (Bulk). */
|
||||
0x0040, /* wMaxPacketSize. */
|
||||
0x00) /* bInterval. */
|
||||
};
|
||||
|
||||
/*
|
||||
* Configuration Descriptor wrapper.
|
||||
*/
|
||||
static const USBDescriptor vcom_configuration_descriptor = {
|
||||
sizeof vcom_configuration_descriptor_data,
|
||||
vcom_configuration_descriptor_data
|
||||
sizeof vcom_configuration_descriptor_data,
|
||||
vcom_configuration_descriptor_data
|
||||
};
|
||||
|
||||
/*
|
||||
* U.S. English language identifier.
|
||||
*/
|
||||
static const uint8_t vcom_string0[] = {
|
||||
USB_DESC_BYTE(4), /* bLength. */
|
||||
USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
|
||||
USB_DESC_WORD(0x0409) /* wLANGID (U.S. English). */
|
||||
USB_DESC_BYTE(4), /* bLength. */
|
||||
USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
|
||||
USB_DESC_WORD(0x0409) /* wLANGID (U.S. English). */
|
||||
};
|
||||
|
||||
/*
|
||||
@ -193,10 +191,10 @@ static const uint8_t vcom_string0[] = {
|
||||
* allow them to be setup with apj_tool
|
||||
*/
|
||||
static USBDescriptor vcom_strings[] = {
|
||||
{sizeof vcom_string0, vcom_string0},
|
||||
{0, NULL}, // manufacturer
|
||||
{0, NULL}, // product
|
||||
{0, NULL}, // version
|
||||
{sizeof vcom_string0, vcom_string0},
|
||||
{0, NULL}, // manufacturer
|
||||
{0, NULL}, // product
|
||||
{0, NULL}, // version
|
||||
};
|
||||
|
||||
static uint8_t vcom_buffers[3][2+2*USB_DESC_MAX_STRLEN];
|
||||
@ -235,22 +233,24 @@ void setup_usb_strings(void)
|
||||
* handled here.
|
||||
*/
|
||||
static const USBDescriptor *get_descriptor(USBDriver *usbp,
|
||||
uint8_t dtype,
|
||||
uint8_t dindex,
|
||||
uint16_t lang) {
|
||||
uint8_t dtype,
|
||||
uint8_t dindex,
|
||||
uint16_t lang)
|
||||
{
|
||||
|
||||
(void)usbp;
|
||||
(void)lang;
|
||||
switch (dtype) {
|
||||
case USB_DESCRIPTOR_DEVICE:
|
||||
return &vcom_device_descriptor;
|
||||
case USB_DESCRIPTOR_CONFIGURATION:
|
||||
return &vcom_configuration_descriptor;
|
||||
case USB_DESCRIPTOR_STRING:
|
||||
if (dindex < 4)
|
||||
return &vcom_strings[dindex];
|
||||
}
|
||||
return NULL;
|
||||
(void)usbp;
|
||||
(void)lang;
|
||||
switch (dtype) {
|
||||
case USB_DESCRIPTOR_DEVICE:
|
||||
return &vcom_device_descriptor;
|
||||
case USB_DESCRIPTOR_CONFIGURATION:
|
||||
return &vcom_configuration_descriptor;
|
||||
case USB_DESCRIPTOR_STRING:
|
||||
if (dindex < 4) {
|
||||
return &vcom_strings[dindex];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -283,16 +283,16 @@ static USBOutEndpointState ep1outstate;
|
||||
* @brief EP1 initialization structure (both IN and OUT).
|
||||
*/
|
||||
static const USBEndpointConfig ep1config = {
|
||||
USB_EP_MODE_TYPE_BULK,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
USB_MSD_EP_SIZE,
|
||||
USB_MSD_EP_SIZE,
|
||||
&ep1instate,
|
||||
&ep1outstate,
|
||||
4,
|
||||
NULL
|
||||
USB_EP_MODE_TYPE_BULK,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
USB_MSD_EP_SIZE,
|
||||
USB_MSD_EP_SIZE,
|
||||
&ep1instate,
|
||||
&ep1outstate,
|
||||
2,
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
@ -312,16 +312,16 @@ static USBOutEndpointState ep2outstate;
|
||||
*/
|
||||
|
||||
static const USBEndpointConfig ep2config = {
|
||||
USB_EP_MODE_TYPE_BULK,
|
||||
NULL,
|
||||
sduDataTransmitted,
|
||||
sduDataReceived,
|
||||
0x0040,
|
||||
0x0040,
|
||||
&ep2instate,
|
||||
&ep2outstate,
|
||||
1,
|
||||
NULL
|
||||
USB_EP_MODE_TYPE_BULK,
|
||||
NULL,
|
||||
sduDataTransmitted,
|
||||
sduDataReceived,
|
||||
0x0040,
|
||||
0x0040,
|
||||
&ep2instate,
|
||||
&ep2outstate,
|
||||
2,
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
@ -333,67 +333,68 @@ static USBInEndpointState ep3instate;
|
||||
* @brief EP3 initialization structure (IN only).
|
||||
*/
|
||||
static const USBEndpointConfig ep3config = {
|
||||
USB_EP_MODE_TYPE_INTR,
|
||||
NULL,
|
||||
sduInterruptTransmitted,
|
||||
NULL,
|
||||
0x0010,
|
||||
0x0000,
|
||||
&ep3instate,
|
||||
NULL,
|
||||
1,
|
||||
NULL
|
||||
USB_EP_MODE_TYPE_INTR,
|
||||
NULL,
|
||||
sduInterruptTransmitted,
|
||||
NULL,
|
||||
0x0010,
|
||||
0x0000,
|
||||
&ep3instate,
|
||||
NULL,
|
||||
1,
|
||||
NULL
|
||||
};
|
||||
|
||||
/*
|
||||
* Handles the USB driver global events.
|
||||
*/
|
||||
static void usb_event(USBDriver *usbp, usbevent_t event) {
|
||||
extern SerialUSBDriver SDU1;
|
||||
static void usb_event(USBDriver *usbp, usbevent_t event)
|
||||
{
|
||||
extern SerialUSBDriver SDU1;
|
||||
|
||||
switch (event) {
|
||||
case USB_EVENT_ADDRESS:
|
||||
return;
|
||||
case USB_EVENT_CONFIGURED:
|
||||
chSysLockFromISR();
|
||||
switch (event) {
|
||||
case USB_EVENT_ADDRESS:
|
||||
return;
|
||||
case USB_EVENT_CONFIGURED:
|
||||
chSysLockFromISR();
|
||||
|
||||
/* Enables the endpoints specified into the configuration.
|
||||
Note, this callback is invoked from an ISR so I-Class functions
|
||||
must be used.*/
|
||||
/* Enables the endpoints specified into the configuration.
|
||||
Note, this callback is invoked from an ISR so I-Class functions
|
||||
must be used.*/
|
||||
|
||||
usbInitEndpointI(usbp, USB_MSD_DATA_EP, &ep1config);
|
||||
usbInitEndpointI(usbp, USB_DATA_REQUEST_EP, &ep2config);
|
||||
usbInitEndpointI(usbp, USB_INTERRUPT_REQUEST_EP, &ep3config);
|
||||
usbInitEndpointI(usbp, USB_MSD_DATA_EP, &ep1config);
|
||||
usbInitEndpointI(usbp, USB_DATA_REQUEST_EP, &ep2config);
|
||||
usbInitEndpointI(usbp, USB_INTERRUPT_REQUEST_EP, &ep3config);
|
||||
|
||||
/* Resetting the state of the CDC subsystem.*/
|
||||
sduConfigureHookI(&SDU1);
|
||||
/* Resetting the state of the CDC subsystem.*/
|
||||
sduConfigureHookI(&SDU1);
|
||||
|
||||
chSysUnlockFromISR();
|
||||
return;
|
||||
case USB_EVENT_RESET:
|
||||
chSysUnlockFromISR();
|
||||
return;
|
||||
case USB_EVENT_RESET:
|
||||
/* Falls into.*/
|
||||
case USB_EVENT_UNCONFIGURED:
|
||||
case USB_EVENT_UNCONFIGURED:
|
||||
/* Falls into.*/
|
||||
case USB_EVENT_SUSPEND:
|
||||
chSysLockFromISR();
|
||||
case USB_EVENT_SUSPEND:
|
||||
chSysLockFromISR();
|
||||
|
||||
/* Disconnection event on suspend.*/
|
||||
sduSuspendHookI(&SDU1);
|
||||
/* Disconnection event on suspend.*/
|
||||
sduSuspendHookI(&SDU1);
|
||||
|
||||
chSysUnlockFromISR();
|
||||
chSysUnlockFromISR();
|
||||
return;
|
||||
case USB_EVENT_WAKEUP:
|
||||
chSysLockFromISR();
|
||||
|
||||
/* Disconnection event on suspend.*/
|
||||
sduWakeupHookI(&SDU1);
|
||||
|
||||
chSysUnlockFromISR();
|
||||
return;
|
||||
case USB_EVENT_STALLED:
|
||||
return;
|
||||
}
|
||||
return;
|
||||
case USB_EVENT_WAKEUP:
|
||||
chSysLockFromISR();
|
||||
|
||||
/* Disconnection event on suspend.*/
|
||||
sduWakeupHookI(&SDU1);
|
||||
|
||||
chSysUnlockFromISR();
|
||||
return;
|
||||
case USB_EVENT_STALLED:
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -407,75 +408,78 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
|
||||
#define MSD_GET_MAX_LUN 0xFE
|
||||
|
||||
static uint8_t zbuf = 0;
|
||||
static bool hybridRequestHook(USBDriver *usbp) {
|
||||
static bool hybridRequestHook(USBDriver *usbp)
|
||||
{
|
||||
|
||||
// handle MSD setup request -- we could change the interface here
|
||||
#define USB_MSD_INTERFACE 0
|
||||
// handle MSD setup request -- we could change the interface here
|
||||
#define USB_MSD_INTERFACE 0
|
||||
|
||||
if (((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) &&
|
||||
((usbp->setup[0] & USB_RTYPE_RECIPIENT_MASK) ==
|
||||
USB_RTYPE_RECIPIENT_INTERFACE)) {
|
||||
if (((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) &&
|
||||
((usbp->setup[0] & USB_RTYPE_RECIPIENT_MASK) ==
|
||||
USB_RTYPE_RECIPIENT_INTERFACE)) {
|
||||
|
||||
if (MSD_SETUP_INDEX(usbp->setup) == USB_MSD_INTERFACE) {
|
||||
if (MSD_SETUP_INDEX(usbp->setup) == USB_MSD_INTERFACE) {
|
||||
|
||||
switch(usbp->setup[1]) {
|
||||
case MSD_REQ_RESET:
|
||||
/* check that it is a HOST2DEV request */
|
||||
if (((usbp->setup[0] & USB_RTYPE_DIR_MASK) != USB_RTYPE_DIR_HOST2DEV) ||
|
||||
(MSD_SETUP_LENGTH(usbp->setup) != 0) ||
|
||||
(MSD_SETUP_VALUE(usbp->setup) != 0)) {
|
||||
return false;
|
||||
}
|
||||
chSysLockFromISR();
|
||||
usbStallReceiveI(usbp, 1);
|
||||
usbStallTransmitI(usbp, 1);
|
||||
chSysUnlockFromISR();
|
||||
switch (usbp->setup[1]) {
|
||||
case MSD_REQ_RESET:
|
||||
/* check that it is a HOST2DEV request */
|
||||
if (((usbp->setup[0] & USB_RTYPE_DIR_MASK) != USB_RTYPE_DIR_HOST2DEV) ||
|
||||
(MSD_SETUP_LENGTH(usbp->setup) != 0) ||
|
||||
(MSD_SETUP_VALUE(usbp->setup) != 0)) {
|
||||
return false;
|
||||
}
|
||||
chSysLockFromISR();
|
||||
usbStallReceiveI(usbp, 1);
|
||||
usbStallTransmitI(usbp, 1);
|
||||
chSysUnlockFromISR();
|
||||
|
||||
/* response to this request using EP0 */
|
||||
/* response to this request using EP0 */
|
||||
|
||||
usbSetupTransfer(usbp, 0, 0, NULL);
|
||||
return true;
|
||||
usbSetupTransfer(usbp, 0, 0, NULL);
|
||||
return true;
|
||||
|
||||
case MSD_GET_MAX_LUN:
|
||||
/* check that it is a DEV2HOST request */
|
||||
if (((usbp->setup[0] & USB_RTYPE_DIR_MASK) != USB_RTYPE_DIR_DEV2HOST) ||
|
||||
(MSD_SETUP_LENGTH(usbp->setup) != 1) ||
|
||||
(MSD_SETUP_VALUE(usbp->setup) != 0)) {
|
||||
return false;
|
||||
}
|
||||
// send 0 packet to indicate that we don't do LUN
|
||||
zbuf = 0;
|
||||
usbSetupTransfer(usbp, &zbuf, 1, NULL);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
case MSD_GET_MAX_LUN:
|
||||
/* check that it is a DEV2HOST request */
|
||||
if (((usbp->setup[0] & USB_RTYPE_DIR_MASK) != USB_RTYPE_DIR_DEV2HOST) ||
|
||||
(MSD_SETUP_LENGTH(usbp->setup) != 1) ||
|
||||
(MSD_SETUP_VALUE(usbp->setup) != 0)) {
|
||||
return false;
|
||||
}
|
||||
// send 0 packet to indicate that we don't do LUN
|
||||
zbuf = 0;
|
||||
usbSetupTransfer(usbp, &zbuf, 1, NULL);
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sduRequestsHook(usbp);
|
||||
return sduRequestsHook(usbp);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Handles the USB driver global events.
|
||||
*/
|
||||
static void sof_handler(USBDriver *usbp) {
|
||||
static void sof_handler(USBDriver *usbp)
|
||||
{
|
||||
|
||||
(void)usbp;
|
||||
(void)usbp;
|
||||
|
||||
osalSysLockFromISR();
|
||||
sduSOFHookI(&SDU1);
|
||||
osalSysUnlockFromISR();
|
||||
osalSysLockFromISR();
|
||||
sduSOFHookI(&SDU1);
|
||||
osalSysUnlockFromISR();
|
||||
}
|
||||
|
||||
// USB Driver configuration.
|
||||
|
||||
const USBConfig usbcfg = {
|
||||
usb_event,
|
||||
get_descriptor,
|
||||
hybridRequestHook,
|
||||
sof_handler
|
||||
usb_event,
|
||||
get_descriptor,
|
||||
hybridRequestHook,
|
||||
sof_handler
|
||||
};
|
||||
|
||||
|
||||
@ -483,12 +487,12 @@ const USBConfig usbcfg = {
|
||||
|
||||
const SerialUSBConfig serusbcfg1 = {
|
||||
#if STM32_USB_USE_OTG1
|
||||
&USBD1,
|
||||
&USBD1,
|
||||
#else
|
||||
&USBD2,
|
||||
&USBD2,
|
||||
#endif
|
||||
USB_DATA_REQUEST_EP,
|
||||
USB_DATA_AVAILABLE_EP,
|
||||
USB_INTERRUPT_REQUEST_EP
|
||||
USB_DATA_REQUEST_EP,
|
||||
USB_DATA_AVAILABLE_EP,
|
||||
USB_INTERRUPT_REQUEST_EP
|
||||
};
|
||||
#endif // HAL_HAVE_USB_CDC_MSD
|
||||
|
@ -24,9 +24,21 @@
|
||||
#include "bouncebuffer.h"
|
||||
#include "stm32_util.h"
|
||||
#include "hwdef/common/usbcfg.h"
|
||||
#include "stm32_util.h"
|
||||
|
||||
extern const AP_HAL::HAL& hal;
|
||||
|
||||
|
||||
static void block_filesys_access()
|
||||
{
|
||||
AP::FS().block_access();
|
||||
}
|
||||
|
||||
static void free_filesys_access()
|
||||
{
|
||||
AP::FS().free_access();
|
||||
}
|
||||
|
||||
#ifdef USE_POSIX
|
||||
static FATFS SDC_FS; // FATFS object
|
||||
#ifndef HAL_BOOTLOADER_BUILD
|
||||
@ -121,7 +133,7 @@ bool sdcard_init()
|
||||
#else
|
||||
&USBD2,
|
||||
#endif
|
||||
(BaseBlockDevice*)&SDCD1, blkbuf, txbuf, NULL, NULL);
|
||||
(BaseBlockDevice*)&SDCD1, blkbuf, txbuf, NULL, NULL, block_filesys_access, free_filesys_access);
|
||||
usbDisconnectBus(serusbcfg1.usbp);
|
||||
usbStop(serusbcfg1.usbp);
|
||||
chThdSleep(chTimeUS2I(1500));
|
||||
|
Loading…
Reference in New Issue
Block a user