AP_HAL_ChibiOS: add block filesystem access support when using MSD USB

This commit is contained in:
bugobliterator 2022-07-22 05:17:43 +05:30 committed by Andrew Tridgell
parent 414606ba31
commit c6631bce57
2 changed files with 241 additions and 225 deletions

View File

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

View File

@ -24,9 +24,21 @@
#include "bouncebuffer.h" #include "bouncebuffer.h"
#include "stm32_util.h" #include "stm32_util.h"
#include "hwdef/common/usbcfg.h" #include "hwdef/common/usbcfg.h"
#include "stm32_util.h"
extern const AP_HAL::HAL& hal; 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 #ifdef USE_POSIX
static FATFS SDC_FS; // FATFS object static FATFS SDC_FS; // FATFS object
#ifndef HAL_BOOTLOADER_BUILD #ifndef HAL_BOOTLOADER_BUILD
@ -121,7 +133,7 @@ bool sdcard_init()
#else #else
&USBD2, &USBD2,
#endif #endif
(BaseBlockDevice*)&SDCD1, blkbuf, txbuf, NULL, NULL); (BaseBlockDevice*)&SDCD1, blkbuf, txbuf, NULL, NULL, block_filesys_access, free_filesys_access);
usbDisconnectBus(serusbcfg1.usbp); usbDisconnectBus(serusbcfg1.usbp);
usbStop(serusbcfg1.usbp); usbStop(serusbcfg1.usbp);
chThdSleep(chTimeUS2I(1500)); chThdSleep(chTimeUS2I(1500));