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 Norimasa Okamoto

Committer:
va009039
Date:
Mon Feb 03 13:00:16 2014 +0000
Revision:
9:7f9f64cf5ded
Parent:
8:6463cd1964c0
add interrupt write transfer.

Who changed what in which revision?

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