ram version see usbmsd_sd.cpp ram ok fs CANNOT be installed - too small use for illustrative purpose only
Dependencies: USBDevice USBMSD_SD mbed
Fork of USBMSD_SD_HelloWorld_Mbed by
USBMSD/USBMSD.h
- Committer:
- samux
- Date:
- 2011-11-14
- Revision:
- 8:534fd41d8cc7
- Parent:
- 7:6494da2a5c60
- Child:
- 9:9c343b9ee6d8
File content as of revision 8:534fd41d8cc7:
/* USBMSD.h */ /* USB mass storage device example */ /* Copyright (c) 2011 ARM Limited. All rights reserved. */ /* * Guide to adapt this class to your storage chip: * */ #ifndef USBMSD_H #define USBMSD_H /* These headers are included for child class. */ #include "USBEndpoints.h" #include "USBDescriptor.h" #include "USBDevice_Types.h" #include "USBDevice.h" #define DEFAULT_CONFIGURATION (1) // MSC Bulk-only Stage enum Stage { READ_CBW, // wait a CBW ERROR, // error PROCESS_CBW, // process a CBW request SEND_CSW, // send a CSW WAIT_CSW, // wait that a CSW has been effectively sent }; // Bulk-only CBW typedef __packed struct { uint32_t Signature; uint32_t Tag; uint32_t DataLength; uint8_t Flags; uint8_t LUN; uint8_t CBLength; uint8_t CB[16]; } CBW; // Bulk-only CSW typedef __packed struct { uint32_t Signature; uint32_t Tag; uint32_t DataResidue; uint8_t Status; } CSW; class USBMSD: public USBDevice { public: /** * Constructor * * @param vendor_id Your vendor_id * @param product_id Your product_id * @param product_release Your preoduct_release */ USBMSD(uint16_t vendor_id = 0x0703, uint16_t product_id = 0x0104, uint16_t product_release = 0x0001); /* * read a block on a storage chip * * @param data pointer where will be stored read data * @param block block number * @returns 0 if successful */ virtual int disk_read(char *buffer, int block_number){return 1;}; /* * write a block on a storage chip * * @param data data to write * @param block block number * @returns 0 if successful */ virtual int disk_write(const char *buffer, int block_number){return 1;}; /* * Disk initilization */ virtual int disk_initialize(){return -1;}; /* * Return number of sectors * * @returns number of sectors */ virtual int disk_sectors(){return 0;}; virtual void set_status(int st){}; /* * Connect the USB MSD device. Establish disk initialization before really connect the device. * * @returns */ bool connect(); protected: /* * Get number of logical unit - 1 (here 0) * * @returns Pointer containing the number of logical unit - 1 */ uint8_t * getMaxLUN(); /* * Get string product descriptor * * @returns pointer to the string product descriptor */ virtual uint8_t * stringIproductDesc(); /* * Get string interface descriptor * * @returns pointer to the string interface descriptor */ virtual uint8_t * stringIinterfaceDesc(); /* * Get configuration descriptor * * @returns pointer to the configuration descriptor */ virtual uint8_t * configurationDesc(); /* * Callback called when a packet is received */ virtual bool EP2_OUT_callback(); /* * Callback called when a packet has been sent */ virtual bool EP2_IN_callback(); /* * Set configuration of device. Add endpoints */ virtual bool USBCallback_setConfiguration(uint8_t configuration); /* * Callback called to process class specific requests */ virtual bool USBCallback_request(); private: //state of the bulk-only state machine Stage stage; // current CBW CBW cbw; // CSW which will be sent CSW csw; // addr where will be read or written data uint32_t addr; // length of a reading or writing uint32_t length; // memory OK (after a memoryVerify) bool memOK; // cache in RAM before writing in memory. Useful also to read a block. uint8_t * page; uint16_t BlockSize; uint32_t MemorySize; uint32_t BlockCount; void CBWDecode(uint8_t * buf, uint16_t size); void sendCSW (void); bool inquiryRequest (void); bool write (uint8_t * buf, uint16_t size); bool readFormatCapacity(); bool readCapacity (void); bool infoTransfer (void); void memoryRead (void); bool modeSense6 (void); void testUnitReady (void); bool requestSense (void); void memoryVerify (uint8_t * buf, uint16_t size); void memoryWrite (uint8_t * buf, uint16_t size); void reset(); void fail(); }; #endif