diff options
Diffstat (limited to 'stmhal/usb.c')
-rw-r--r-- | stmhal/usb.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/stmhal/usb.c b/stmhal/usb.c index 5cf7b5f32c..c14a5ad688 100644 --- a/stmhal/usb.c +++ b/stmhal/usb.c @@ -1,21 +1,16 @@ #include <string.h> -/* -#include "usb_core.h" -#include "usbd_cdc_core.h" -#include "usbd_pyb_core.h" -#include "usbd_usr.h" -*/ #include "usbd_core.h" #include "usbd_desc.h" #include "usbd_cdc.h" #include "usbd_cdc_interface.h" +#include "usbd_msc.h" +#include "usbd_msc_storage.h" #include "misc.h" #include "mpconfig.h" #include "qstr.h" #include "obj.h" -//#include "pendsv.h" #include "usb.h" #ifdef USE_DEVICE_MODE @@ -26,12 +21,12 @@ static int dev_is_enabled = 0; uint32_t APP_dev_is_connected = 0; /* used by usbd_cdc_vcp */ mp_obj_t mp_const_vcp_interrupt = MP_OBJ_NULL; -void pyb_usb_dev_init(int usb_dev_type) { +void pyb_usb_dev_init(usbd_device_kind_t device_kind, usbd_storage_medium_kind_t medium_kind) { #ifdef USE_DEVICE_MODE if (!dev_is_enabled) { // only init USB once in the device's power-lifetime - switch (usb_dev_type) { - case PYB_USB_DEV_VCP_MSC: + switch (device_kind) { + case USBD_DEVICE_CDC: // XXX USBD_CDC_Init (called by one of these functions below) uses malloc, // so the memory is invalid after a soft reset (which resets the GC). USBD_Init(&hUSBDDevice, &VCP_Desc, 0); @@ -41,7 +36,20 @@ void pyb_usb_dev_init(int usb_dev_type) { //USBD_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_cb, &USR_cb); break; - case PYB_USB_DEV_HID: + case USBD_DEVICE_MSC: + // XXX USBD_CDC_Init (called by one of these functions below) uses malloc, + // so the memory is invalid after a soft reset (which resets the GC). + USBD_Init(&hUSBDDevice, &MSC_Desc, 0); + USBD_RegisterClass(&hUSBDDevice, &USBD_MSC); + if (medium_kind == USBD_STORAGE_MEDIUM_FLASH) { + USBD_MSC_RegisterStorage(&hUSBDDevice, (USBD_StorageTypeDef*)&USBD_FLASH_STORAGE_fops); + } else { + USBD_MSC_RegisterStorage(&hUSBDDevice, (USBD_StorageTypeDef*)&USBD_SDCARD_STORAGE_fops); + } + USBD_Start(&hUSBDDevice); + break; + + case USBD_DEVICE_HID: //USBD_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_HID_cb, &USR_cb); // TODO break; |