Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add USB MSC + MSC/CDC Composite Class #1088

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
26f5806
initial commit of new cdc_msc and updated msc
May 29, 2020
db11e1b
added endpoint configuration
May 29, 2020
1c247ed
added endpoint define changes
May 29, 2020
0b9e38e
added default msc interface
May 29, 2020
162ade3
fixed cdc handle nad renamed cdc msc flag
May 29, 2020
8d7e9d8
added usb class
May 29, 2020
4b489ef
add new include dirs
May 30, 2020
a144bca
formatting changes, improved usbd_ep_conf and now compiles in marlin
Jun 1, 2020
6717196
fixed bug in descriptor, small changes to USB class
Jun 1, 2020
6f3ebfc
fixed duplicate endpoint definition and somewhat fixed endpoint confi…
Jun 2, 2020
ccef556
fixed styling and changed dummy sd usb so it is always not ready
Jun 2, 2020
ff6cecf
fixed small type and more formatting
Jun 2, 2020
da5c702
added ifdef for USB.c
Jun 2, 2020
ffd635d
fixed bug in ST MSC SCSI library
Jun 2, 2020
7676e07
fixed formatting
Jun 2, 2020
3761125
introduced usb msc abstract class
Jun 3, 2020
6f00830
changes to formatting
Jun 3, 2020
f578d6c
more formatting changes
Jun 3, 2020
805113d
and more formatting changes
Jun 3, 2020
5df8d9c
small bugfixes
Jun 3, 2020
5b3e972
added back early usb initialisation and fixed write protection bug in…
Jun 3, 2020
77d673b
fixed hs/fs/other speed interface descriptors for cdc msc
Jun 3, 2020
3f3783e
small changes to ep conf
Jun 3, 2020
3c4d73d
fixed bug where usb device library relies on pdev->pClassData to dete…
Jun 4, 2020
f0e3993
update msc and cdc classes
Jun 4, 2020
a7fd6e2
fixed ep addresses
Jun 4, 2020
df73d28
fixed formatting
Jun 4, 2020
760d8e3
added back cdc clear buffer
Jun 4, 2020
f7dbf85
remove reference to userdata
Jun 4, 2020
6d0023f
fixed pointer error and warning
Jun 4, 2020
4d0f562
changes to cdc msc interface definitions
Jun 4, 2020
b29c3ea
remove SOF from MSC+CDC
Jun 4, 2020
2207a41
further changes during merging
Jun 4, 2020
a341011
set cdc usb handle to usb handle
Jun 4, 2020
8709e8f
refactored cdc msc descriptor and fixed for windowsn
Jun 7, 2020
def0867
fixed formatting
Jun 7, 2020
4447803
added extra board configurations
Jun 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,8 @@ Nucleo_144.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
Nucleo_144.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
Nucleo_144.menu.usb.CDC=CDC (no generic 'Serial')
Nucleo_144.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
Nucleo_144.menu.usb.CDC_MSC=CDC + MSC
Nucleo_144.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
Nucleo_144.menu.usb.HID=HID (keyboard and mouse)
Nucleo_144.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
Nucleo_144.menu.xusb.FS=Low/Full Speed
Expand All @@ -2338,6 +2340,8 @@ Nucleo_64.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
Nucleo_64.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
Nucleo_64.menu.usb.CDC=CDC (no generic 'Serial')
Nucleo_64.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
Nucleo_64.menu.usb.CDC_MSC=CDC + MSC
Nucleo_64.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
Nucleo_64.menu.usb.HID=HID (keyboard and mouse)
Nucleo_64.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
Nucleo_64.menu.xusb.FS=Low/Full Speed
Expand All @@ -2351,6 +2355,8 @@ Nucleo_32.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
Nucleo_32.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
Nucleo_32.menu.usb.CDC=CDC (no generic 'Serial')
Nucleo_32.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
Nucleo_32.menu.usb.CDC_MSC=CDC + MSC
Nucleo_32.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
Nucleo_32.menu.usb.HID=HID (keyboard and mouse)
Nucleo_32.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
Nucleo_32.menu.xusb.FS=Low/Full Speed
Expand All @@ -2364,6 +2370,8 @@ Disco.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
Disco.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
Disco.menu.usb.CDC=CDC (no generic 'Serial')
Disco.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
Disco.menu.usb.CDC_MSC=CDC + MSC
Disco.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
Disco.menu.usb.HID=HID (keyboard and mouse)
Disco.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
Disco.menu.xusb.FS=Low/Full Speed
Expand All @@ -2377,6 +2385,8 @@ Eval.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
Eval.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
Eval.menu.usb.CDC=CDC (no generic 'Serial')
Eval.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
Eval.menu.usb.CDC_MSC=CDC + MSC
Eval.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
Eval.menu.usb.HID=HID (keyboard and mouse)
Eval.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
Eval.menu.xusb.FS=Low/Full Speed
Expand All @@ -2390,6 +2400,8 @@ GenF1.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
GenF1.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
GenF1.menu.usb.CDC=CDC (no generic 'Serial')
GenF1.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
GenF1.menu.usb.CDC_MSC=CDC + MSC
GenF1.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
GenF1.menu.usb.HID=HID (keyboard and mouse)
GenF1.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
GenF1.menu.xusb.FS=Low/Full Speed
Expand All @@ -2403,6 +2415,8 @@ GenF3.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
GenF3.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
GenF3.menu.usb.CDC=CDC (no generic 'Serial')
GenF3.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
GenF3.menu.usb.CDC_MSC=CDC + MSC
GenF3.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
GenF3.menu.usb.HID=HID (keyboard and mouse)
GenF3.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
GenF3.menu.xusb.FS=Low/Full Speed
Expand All @@ -2416,6 +2430,8 @@ GenF4.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
GenF4.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
GenF4.menu.usb.CDC=CDC (no generic 'Serial')
GenF4.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
GenF4.menu.usb.CDC_MSC=CDC + MSC
GenF4.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
GenF4.menu.usb.HID=HID (keyboard and mouse)
GenF4.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
GenF4.menu.xusb.FS=Low/Full Speed
Expand All @@ -2429,6 +2445,8 @@ GenH7.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
GenH7.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
GenH7.menu.usb.CDC=CDC (no generic 'Serial')
GenH7.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
GenH7.menu.usb.CDC_MSC=CDC + MSC
GenH7.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
GenH7.menu.usb.HID=HID (keyboard and mouse)
GenH7.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
GenH7.menu.xusb.FS=Low/Full Speed
Expand All @@ -2440,6 +2458,8 @@ GenL0.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
GenL0.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
GenL0.menu.usb.CDC=CDC (no generic 'Serial')
GenL0.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
GenL0.menu.usb.CDC_MSC=CDC + MSC
GenL0.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
GenL0.menu.usb.HID=HID (keyboard and mouse)
GenL0.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE

Expand All @@ -2448,6 +2468,8 @@ GenL0.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
3dprinter.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
3dprinter.menu.usb.CDC=CDC (no generic 'Serial')
3dprinter.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
3dprinter.menu.usb.CDC_MSC=CDC + MSC
3dprinter.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
3dprinter.menu.xusb.FS=Low/Full Speed
3dprinter.menu.xusb.HS=High Speed
3dprinter.menu.xusb.HS.build.usb_speed=-DUSE_USB_HS
Expand All @@ -2459,6 +2481,8 @@ Genericflight.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
Genericflight.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
Genericflight.menu.usb.CDC=CDC (no generic 'Serial')
Genericflight.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
Genericflight.menu.usb.CDC_MSC=CDC + MSC
Genericflight.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
Genericflight.menu.usb.HID=HID (keyboard and mouse)
Genericflight.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
Genericflight.menu.xusb.FS=Low/Full Speed
Expand All @@ -2472,6 +2496,8 @@ Garatronic.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
Garatronic.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
Garatronic.menu.usb.CDC=CDC (no generic 'Serial')
Garatronic.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
Garatronic.menu.usb.CDC_MSC=CDC + MSC
Garatronic.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
Garatronic.menu.usb.HID=HID (keyboard and mouse)
Garatronic.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE

Expand All @@ -2480,6 +2506,8 @@ Midatronics.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
Midatronics.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
Midatronics.menu.usb.CDC=CDC (no generic 'Serial')
Midatronics.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
Midatronics.menu.usb.CDC_MSC=CDC + MSC
Midatronics.menu.usb.CDC_MSC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC_MSC
Midatronics.menu.usb.HID=HID (keyboard and mouse)
Midatronics.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
Midatronics.menu.xusb.FS=Low/Full Speed
Expand Down
126 changes: 126 additions & 0 deletions cores/arduino/USB.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
Copyright (c) 2015 Arduino LLC. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifdef USBCON

#include "usbd_desc.h"
#include "USB.h"
#include "wiring.h"

#ifdef USBD_USE_CDC_CLASS
#include "usbd_cdc.h"
#include "usbd_cdc_msc.h"
#include "usbd_cdc_if.h"
#endif

#ifdef USBD_USE_MSC_CLASS
#include "usbd_msc.h"
#include "usbd_msc_storage_if.h"
#endif

USB USBDevice;

void USB::begin()
{
if (!initialized) {
initialize();
}
}

#ifdef USBD_USE_MSC_CLASS
DummyUSBMscHandler dummyHandler;

void USB::registerMscHandler(USBMscHandler &handler)
{
pSingleMscHandler = &handler;
registerMscHandlers(1, &pSingleMscHandler, USBD_MSC_fops.pInquiry);
}

void USB::registerMscHandlers(uint8_t count, USBMscHandler **ppHandlers, uint8_t *pInquiryData)
{
if (count == 0) {
registerMscHandler(dummyHandler);
} else {
ppUsbMscHandlers = ppHandlers;
usbMscMaxLun = count - 1;
USBD_MSC_fops.pInquiry = pInquiryData;
}
}
#endif

void USB::initialize()
{
hUSBD_Device_CDC = &hUSBD_Device;


/* Init Device Library */
if (USBD_Init(&hUSBD_Device, &USBD_Desc, 0) != USBD_OK) {
return;
}

/* Add Supported Class and register interface */
#ifdef USBD_USE_CDC
if (USBD_RegisterClass(&hUSBD_Device, &USBD_CDC) != USBD_OK) {
return;
}
#elif USBD_USE_CDC_MSC
if (USBD_RegisterClass(&hUSBD_Device, &USBD_CDC_MSC) != USBD_OK) {
return;
}
#elif USBD_USE_MSC
if (USBD_RegisterClass(&hUSBD_Device, &USBD_CDC_MSC) != USBD_OK) {
return;
}
#endif

#ifdef USBD_USE_CDC_CLASS
hUSBD_Device_CDC = &hUSBD_Device;
if (USBD_CDC_RegisterInterface(&hUSBD_Device, &USBD_CDC_fops) != USBD_OK) {
return;
}
#endif

#ifdef USBD_USE_MSC_CLASS
if (ppUsbMscHandlers == nullptr) {
registerMscHandler(dummyHandler);
}
if (USBD_MSC_RegisterStorage(&hUSBD_Device, &USBD_MSC_fops) != USBD_OK) {
return;
}
#endif

/* Start Device Process */
USBD_Start(&hUSBD_Device);
initialized = true;
}

void USB::end()
{
if (initialized) {
deinitialize();
}
}

void USB::deinitialize()
{
USBD_Stop(&hUSBD_Device);
USBD_DeInit(&hUSBD_Device);
initialized = false;
}

#endif // USBCON
58 changes: 58 additions & 0 deletions cores/arduino/USB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright (c) 2015 Arduino LLC. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef _USB_H_
#define _USB_H_

#ifdef USBCON

#include "usbd_core.h"
#include "usbd_ep_conf.h"

#ifdef USBD_USE_MSC_CLASS
#include "USBMscHandler.h"
#endif

class USB {
public:
#ifdef USBD_USE_MSC_CLASS
void registerMscHandler(USBMscHandler &pHandler);
void registerMscHandlers(uint8_t count, USBMscHandler **pHandlers, uint8_t *pInquiryData);
#endif

void begin(void);

void end(void);

protected:
void initialize();
void deinitialize();

bool initialized;

USBD_HandleTypeDef hUSBD_Device;

#ifdef USBD_USE_MSC_CLASS
USBMscHandler *pSingleMscHandler;
#endif
};

extern USB USBDevice;

#endif // USBCON
#endif // _USB_H_
Loading