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:
Sat Jan 25 12:51:44 2014 +0000
Revision:
3:a3872f7593e2
Child:
8:6463cd1964c0
fix max packet size

Who changed what in which revision?

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