Added TARGET_DISCO_F469NI in USBHOST\USBHost\TARGET_STM\USBHALHost_STM_TARGET.h
Dependents: DISCO-F469NI_USB_Disk STM32F4xx_USB_Memory
Fork of USBHOST by
USBHostMSD/USBHostMSD.h@1:ab240722d7ef, 2017-02-15 (annotated)
- Committer:
- frq08711@LMECWL0871.LME.ST.COM
- Date:
- Wed Feb 15 10:49:44 2017 +0100
- Revision:
- 1:ab240722d7ef
- Child:
- 4:fb979eb32081
- Child:
- 5:fc157e6bd5a5
update to mbed 5.3.5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1 | /* mbed USBHost Library |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 2 | * Copyright (c) 2006-2013 ARM Limited |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 3 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 5 | * you may not use this file except in compliance with the License. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 6 | * You may obtain a copy of the License at |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 7 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 9 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 10 | * Unless required by applicable law or agreed to in writing, software |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 13 | * See the License for the specific language governing permissions and |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 14 | * limitations under the License. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 15 | */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 16 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 17 | #ifndef USBHOSTMSD_H |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 18 | #define USBHOSTMSD_H |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 19 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 20 | #include "USBHostConf.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 21 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 22 | #if USBHOST_MSD |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 23 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 24 | #include "USBHost.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 25 | #include "FATFileSystem.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 26 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 27 | /** |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 28 | * A class to communicate a USB flash disk |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 29 | */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 30 | class USBHostMSD : public IUSBEnumerator, public FATFileSystem { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 31 | public: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 32 | /** |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 33 | * Constructor |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 34 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 35 | * @param rootdir mount name |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 36 | */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 37 | USBHostMSD(const char * rootdir); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 38 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 39 | /** |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 40 | * Check if a MSD device is connected |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 41 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 42 | * @return true if a MSD device is connected |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 43 | */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 44 | bool connected(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 45 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 46 | /** |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 47 | * Try to connect to a MSD device |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 48 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 49 | * @return true if connection was successful |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 50 | */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 51 | bool connect(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 52 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 53 | protected: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 54 | //From IUSBEnumerator |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 55 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 56 | virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 57 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 58 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 59 | // From FATFileSystem |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 60 | virtual int disk_initialize(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 61 | virtual int disk_status() {return 0;}; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 62 | virtual int disk_read(uint8_t* buffer, uint32_t sector, uint32_t count); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 63 | virtual int disk_write(const uint8_t* buffer, uint32_t sector, uint32_t count); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 64 | virtual int disk_sync() {return 0;}; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 65 | virtual uint32_t disk_sectors(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 66 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 67 | private: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 68 | USBHost * host; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 69 | USBDeviceConnected * dev; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 70 | bool dev_connected; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 71 | USBEndpoint * bulk_in; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 72 | USBEndpoint * bulk_out; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 73 | uint8_t nb_ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 74 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 75 | // Bulk-only CBW |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 76 | typedef struct { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 77 | uint32_t Signature; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 78 | uint32_t Tag; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 79 | uint32_t DataLength; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 80 | uint8_t Flags; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 81 | uint8_t LUN; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 82 | uint8_t CBLength; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 83 | uint8_t CB[16]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 84 | } PACKED CBW; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 85 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 86 | // Bulk-only CSW |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 87 | typedef struct { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 88 | uint32_t Signature; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 89 | uint32_t Tag; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 90 | uint32_t DataResidue; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 91 | uint8_t Status; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 92 | } PACKED CSW; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 93 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 94 | CBW cbw; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 95 | CSW csw; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 96 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 97 | int SCSITransfer(uint8_t * cmd, uint8_t cmd_len, int flags, uint8_t * data, uint32_t transfer_len); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 98 | int testUnitReady(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 99 | int readCapacity(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 100 | int inquiry(uint8_t lun, uint8_t page_code); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 101 | int SCSIRequestSense(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 102 | int dataTransfer(uint8_t * buf, uint32_t block, uint8_t nbBlock, int direction); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 103 | int checkResult(uint8_t res, USBEndpoint * ep); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 104 | int getMaxLun(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 105 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 106 | int blockSize; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 107 | uint32_t blockCount; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 108 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 109 | int msd_intf; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 110 | bool msd_device_found; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 111 | bool disk_init; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 112 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 113 | void init(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 114 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 115 | }; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 116 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 117 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 118 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 119 | #endif |