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