11#include <string.h>
22
3- /*
4- #include "usb_core.h"
5- #include "usbd_cdc_core.h"
6- #include "usbd_pyb_core.h"
7- #include "usbd_usr.h"
8- */
93#include "usbd_core.h"
104#include "usbd_desc.h"
115#include "usbd_cdc.h"
126#include "usbd_cdc_interface.h"
7+ #include "usbd_msc.h"
8+ #include "usbd_msc_storage.h"
139
1410#include "misc.h"
1511#include "mpconfig.h"
1612#include "qstr.h"
1713#include "obj.h"
18- //#include "pendsv.h"
1914#include "usb.h"
2015
2116#ifdef USE_DEVICE_MODE
@@ -26,12 +21,12 @@ static int dev_is_enabled = 0;
2621uint32_t APP_dev_is_connected = 0 ; /* used by usbd_cdc_vcp */
2722mp_obj_t mp_const_vcp_interrupt = MP_OBJ_NULL ;
2823
29- void pyb_usb_dev_init (int usb_dev_type ) {
24+ void pyb_usb_dev_init (usbd_device_kind_t device_kind , usbd_storage_medium_kind_t medium_kind ) {
3025#ifdef USE_DEVICE_MODE
3126 if (!dev_is_enabled ) {
3227 // only init USB once in the device's power-lifetime
33- switch (usb_dev_type ) {
34- case PYB_USB_DEV_VCP_MSC :
28+ switch (device_kind ) {
29+ case USBD_DEVICE_CDC :
3530 // XXX USBD_CDC_Init (called by one of these functions below) uses malloc,
3631 // so the memory is invalid after a soft reset (which resets the GC).
3732 USBD_Init (& hUSBDDevice , & VCP_Desc , 0 );
@@ -41,7 +36,20 @@ void pyb_usb_dev_init(int usb_dev_type) {
4136 //USBD_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_cb, &USR_cb);
4237 break ;
4338
44- case PYB_USB_DEV_HID :
39+ case USBD_DEVICE_MSC :
40+ // XXX USBD_CDC_Init (called by one of these functions below) uses malloc,
41+ // so the memory is invalid after a soft reset (which resets the GC).
42+ USBD_Init (& hUSBDDevice , & MSC_Desc , 0 );
43+ USBD_RegisterClass (& hUSBDDevice , & USBD_MSC );
44+ if (medium_kind == USBD_STORAGE_MEDIUM_FLASH ) {
45+ USBD_MSC_RegisterStorage (& hUSBDDevice , (USBD_StorageTypeDef * )& USBD_FLASH_STORAGE_fops );
46+ } else {
47+ USBD_MSC_RegisterStorage (& hUSBDDevice , (USBD_StorageTypeDef * )& USBD_SDCARD_STORAGE_fops );
48+ }
49+ USBD_Start (& hUSBDDevice );
50+ break ;
51+
52+ case USBD_DEVICE_HID :
4553 //USBD_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_HID_cb, &USR_cb);
4654 // TODO
4755 break ;
0 commit comments