USBMSD class: generic class in order to use all kinds of blocks storage chip. More...
#include <USBMSD.h>
 
  
 | Public Member Functions | |
| USBMSD (BlockDevice *bd, bool connect_blocking=true, uint16_t vendor_id=0x0703, uint16_t product_id=0x0104, uint16_t product_release=0x0001) | |
| Constructor.  More... | |
| USBMSD (USBPhy *phy, BlockDevice *bd, uint16_t vendor_id, uint16_t product_id, uint16_t product_release) | |
| Fully featured constructor.  More... | |
| virtual | ~USBMSD () | 
| Destroy this object.  More... | |
| bool | connect () | 
| Connect the USB MSD device.  More... | |
| void | disconnect () | 
| Disconnect the USB MSD device.  More... | |
| void | process () | 
| Perform USB processing.  More... | |
| void | attach (mbed::Callback< void()> cb) | 
| Called when USBMSD needs to perform processing.  More... | |
| bool | media_removed () | 
| Check if MSD device was removed/unmounted on the host side.  More... | |
| void | init () | 
| Initialize this instance.  More... | |
| void | deinit () | 
| Power down this instance.  More... | |
| bool | configured () | 
| Check if the device is configured.  More... | |
| void | sof_enable () | 
| Enable the start of frame interrupt.  More... | |
| void | sof_disable () | 
| Disable the start of frame interrupt.  More... | |
| bool | endpoint_add (usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, ep_cb_t callback=NULL) | 
| Add an endpoint.  More... | |
| template<typename T > | |
| bool | endpoint_add (usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, void(T::*callback)()) | 
| Add an endpoint.  More... | |
| void | endpoint_remove (usb_ep_t endpoint) | 
| Remove an endpoint.  More... | |
| void | endpoint_remove_all () | 
| Remove all non-zero endpoints.  More... | |
| void | endpoint_stall (usb_ep_t endpoint) | 
| Stall an endpoint.  More... | |
| void | endpoint_unstall (usb_ep_t endpoint) | 
| Unstall an endpoint.  More... | |
| uint32_t | endpoint_max_packet_size (usb_ep_t endpoint) | 
| Get the current maximum size for this endpoint.  More... | |
| void | endpoint_abort (usb_ep_t endpoint) | 
| Abort the current transfer on this endpoint.  More... | |
| bool | read_start (usb_ep_t endpoint, uint8_t *buffer, uint32_t size) | 
| start a read on the given endpoint  More... | |
| uint32_t | read_finish (usb_ep_t endpoint) | 
| Get the status of a read.  More... | |
| bool | write_start (usb_ep_t endpoint, uint8_t *buffer, uint32_t size) | 
| Write a data to the given endpoint.  More... | |
| uint32_t | write_finish (usb_ep_t endpoint) | 
| Get the status of a write.  More... | |
| Protected Member Functions | |
| virtual void | callback_power (bool powered) | 
| Called by USBDevice layer on power state change.  More... | |
| virtual void | callback_sof (int frame_number) | 
| Called by USBDevice layer on each new USB frame.  More... | |
| virtual void | callback_reset () | 
| Called by USBDevice layer on bus reset.  More... | |
| void | complete_request (RequestResult result, uint8_t *data=NULL, uint32_t size=0) | 
| Called to complete the setup stage of a callback request.  More... | |
| void | complete_request_xfer_done (bool success) | 
| Called to complete the data stage of a callback request.  More... | |
| void | complete_set_configuration (bool success) | 
| Called to complete a set configuration command.  More... | |
| void | complete_set_interface (bool success) | 
| Called to complete a set interface command.  More... | |
| uint8_t * | find_descriptor (uint8_t descriptor_type, uint8_t index=0) | 
| Find a descriptor type inside the configuration descriptor.  More... | |
| const usb_ep_table_t * | endpoint_table () | 
| Get the endpoint table of this device.  More... | |
| virtual void | start_process () | 
| Callback called to indicate the USB processing needs to be done.  More... | |
| virtual void | lock () | 
| Acquire exclusive access to this instance USBDevice.  More... | |
| virtual void | unlock () | 
| Release exclusive access to this instance USBDevice.  More... | |
| virtual void | assert_locked () | 
| Assert that the current thread of execution holds the lock.  More... | |
USBMSD class: generic class in order to use all kinds of blocks storage chip.
Introduction
USBMSD implements the MSD protocol. It permits to access a block device (flash, sdcard,...) from a computer over USB.
| USBMSD | ( | BlockDevice * | bd, | 
| bool | connect_blocking = true, | ||
| uint16_t | vendor_id = 0x0703, | ||
| uint16_t | product_id = 0x0104, | ||
| uint16_t | product_release = 0x0001 | ||
| ) | 
Constructor.
This creates a new USBMSD object with the given block device. Connect must be called for the block device to connect.
| bd | BlockDevice to mount as a USB drive | 
| connect_blocking | true to perform a blocking connect, false to start in a disconnected state | 
| vendor_id | Your vendor_id | 
| product_id | Your product_id | 
| product_release | Your preoduct_release | 
| USBMSD | ( | USBPhy * | phy, | 
| BlockDevice * | bd, | ||
| uint16_t | vendor_id, | ||
| uint16_t | product_id, | ||
| uint16_t | product_release | ||
| ) | 
Fully featured constructor.
Construct this object with the supplied USBPhy and parameters. The user this object is responsible for calling connect() or init().
| phy | USB phy to use | 
| bd | BlockDevice to mount as a USB drive | 
| vendor_id | Your vendor_id | 
| product_id | Your product_id | 
| product_release | Your preoduct_release | 
| 
 | virtual | 
Destroy this object.
Any classes which inherit from this class must call disconnect before this destructor runs.
| 
 | protectedvirtualinherited | 
Assert that the current thread of execution holds the lock.
| void attach | ( | mbed::Callback< void()> | cb | ) | 
| 
 | protectedvirtualinherited | 
Called by USBDevice layer on power state change.
| powered | true if device is powered, false otherwise | 
Warning: Called in ISR context
Definition at line 341 of file USBDevice.h.
| 
 | protectedvirtualinherited | 
Called by USBDevice layer on bus reset.
complete_reset must be called after the device is fully reset.
Warning: Called in ISR context
Reimplemented in USBCDC_ECM, USBCDC, and USBTester.
Definition at line 369 of file USBDevice.h.
| 
 | protectedvirtualinherited | 
Called by USBDevice layer on each new USB frame.
Callbacks are enabled and disabled by calling sof_enable and sof_disable.
| frame_number | The current frame number | 
Warning: Called in ISR context
Definition at line 356 of file USBDevice.h.
| 
 | protectedinherited | 
Called to complete the setup stage of a callback request.
Possible options that can be passed as a result are:
| result | The result of the setup phase. | 
| data | Buffer to send or receive if the result is Send or Receive | 
| size | Size to transfer if the result is Send or Receive | 
| 
 | protectedinherited | 
Called to complete the data stage of a callback request.
| success | true if the operation was successful, false otherwise | 
| 
 | protectedinherited | 
Called to complete a set configuration command.
| success | true if the configuration was set, false otherwise | 
| 
 | protectedinherited | 
Called to complete a set interface command.
| success | true if the interface was set, false otherwise | 
| 
 | inherited | 
Check if the device is configured.
| bool connect | ( | ) | 
Connect the USB MSD device.
| 
 | inherited | 
Power down this instance.
Disable interrupts and stop sending events.
| void disconnect | ( | ) | 
Disconnect the USB MSD device.
| 
 | inherited | 
Abort the current transfer on this endpoint.
| endpoint | endpoint with transfer to abort | 
| 
 | inherited | 
Add an endpoint.
| endpoint | Endpoint to enable | 
| max_packet | Maximum size of a packet which can be sent or received on this endpoint | 
| type | Endpoint type - USB_EP_TYPE_BULK, USB_EP_TYPE_INT or USB_EP_TYPE_ISO | 
| callback | Method pointer to be called when a packet is transferred | 
| 
 | inherited | 
Add an endpoint.
| endpoint | Endpoint to enable | 
| max_packet | Maximum size of a packet which can be sent or received on this endpoint | 
| type | Endpoint type - USB_EP_TYPE_BULK, USB_EP_TYPE_INT or USB_EP_TYPE_ISO | 
| callback | Method pointer to be called when a packet is transferred | 
Definition at line 161 of file USBDevice.h.
| 
 | inherited | 
Get the current maximum size for this endpoint.
Return the currently configured maximum packet size, wMaxPacketSize, for this endpoint.
| 
 | inherited | 
Remove an endpoint.
| endpoint | Endpoint to disable | 
| 
 | inherited | 
Remove all non-zero endpoints.
| 
 | inherited | 
Stall an endpoint.
If there is an ongoing transfer on this endpoint then it will be aborted.
| endpoint | Endpoint to stall | 
| 
 | protectedinherited | 
| 
 | inherited | 
Unstall an endpoint.
Unstalling an endpoint resets data toggle back to DATA0. Additionally, if there is an ongoing transfer on this endpoint it will be aborted.
| endpoint | Endpoint to unstall | 
| 
 | protectedinherited | 
Find a descriptor type inside the configuration descriptor.
| descriptor_type | Type of descriptor to find | 
| index | Configuration descriptor index ( 0 if only one configuration present ) | 
| 
 | inherited | 
Initialize this instance.
This function must be called before calling any other functions of this class, unless specifically
| 
 | protectedvirtualinherited | 
Acquire exclusive access to this instance USBDevice.
| bool media_removed | ( | ) | 
Check if MSD device was removed/unmounted on the host side.
| void process | ( | ) | 
Perform USB processing.
| 
 | inherited | 
Get the status of a read.
| endpoint | endpoint to get the status of | 
| 
 | inherited | 
start a read on the given endpoint
Start a read on the given endpoint. The data buffer must remain unchanged until the transfer either completes or is aborted.
| endpoint | endpoint to read data from | 
| buffer | buffer to fill with read data | 
| size | The size of data to read. This must be greater than or equal to the max packet size for this endpoint | 
| 
 | inherited | 
Disable the start of frame interrupt.
Stop calling USBDevice::callback_sof.
| 
 | inherited | 
Enable the start of frame interrupt.
Call USBDevice::callback_sof on every frame.
| 
 | protectedvirtualinherited | 
Callback called to indicate the USB processing needs to be done.
Implements USBPhyEvents.
| 
 | protectedvirtualinherited | 
Release exclusive access to this instance USBDevice.
| 
 | inherited | 
Get the status of a write.
| endpoint | endpoint to get the status of | 
| 
 | inherited | 
Write a data to the given endpoint.
Write data to an endpoint. The data sent must remain unchanged until the transfer either completes or is aborted.
| endpoint | endpoint to write data to | 
| buffer | data to write | 
| size | the size of data to send. This must be less than or equal to the max packet size of this endpoint |