Fork of [[https://os.mbed.com/users/va009039/code/F401RE-USBHost/]]. Added support for Seeed Arch Max and STM32F407.

Dependents:   STM32F407VET6_USBHostMSD STM32F407VET6_USBHostMouse STM32F407VET6_USBHostKeyboard STM32F407VET6_USBHostMSD_1

Committer:
hudakz
Date:
Tue Feb 19 21:32:56 2019 +0000
Revision:
0:458bf947f46f
Fork of [[https://os.mbed.com/users/va009039/code/F401RE-USBHost/]]. Added support for Seeed Arch Max and STM32F407.

Who changed what in which revision?

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