library

Dependents:   USB_CDC_MSD_Hello

Committer:
sherckuith
Date:
Fri Aug 24 02:01:51 2012 +0000
Revision:
0:d5bb9a9c3e24
[mbed] converted /USB_CDC_MSD_Hello/USBDevice

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sherckuith 0:d5bb9a9c3e24 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
sherckuith 0:d5bb9a9c3e24 2 *
sherckuith 0:d5bb9a9c3e24 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
sherckuith 0:d5bb9a9c3e24 4 * and associated documentation files (the "Software"), to deal in the Software without
sherckuith 0:d5bb9a9c3e24 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
sherckuith 0:d5bb9a9c3e24 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
sherckuith 0:d5bb9a9c3e24 7 * Software is furnished to do so, subject to the following conditions:
sherckuith 0:d5bb9a9c3e24 8 *
sherckuith 0:d5bb9a9c3e24 9 * The above copyright notice and this permission notice shall be included in all copies or
sherckuith 0:d5bb9a9c3e24 10 * substantial portions of the Software.
sherckuith 0:d5bb9a9c3e24 11 *
sherckuith 0:d5bb9a9c3e24 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
sherckuith 0:d5bb9a9c3e24 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
sherckuith 0:d5bb9a9c3e24 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
sherckuith 0:d5bb9a9c3e24 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
sherckuith 0:d5bb9a9c3e24 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sherckuith 0:d5bb9a9c3e24 17 */
sherckuith 0:d5bb9a9c3e24 18
sherckuith 0:d5bb9a9c3e24 19 #include "stdint.h"
sherckuith 0:d5bb9a9c3e24 20 #include "USBMSD.h"
sherckuith 0:d5bb9a9c3e24 21
sherckuith 0:d5bb9a9c3e24 22 #define DISK_OK 0x00
sherckuith 0:d5bb9a9c3e24 23 #define NO_INIT 0x01
sherckuith 0:d5bb9a9c3e24 24 #define NO_DISK 0x02
sherckuith 0:d5bb9a9c3e24 25 #define WRITE_PROTECT 0x04
sherckuith 0:d5bb9a9c3e24 26
sherckuith 0:d5bb9a9c3e24 27 #define CBW_Signature 0x43425355
sherckuith 0:d5bb9a9c3e24 28 #define CSW_Signature 0x53425355
sherckuith 0:d5bb9a9c3e24 29
sherckuith 0:d5bb9a9c3e24 30 // SCSI Commands
sherckuith 0:d5bb9a9c3e24 31 #define TEST_UNIT_READY 0x00
sherckuith 0:d5bb9a9c3e24 32 #define REQUEST_SENSE 0x03
sherckuith 0:d5bb9a9c3e24 33 #define FORMAT_UNIT 0x04
sherckuith 0:d5bb9a9c3e24 34 #define INQUIRY 0x12
sherckuith 0:d5bb9a9c3e24 35 #define MODE_SELECT6 0x15
sherckuith 0:d5bb9a9c3e24 36 #define MODE_SENSE6 0x1A
sherckuith 0:d5bb9a9c3e24 37 #define START_STOP_UNIT 0x1B
sherckuith 0:d5bb9a9c3e24 38 #define MEDIA_REMOVAL 0x1E
sherckuith 0:d5bb9a9c3e24 39 #define READ_FORMAT_CAPACITIES 0x23
sherckuith 0:d5bb9a9c3e24 40 #define READ_CAPACITY 0x25
sherckuith 0:d5bb9a9c3e24 41 #define READ10 0x28
sherckuith 0:d5bb9a9c3e24 42 #define WRITE10 0x2A
sherckuith 0:d5bb9a9c3e24 43 #define VERIFY10 0x2F
sherckuith 0:d5bb9a9c3e24 44 #define READ12 0xA8
sherckuith 0:d5bb9a9c3e24 45 #define WRITE12 0xAA
sherckuith 0:d5bb9a9c3e24 46 #define MODE_SELECT10 0x55
sherckuith 0:d5bb9a9c3e24 47 #define MODE_SENSE10 0x5A
sherckuith 0:d5bb9a9c3e24 48
sherckuith 0:d5bb9a9c3e24 49 // MSC class specific requests
sherckuith 0:d5bb9a9c3e24 50 #define MSC_REQUEST_RESET 0xFF
sherckuith 0:d5bb9a9c3e24 51 #define MSC_REQUEST_GET_MAX_LUN 0xFE
sherckuith 0:d5bb9a9c3e24 52
sherckuith 0:d5bb9a9c3e24 53 #define DEFAULT_CONFIGURATION (1)
sherckuith 0:d5bb9a9c3e24 54
sherckuith 0:d5bb9a9c3e24 55 // max packet size
sherckuith 0:d5bb9a9c3e24 56 #define MAX_PACKET MAX_PACKET_SIZE_EPBULK
sherckuith 0:d5bb9a9c3e24 57
sherckuith 0:d5bb9a9c3e24 58 // CSW Status
sherckuith 0:d5bb9a9c3e24 59 enum Status {
sherckuith 0:d5bb9a9c3e24 60 CSW_PASSED,
sherckuith 0:d5bb9a9c3e24 61 CSW_FAILED,
sherckuith 0:d5bb9a9c3e24 62 CSW_ERROR,
sherckuith 0:d5bb9a9c3e24 63 };
sherckuith 0:d5bb9a9c3e24 64
sherckuith 0:d5bb9a9c3e24 65
sherckuith 0:d5bb9a9c3e24 66 USBMSD::USBMSD(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release) {
sherckuith 0:d5bb9a9c3e24 67 }
sherckuith 0:d5bb9a9c3e24 68
sherckuith 0:d5bb9a9c3e24 69
sherckuith 0:d5bb9a9c3e24 70
sherckuith 0:d5bb9a9c3e24 71 // Called in ISR context to process a class specific request
sherckuith 0:d5bb9a9c3e24 72 bool USBMSD::USBCallback_request(void) {
sherckuith 0:d5bb9a9c3e24 73
sherckuith 0:d5bb9a9c3e24 74 bool success = false;
sherckuith 0:d5bb9a9c3e24 75 CONTROL_TRANSFER * transfer = getTransferPtr();
sherckuith 0:d5bb9a9c3e24 76 static uint8_t maxLUN[1] = {0};
sherckuith 0:d5bb9a9c3e24 77
sherckuith 0:d5bb9a9c3e24 78 if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {
sherckuith 0:d5bb9a9c3e24 79 switch (transfer->setup.bRequest) {
sherckuith 0:d5bb9a9c3e24 80 case MSC_REQUEST_RESET:
sherckuith 0:d5bb9a9c3e24 81 reset();
sherckuith 0:d5bb9a9c3e24 82 success = true;
sherckuith 0:d5bb9a9c3e24 83 break;
sherckuith 0:d5bb9a9c3e24 84 case MSC_REQUEST_GET_MAX_LUN:
sherckuith 0:d5bb9a9c3e24 85 transfer->remaining = 1;
sherckuith 0:d5bb9a9c3e24 86 transfer->ptr = maxLUN;
sherckuith 0:d5bb9a9c3e24 87 transfer->direction = DEVICE_TO_HOST;
sherckuith 0:d5bb9a9c3e24 88 success = true;
sherckuith 0:d5bb9a9c3e24 89 break;
sherckuith 0:d5bb9a9c3e24 90 default:
sherckuith 0:d5bb9a9c3e24 91 break;
sherckuith 0:d5bb9a9c3e24 92 }
sherckuith 0:d5bb9a9c3e24 93 }
sherckuith 0:d5bb9a9c3e24 94
sherckuith 0:d5bb9a9c3e24 95 return success;
sherckuith 0:d5bb9a9c3e24 96 }
sherckuith 0:d5bb9a9c3e24 97
sherckuith 0:d5bb9a9c3e24 98
sherckuith 0:d5bb9a9c3e24 99 bool USBMSD::connect() {
sherckuith 0:d5bb9a9c3e24 100
sherckuith 0:d5bb9a9c3e24 101 //disk initialization
sherckuith 0:d5bb9a9c3e24 102 if (disk_status() & NO_INIT) {
sherckuith 0:d5bb9a9c3e24 103 if (disk_initialize()) {
sherckuith 0:d5bb9a9c3e24 104 return false;
sherckuith 0:d5bb9a9c3e24 105 }
sherckuith 0:d5bb9a9c3e24 106 }
sherckuith 0:d5bb9a9c3e24 107
sherckuith 0:d5bb9a9c3e24 108 // get number of blocks
sherckuith 0:d5bb9a9c3e24 109 BlockCount = disk_sectors();
sherckuith 0:d5bb9a9c3e24 110
sherckuith 0:d5bb9a9c3e24 111 // get memory size
sherckuith 0:d5bb9a9c3e24 112 MemorySize = disk_size();
sherckuith 0:d5bb9a9c3e24 113
sherckuith 0:d5bb9a9c3e24 114 if (BlockCount >= 0) {
sherckuith 0:d5bb9a9c3e24 115 BlockSize = MemorySize / BlockCount;
sherckuith 0:d5bb9a9c3e24 116 if (BlockSize != 0) {
sherckuith 0:d5bb9a9c3e24 117 page = (uint8_t *)malloc(BlockSize * sizeof(uint8_t));
sherckuith 0:d5bb9a9c3e24 118 if (page == NULL)
sherckuith 0:d5bb9a9c3e24 119 return false;
sherckuith 0:d5bb9a9c3e24 120 }
sherckuith 0:d5bb9a9c3e24 121 } else {
sherckuith 0:d5bb9a9c3e24 122 return false;
sherckuith 0:d5bb9a9c3e24 123 }
sherckuith 0:d5bb9a9c3e24 124
sherckuith 0:d5bb9a9c3e24 125 //connect the device
sherckuith 0:d5bb9a9c3e24 126 USBDevice::connect();
sherckuith 0:d5bb9a9c3e24 127 return true;
sherckuith 0:d5bb9a9c3e24 128 }
sherckuith 0:d5bb9a9c3e24 129
sherckuith 0:d5bb9a9c3e24 130
sherckuith 0:d5bb9a9c3e24 131 void USBMSD::reset() {
sherckuith 0:d5bb9a9c3e24 132 stage = READ_CBW;
sherckuith 0:d5bb9a9c3e24 133 }
sherckuith 0:d5bb9a9c3e24 134
sherckuith 0:d5bb9a9c3e24 135
sherckuith 0:d5bb9a9c3e24 136 // Called in ISR context called when a data is received
sherckuith 0:d5bb9a9c3e24 137 bool USBMSD::EP2_OUT_callback() {
sherckuith 0:d5bb9a9c3e24 138 uint16_t size = 0;
sherckuith 0:d5bb9a9c3e24 139 uint8_t buf[MAX_PACKET_SIZE_EPBULK];
sherckuith 0:d5bb9a9c3e24 140 readEP(EPBULK_OUT, buf, &size, MAX_PACKET_SIZE_EPBULK);
sherckuith 0:d5bb9a9c3e24 141 switch (stage) {
sherckuith 0:d5bb9a9c3e24 142 // the device has to decode the CBW received
sherckuith 0:d5bb9a9c3e24 143 case READ_CBW:
sherckuith 0:d5bb9a9c3e24 144 CBWDecode(buf, size);
sherckuith 0:d5bb9a9c3e24 145 break;
sherckuith 0:d5bb9a9c3e24 146
sherckuith 0:d5bb9a9c3e24 147 // the device has to receive data from the host
sherckuith 0:d5bb9a9c3e24 148 case PROCESS_CBW:
sherckuith 0:d5bb9a9c3e24 149 switch (cbw.CB[0]) {
sherckuith 0:d5bb9a9c3e24 150 case WRITE10:
sherckuith 0:d5bb9a9c3e24 151 case WRITE12:
sherckuith 0:d5bb9a9c3e24 152 memoryWrite(buf, size);
sherckuith 0:d5bb9a9c3e24 153 break;
sherckuith 0:d5bb9a9c3e24 154 case VERIFY10:
sherckuith 0:d5bb9a9c3e24 155 memoryVerify(buf, size);
sherckuith 0:d5bb9a9c3e24 156 break;
sherckuith 0:d5bb9a9c3e24 157 }
sherckuith 0:d5bb9a9c3e24 158 break;
sherckuith 0:d5bb9a9c3e24 159
sherckuith 0:d5bb9a9c3e24 160 // an error has occured: stall endpoint and send CSW
sherckuith 0:d5bb9a9c3e24 161 default:
sherckuith 0:d5bb9a9c3e24 162 stallEndpoint(EPBULK_OUT);
sherckuith 0:d5bb9a9c3e24 163 csw.Status = CSW_ERROR;
sherckuith 0:d5bb9a9c3e24 164 sendCSW();
sherckuith 0:d5bb9a9c3e24 165 break;
sherckuith 0:d5bb9a9c3e24 166 }
sherckuith 0:d5bb9a9c3e24 167
sherckuith 0:d5bb9a9c3e24 168 //reactivate readings on the OUT bulk endpoint
sherckuith 0:d5bb9a9c3e24 169 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
sherckuith 0:d5bb9a9c3e24 170 return true;
sherckuith 0:d5bb9a9c3e24 171 }
sherckuith 0:d5bb9a9c3e24 172
sherckuith 0:d5bb9a9c3e24 173 // Called in ISR context when a data has been transferred
sherckuith 0:d5bb9a9c3e24 174 bool USBMSD::EP2_IN_callback() {
sherckuith 0:d5bb9a9c3e24 175 switch (stage) {
sherckuith 0:d5bb9a9c3e24 176
sherckuith 0:d5bb9a9c3e24 177 // the device has to send data to the host
sherckuith 0:d5bb9a9c3e24 178 case PROCESS_CBW:
sherckuith 0:d5bb9a9c3e24 179 switch (cbw.CB[0]) {
sherckuith 0:d5bb9a9c3e24 180 case READ10:
sherckuith 0:d5bb9a9c3e24 181 case READ12:
sherckuith 0:d5bb9a9c3e24 182 memoryRead();
sherckuith 0:d5bb9a9c3e24 183 break;
sherckuith 0:d5bb9a9c3e24 184 }
sherckuith 0:d5bb9a9c3e24 185 break;
sherckuith 0:d5bb9a9c3e24 186
sherckuith 0:d5bb9a9c3e24 187 //the device has to send a CSW
sherckuith 0:d5bb9a9c3e24 188 case SEND_CSW:
sherckuith 0:d5bb9a9c3e24 189 sendCSW();
sherckuith 0:d5bb9a9c3e24 190 break;
sherckuith 0:d5bb9a9c3e24 191
sherckuith 0:d5bb9a9c3e24 192 // an error has occured
sherckuith 0:d5bb9a9c3e24 193 case ERROR:
sherckuith 0:d5bb9a9c3e24 194 stallEndpoint(EPBULK_IN);
sherckuith 0:d5bb9a9c3e24 195 sendCSW();
sherckuith 0:d5bb9a9c3e24 196 break;
sherckuith 0:d5bb9a9c3e24 197
sherckuith 0:d5bb9a9c3e24 198 // the host has received the CSW -> we wait a CBW
sherckuith 0:d5bb9a9c3e24 199 case WAIT_CSW:
sherckuith 0:d5bb9a9c3e24 200 stage = READ_CBW;
sherckuith 0:d5bb9a9c3e24 201 break;
sherckuith 0:d5bb9a9c3e24 202 }
sherckuith 0:d5bb9a9c3e24 203 return true;
sherckuith 0:d5bb9a9c3e24 204 }
sherckuith 0:d5bb9a9c3e24 205
sherckuith 0:d5bb9a9c3e24 206
sherckuith 0:d5bb9a9c3e24 207 void USBMSD::memoryWrite (uint8_t * buf, uint16_t size) {
sherckuith 0:d5bb9a9c3e24 208
sherckuith 0:d5bb9a9c3e24 209 if ((addr + size) > MemorySize) {
sherckuith 0:d5bb9a9c3e24 210 size = MemorySize - addr;
sherckuith 0:d5bb9a9c3e24 211 stage = ERROR;
sherckuith 0:d5bb9a9c3e24 212 stallEndpoint(EPBULK_OUT);
sherckuith 0:d5bb9a9c3e24 213 }
sherckuith 0:d5bb9a9c3e24 214
sherckuith 0:d5bb9a9c3e24 215 // we fill an array in RAM of 1 block before writing it in memory
sherckuith 0:d5bb9a9c3e24 216 for (int i = 0; i < size; i++)
sherckuith 0:d5bb9a9c3e24 217 page[addr%BlockSize + i] = buf[i];
sherckuith 0:d5bb9a9c3e24 218
sherckuith 0:d5bb9a9c3e24 219 // if the array is filled, write it in memory
sherckuith 0:d5bb9a9c3e24 220 if (!((addr + size)%BlockSize)) {
sherckuith 0:d5bb9a9c3e24 221 if (!(disk_status() & WRITE_PROTECT)) {
sherckuith 0:d5bb9a9c3e24 222 disk_write((const char *)page, addr/BlockSize);
sherckuith 0:d5bb9a9c3e24 223 }
sherckuith 0:d5bb9a9c3e24 224 }
sherckuith 0:d5bb9a9c3e24 225
sherckuith 0:d5bb9a9c3e24 226 addr += size;
sherckuith 0:d5bb9a9c3e24 227 length -= size;
sherckuith 0:d5bb9a9c3e24 228 csw.DataResidue -= size;
sherckuith 0:d5bb9a9c3e24 229
sherckuith 0:d5bb9a9c3e24 230 if ((!length) || (stage != PROCESS_CBW)) {
sherckuith 0:d5bb9a9c3e24 231 csw.Status = (stage == ERROR) ? CSW_FAILED : CSW_PASSED;
sherckuith 0:d5bb9a9c3e24 232 sendCSW();
sherckuith 0:d5bb9a9c3e24 233 }
sherckuith 0:d5bb9a9c3e24 234 }
sherckuith 0:d5bb9a9c3e24 235
sherckuith 0:d5bb9a9c3e24 236 void USBMSD::memoryVerify (uint8_t * buf, uint16_t size) {
sherckuith 0:d5bb9a9c3e24 237 uint32_t n;
sherckuith 0:d5bb9a9c3e24 238
sherckuith 0:d5bb9a9c3e24 239 if ((addr + size) > MemorySize) {
sherckuith 0:d5bb9a9c3e24 240 size = MemorySize - addr;
sherckuith 0:d5bb9a9c3e24 241 stage = ERROR;
sherckuith 0:d5bb9a9c3e24 242 stallEndpoint(EPBULK_OUT);
sherckuith 0:d5bb9a9c3e24 243 }
sherckuith 0:d5bb9a9c3e24 244
sherckuith 0:d5bb9a9c3e24 245 // beginning of a new block -> load a whole block in RAM
sherckuith 0:d5bb9a9c3e24 246 if (!(addr%BlockSize))
sherckuith 0:d5bb9a9c3e24 247 disk_read((char *)page, addr/BlockSize);
sherckuith 0:d5bb9a9c3e24 248
sherckuith 0:d5bb9a9c3e24 249 // info are in RAM -> no need to re-read memory
sherckuith 0:d5bb9a9c3e24 250 for (n = 0; n < size; n++) {
sherckuith 0:d5bb9a9c3e24 251 if (page[addr%BlockSize + n] != buf[n]) {
sherckuith 0:d5bb9a9c3e24 252 memOK = false;
sherckuith 0:d5bb9a9c3e24 253 break;
sherckuith 0:d5bb9a9c3e24 254 }
sherckuith 0:d5bb9a9c3e24 255 }
sherckuith 0:d5bb9a9c3e24 256
sherckuith 0:d5bb9a9c3e24 257 addr += size;
sherckuith 0:d5bb9a9c3e24 258 length -= size;
sherckuith 0:d5bb9a9c3e24 259 csw.DataResidue -= size;
sherckuith 0:d5bb9a9c3e24 260
sherckuith 0:d5bb9a9c3e24 261 if ( !length || (stage != PROCESS_CBW)) {
sherckuith 0:d5bb9a9c3e24 262 csw.Status = (memOK && (stage == PROCESS_CBW)) ? CSW_PASSED : CSW_FAILED;
sherckuith 0:d5bb9a9c3e24 263 sendCSW();
sherckuith 0:d5bb9a9c3e24 264 }
sherckuith 0:d5bb9a9c3e24 265 }
sherckuith 0:d5bb9a9c3e24 266
sherckuith 0:d5bb9a9c3e24 267
sherckuith 0:d5bb9a9c3e24 268 bool USBMSD::inquiryRequest (void) {
sherckuith 0:d5bb9a9c3e24 269 uint8_t inquiry[] = { 0x00, 0x80, 0x00, 0x01,
sherckuith 0:d5bb9a9c3e24 270 36 - 4, 0x80, 0x00, 0x00,
sherckuith 0:d5bb9a9c3e24 271 'M', 'B', 'E', 'D', '.', 'O', 'R', 'G',
sherckuith 0:d5bb9a9c3e24 272 'M', 'B', 'E', 'D', ' ', 'U', 'S', 'B', ' ', 'D', 'I', 'S', 'K', ' ', ' ', ' ',
sherckuith 0:d5bb9a9c3e24 273 '1', '.', '0', ' ',
sherckuith 0:d5bb9a9c3e24 274 };
sherckuith 0:d5bb9a9c3e24 275 if (!write(inquiry, sizeof(inquiry))) {
sherckuith 0:d5bb9a9c3e24 276 return false;
sherckuith 0:d5bb9a9c3e24 277 }
sherckuith 0:d5bb9a9c3e24 278 return true;
sherckuith 0:d5bb9a9c3e24 279 }
sherckuith 0:d5bb9a9c3e24 280
sherckuith 0:d5bb9a9c3e24 281
sherckuith 0:d5bb9a9c3e24 282 bool USBMSD::readFormatCapacity() {
sherckuith 0:d5bb9a9c3e24 283 uint8_t capacity[] = { 0x00, 0x00, 0x00, 0x08,
sherckuith 0:d5bb9a9c3e24 284 (BlockCount >> 24) & 0xff,
sherckuith 0:d5bb9a9c3e24 285 (BlockCount >> 16) & 0xff,
sherckuith 0:d5bb9a9c3e24 286 (BlockCount >> 8) & 0xff,
sherckuith 0:d5bb9a9c3e24 287 (BlockCount >> 0) & 0xff,
sherckuith 0:d5bb9a9c3e24 288
sherckuith 0:d5bb9a9c3e24 289 0x02,
sherckuith 0:d5bb9a9c3e24 290 (BlockSize >> 16) & 0xff,
sherckuith 0:d5bb9a9c3e24 291 (BlockSize >> 8) & 0xff,
sherckuith 0:d5bb9a9c3e24 292 (BlockSize >> 0) & 0xff,
sherckuith 0:d5bb9a9c3e24 293 };
sherckuith 0:d5bb9a9c3e24 294 if (!write(capacity, sizeof(capacity))) {
sherckuith 0:d5bb9a9c3e24 295 return false;
sherckuith 0:d5bb9a9c3e24 296 }
sherckuith 0:d5bb9a9c3e24 297 return true;
sherckuith 0:d5bb9a9c3e24 298 }
sherckuith 0:d5bb9a9c3e24 299
sherckuith 0:d5bb9a9c3e24 300
sherckuith 0:d5bb9a9c3e24 301 bool USBMSD::readCapacity (void) {
sherckuith 0:d5bb9a9c3e24 302 uint8_t capacity[] = {
sherckuith 0:d5bb9a9c3e24 303 ((BlockCount - 1) >> 24) & 0xff,
sherckuith 0:d5bb9a9c3e24 304 ((BlockCount - 1) >> 16) & 0xff,
sherckuith 0:d5bb9a9c3e24 305 ((BlockCount - 1) >> 8) & 0xff,
sherckuith 0:d5bb9a9c3e24 306 ((BlockCount - 1) >> 0) & 0xff,
sherckuith 0:d5bb9a9c3e24 307
sherckuith 0:d5bb9a9c3e24 308 (BlockSize >> 24) & 0xff,
sherckuith 0:d5bb9a9c3e24 309 (BlockSize >> 16) & 0xff,
sherckuith 0:d5bb9a9c3e24 310 (BlockSize >> 8) & 0xff,
sherckuith 0:d5bb9a9c3e24 311 (BlockSize >> 0) & 0xff,
sherckuith 0:d5bb9a9c3e24 312 };
sherckuith 0:d5bb9a9c3e24 313 if (!write(capacity, sizeof(capacity))) {
sherckuith 0:d5bb9a9c3e24 314 return false;
sherckuith 0:d5bb9a9c3e24 315 }
sherckuith 0:d5bb9a9c3e24 316 return true;
sherckuith 0:d5bb9a9c3e24 317 }
sherckuith 0:d5bb9a9c3e24 318
sherckuith 0:d5bb9a9c3e24 319 bool USBMSD::write (uint8_t * buf, uint16_t size) {
sherckuith 0:d5bb9a9c3e24 320
sherckuith 0:d5bb9a9c3e24 321 if (size >= cbw.DataLength) {
sherckuith 0:d5bb9a9c3e24 322 size = cbw.DataLength;
sherckuith 0:d5bb9a9c3e24 323 }
sherckuith 0:d5bb9a9c3e24 324 stage = SEND_CSW;
sherckuith 0:d5bb9a9c3e24 325
sherckuith 0:d5bb9a9c3e24 326 if (!writeNB(EPBULK_IN, buf, size, MAX_PACKET_SIZE_EPBULK)) {
sherckuith 0:d5bb9a9c3e24 327 return false;
sherckuith 0:d5bb9a9c3e24 328 }
sherckuith 0:d5bb9a9c3e24 329
sherckuith 0:d5bb9a9c3e24 330 csw.DataResidue -= size;
sherckuith 0:d5bb9a9c3e24 331 csw.Status = CSW_PASSED;
sherckuith 0:d5bb9a9c3e24 332 return true;
sherckuith 0:d5bb9a9c3e24 333 }
sherckuith 0:d5bb9a9c3e24 334
sherckuith 0:d5bb9a9c3e24 335
sherckuith 0:d5bb9a9c3e24 336 bool USBMSD::modeSense6 (void) {
sherckuith 0:d5bb9a9c3e24 337 uint8_t sense6[] = { 0x03, 0x00, 0x00, 0x00 };
sherckuith 0:d5bb9a9c3e24 338 if (!write(sense6, sizeof(sense6))) {
sherckuith 0:d5bb9a9c3e24 339 return false;
sherckuith 0:d5bb9a9c3e24 340 }
sherckuith 0:d5bb9a9c3e24 341 return true;
sherckuith 0:d5bb9a9c3e24 342 }
sherckuith 0:d5bb9a9c3e24 343
sherckuith 0:d5bb9a9c3e24 344 void USBMSD::sendCSW() {
sherckuith 0:d5bb9a9c3e24 345 csw.Signature = CSW_Signature;
sherckuith 0:d5bb9a9c3e24 346 writeNB(EPBULK_IN, (uint8_t *)&csw, sizeof(CSW), MAX_PACKET_SIZE_EPBULK);
sherckuith 0:d5bb9a9c3e24 347 stage = WAIT_CSW;
sherckuith 0:d5bb9a9c3e24 348 }
sherckuith 0:d5bb9a9c3e24 349
sherckuith 0:d5bb9a9c3e24 350 bool USBMSD::requestSense (void) {
sherckuith 0:d5bb9a9c3e24 351 uint8_t request_sense[] = {
sherckuith 0:d5bb9a9c3e24 352 0x70,
sherckuith 0:d5bb9a9c3e24 353 0x00,
sherckuith 0:d5bb9a9c3e24 354 0x05, // Sense Key: illegal request
sherckuith 0:d5bb9a9c3e24 355 0x00,
sherckuith 0:d5bb9a9c3e24 356 0x00,
sherckuith 0:d5bb9a9c3e24 357 0x00,
sherckuith 0:d5bb9a9c3e24 358 0x00,
sherckuith 0:d5bb9a9c3e24 359 0x0A,
sherckuith 0:d5bb9a9c3e24 360 0x00,
sherckuith 0:d5bb9a9c3e24 361 0x00,
sherckuith 0:d5bb9a9c3e24 362 0x00,
sherckuith 0:d5bb9a9c3e24 363 0x00,
sherckuith 0:d5bb9a9c3e24 364 0x30,
sherckuith 0:d5bb9a9c3e24 365 0x01,
sherckuith 0:d5bb9a9c3e24 366 0x00,
sherckuith 0:d5bb9a9c3e24 367 0x00,
sherckuith 0:d5bb9a9c3e24 368 0x00,
sherckuith 0:d5bb9a9c3e24 369 0x00,
sherckuith 0:d5bb9a9c3e24 370 };
sherckuith 0:d5bb9a9c3e24 371
sherckuith 0:d5bb9a9c3e24 372 if (!write(request_sense, sizeof(request_sense))) {
sherckuith 0:d5bb9a9c3e24 373 return false;
sherckuith 0:d5bb9a9c3e24 374 }
sherckuith 0:d5bb9a9c3e24 375
sherckuith 0:d5bb9a9c3e24 376 return true;
sherckuith 0:d5bb9a9c3e24 377 }
sherckuith 0:d5bb9a9c3e24 378
sherckuith 0:d5bb9a9c3e24 379 void USBMSD::fail() {
sherckuith 0:d5bb9a9c3e24 380 csw.Status = CSW_FAILED;
sherckuith 0:d5bb9a9c3e24 381 sendCSW();
sherckuith 0:d5bb9a9c3e24 382 }
sherckuith 0:d5bb9a9c3e24 383
sherckuith 0:d5bb9a9c3e24 384
sherckuith 0:d5bb9a9c3e24 385 void USBMSD::CBWDecode(uint8_t * buf, uint16_t size) {
sherckuith 0:d5bb9a9c3e24 386 if (size == sizeof(cbw)) {
sherckuith 0:d5bb9a9c3e24 387 memcpy((uint8_t *)&cbw, buf, size);
sherckuith 0:d5bb9a9c3e24 388 if (cbw.Signature == CBW_Signature) {
sherckuith 0:d5bb9a9c3e24 389 csw.Tag = cbw.Tag;
sherckuith 0:d5bb9a9c3e24 390 csw.DataResidue = cbw.DataLength;
sherckuith 0:d5bb9a9c3e24 391 if ((cbw.CBLength < 1) || (cbw.CBLength > 16) ) {
sherckuith 0:d5bb9a9c3e24 392 fail();
sherckuith 0:d5bb9a9c3e24 393 } else {
sherckuith 0:d5bb9a9c3e24 394 switch (cbw.CB[0]) {
sherckuith 0:d5bb9a9c3e24 395 case TEST_UNIT_READY:
sherckuith 0:d5bb9a9c3e24 396 testUnitReady();
sherckuith 0:d5bb9a9c3e24 397 break;
sherckuith 0:d5bb9a9c3e24 398 case REQUEST_SENSE:
sherckuith 0:d5bb9a9c3e24 399 requestSense();
sherckuith 0:d5bb9a9c3e24 400 break;
sherckuith 0:d5bb9a9c3e24 401 case INQUIRY:
sherckuith 0:d5bb9a9c3e24 402 inquiryRequest();
sherckuith 0:d5bb9a9c3e24 403 break;
sherckuith 0:d5bb9a9c3e24 404 case MODE_SENSE6:
sherckuith 0:d5bb9a9c3e24 405 modeSense6();
sherckuith 0:d5bb9a9c3e24 406 break;
sherckuith 0:d5bb9a9c3e24 407 case READ_FORMAT_CAPACITIES:
sherckuith 0:d5bb9a9c3e24 408 readFormatCapacity();
sherckuith 0:d5bb9a9c3e24 409 break;
sherckuith 0:d5bb9a9c3e24 410 case READ_CAPACITY:
sherckuith 0:d5bb9a9c3e24 411 readCapacity();
sherckuith 0:d5bb9a9c3e24 412 break;
sherckuith 0:d5bb9a9c3e24 413 case READ10:
sherckuith 0:d5bb9a9c3e24 414 case READ12:
sherckuith 0:d5bb9a9c3e24 415 if (infoTransfer()) {
sherckuith 0:d5bb9a9c3e24 416 if ((cbw.Flags & 0x80)) {
sherckuith 0:d5bb9a9c3e24 417 stage = PROCESS_CBW;
sherckuith 0:d5bb9a9c3e24 418 memoryRead();
sherckuith 0:d5bb9a9c3e24 419 } else {
sherckuith 0:d5bb9a9c3e24 420 stallEndpoint(EPBULK_OUT);
sherckuith 0:d5bb9a9c3e24 421 csw.Status = CSW_ERROR;
sherckuith 0:d5bb9a9c3e24 422 sendCSW();
sherckuith 0:d5bb9a9c3e24 423 }
sherckuith 0:d5bb9a9c3e24 424 }
sherckuith 0:d5bb9a9c3e24 425 break;
sherckuith 0:d5bb9a9c3e24 426 case WRITE10:
sherckuith 0:d5bb9a9c3e24 427 case WRITE12:
sherckuith 0:d5bb9a9c3e24 428 if (infoTransfer()) {
sherckuith 0:d5bb9a9c3e24 429 if (!(cbw.Flags & 0x80)) {
sherckuith 0:d5bb9a9c3e24 430 stage = PROCESS_CBW;
sherckuith 0:d5bb9a9c3e24 431 } else {
sherckuith 0:d5bb9a9c3e24 432 stallEndpoint(EPBULK_IN);
sherckuith 0:d5bb9a9c3e24 433 csw.Status = CSW_ERROR;
sherckuith 0:d5bb9a9c3e24 434 sendCSW();
sherckuith 0:d5bb9a9c3e24 435 }
sherckuith 0:d5bb9a9c3e24 436 }
sherckuith 0:d5bb9a9c3e24 437 break;
sherckuith 0:d5bb9a9c3e24 438 case VERIFY10:
sherckuith 0:d5bb9a9c3e24 439 if (!(cbw.CB[1] & 0x02)) {
sherckuith 0:d5bb9a9c3e24 440 csw.Status = CSW_PASSED;
sherckuith 0:d5bb9a9c3e24 441 sendCSW();
sherckuith 0:d5bb9a9c3e24 442 break;
sherckuith 0:d5bb9a9c3e24 443 }
sherckuith 0:d5bb9a9c3e24 444 if (infoTransfer()) {
sherckuith 0:d5bb9a9c3e24 445 if (!(cbw.Flags & 0x80)) {
sherckuith 0:d5bb9a9c3e24 446 stage = PROCESS_CBW;
sherckuith 0:d5bb9a9c3e24 447 memOK = true;
sherckuith 0:d5bb9a9c3e24 448 } else {
sherckuith 0:d5bb9a9c3e24 449 stallEndpoint(EPBULK_IN);
sherckuith 0:d5bb9a9c3e24 450 csw.Status = CSW_ERROR;
sherckuith 0:d5bb9a9c3e24 451 sendCSW();
sherckuith 0:d5bb9a9c3e24 452 }
sherckuith 0:d5bb9a9c3e24 453 }
sherckuith 0:d5bb9a9c3e24 454 break;
sherckuith 0:d5bb9a9c3e24 455 default:
sherckuith 0:d5bb9a9c3e24 456 fail();
sherckuith 0:d5bb9a9c3e24 457 break;
sherckuith 0:d5bb9a9c3e24 458 }
sherckuith 0:d5bb9a9c3e24 459 }
sherckuith 0:d5bb9a9c3e24 460 }
sherckuith 0:d5bb9a9c3e24 461 }
sherckuith 0:d5bb9a9c3e24 462 }
sherckuith 0:d5bb9a9c3e24 463
sherckuith 0:d5bb9a9c3e24 464 void USBMSD::testUnitReady (void) {
sherckuith 0:d5bb9a9c3e24 465
sherckuith 0:d5bb9a9c3e24 466 if (cbw.DataLength != 0) {
sherckuith 0:d5bb9a9c3e24 467 if ((cbw.Flags & 0x80) != 0) {
sherckuith 0:d5bb9a9c3e24 468 stallEndpoint(EPBULK_IN);
sherckuith 0:d5bb9a9c3e24 469 } else {
sherckuith 0:d5bb9a9c3e24 470 stallEndpoint(EPBULK_OUT);
sherckuith 0:d5bb9a9c3e24 471 }
sherckuith 0:d5bb9a9c3e24 472 }
sherckuith 0:d5bb9a9c3e24 473
sherckuith 0:d5bb9a9c3e24 474 csw.Status = CSW_PASSED;
sherckuith 0:d5bb9a9c3e24 475 sendCSW();
sherckuith 0:d5bb9a9c3e24 476 }
sherckuith 0:d5bb9a9c3e24 477
sherckuith 0:d5bb9a9c3e24 478
sherckuith 0:d5bb9a9c3e24 479 void USBMSD::memoryRead (void) {
sherckuith 0:d5bb9a9c3e24 480 uint32_t n;
sherckuith 0:d5bb9a9c3e24 481
sherckuith 0:d5bb9a9c3e24 482 n = (length > MAX_PACKET) ? MAX_PACKET : length;
sherckuith 0:d5bb9a9c3e24 483
sherckuith 0:d5bb9a9c3e24 484 if ((addr + n) > MemorySize) {
sherckuith 0:d5bb9a9c3e24 485 n = MemorySize - addr;
sherckuith 0:d5bb9a9c3e24 486 stage = ERROR;
sherckuith 0:d5bb9a9c3e24 487 }
sherckuith 0:d5bb9a9c3e24 488
sherckuith 0:d5bb9a9c3e24 489 // we read an entire block
sherckuith 0:d5bb9a9c3e24 490 if (!(addr%BlockSize))
sherckuith 0:d5bb9a9c3e24 491 disk_read((char *)page, addr/BlockSize);
sherckuith 0:d5bb9a9c3e24 492
sherckuith 0:d5bb9a9c3e24 493 // write data which are in RAM
sherckuith 0:d5bb9a9c3e24 494 writeNB(EPBULK_IN, &page[addr%BlockSize], n, MAX_PACKET_SIZE_EPBULK);
sherckuith 0:d5bb9a9c3e24 495
sherckuith 0:d5bb9a9c3e24 496 addr += n;
sherckuith 0:d5bb9a9c3e24 497 length -= n;
sherckuith 0:d5bb9a9c3e24 498
sherckuith 0:d5bb9a9c3e24 499 csw.DataResidue -= n;
sherckuith 0:d5bb9a9c3e24 500
sherckuith 0:d5bb9a9c3e24 501 if ( !length || (stage != PROCESS_CBW)) {
sherckuith 0:d5bb9a9c3e24 502 csw.Status = (stage == PROCESS_CBW) ? CSW_PASSED : CSW_FAILED;
sherckuith 0:d5bb9a9c3e24 503 stage = (stage == PROCESS_CBW) ? SEND_CSW : stage;
sherckuith 0:d5bb9a9c3e24 504 }
sherckuith 0:d5bb9a9c3e24 505 }
sherckuith 0:d5bb9a9c3e24 506
sherckuith 0:d5bb9a9c3e24 507
sherckuith 0:d5bb9a9c3e24 508 bool USBMSD::infoTransfer (void) {
sherckuith 0:d5bb9a9c3e24 509 uint32_t n;
sherckuith 0:d5bb9a9c3e24 510
sherckuith 0:d5bb9a9c3e24 511 // Logical Block Address of First Block
sherckuith 0:d5bb9a9c3e24 512 n = (cbw.CB[2] << 24) | (cbw.CB[3] << 16) | (cbw.CB[4] << 8) | (cbw.CB[5] << 0);
sherckuith 0:d5bb9a9c3e24 513
sherckuith 0:d5bb9a9c3e24 514 addr = n * BlockSize;
sherckuith 0:d5bb9a9c3e24 515
sherckuith 0:d5bb9a9c3e24 516 // Number of Blocks to transfer
sherckuith 0:d5bb9a9c3e24 517 switch (cbw.CB[0]) {
sherckuith 0:d5bb9a9c3e24 518 case READ10:
sherckuith 0:d5bb9a9c3e24 519 case WRITE10:
sherckuith 0:d5bb9a9c3e24 520 case VERIFY10:
sherckuith 0:d5bb9a9c3e24 521 n = (cbw.CB[7] << 8) | (cbw.CB[8] << 0);
sherckuith 0:d5bb9a9c3e24 522 break;
sherckuith 0:d5bb9a9c3e24 523
sherckuith 0:d5bb9a9c3e24 524 case READ12:
sherckuith 0:d5bb9a9c3e24 525 case WRITE12:
sherckuith 0:d5bb9a9c3e24 526 n = (cbw.CB[6] << 24) | (cbw.CB[7] << 16) | (cbw.CB[8] << 8) | (cbw.CB[9] << 0);
sherckuith 0:d5bb9a9c3e24 527 break;
sherckuith 0:d5bb9a9c3e24 528 }
sherckuith 0:d5bb9a9c3e24 529
sherckuith 0:d5bb9a9c3e24 530 length = n * BlockSize;
sherckuith 0:d5bb9a9c3e24 531
sherckuith 0:d5bb9a9c3e24 532 if (!cbw.DataLength) { // host requests no data
sherckuith 0:d5bb9a9c3e24 533 csw.Status = CSW_FAILED;
sherckuith 0:d5bb9a9c3e24 534 sendCSW();
sherckuith 0:d5bb9a9c3e24 535 return false;
sherckuith 0:d5bb9a9c3e24 536 }
sherckuith 0:d5bb9a9c3e24 537
sherckuith 0:d5bb9a9c3e24 538 if (cbw.DataLength != length) {
sherckuith 0:d5bb9a9c3e24 539 if ((cbw.Flags & 0x80) != 0) {
sherckuith 0:d5bb9a9c3e24 540 stallEndpoint(EPBULK_IN);
sherckuith 0:d5bb9a9c3e24 541 } else {
sherckuith 0:d5bb9a9c3e24 542 stallEndpoint(EPBULK_OUT);
sherckuith 0:d5bb9a9c3e24 543 }
sherckuith 0:d5bb9a9c3e24 544
sherckuith 0:d5bb9a9c3e24 545 csw.Status = CSW_FAILED;
sherckuith 0:d5bb9a9c3e24 546 sendCSW();
sherckuith 0:d5bb9a9c3e24 547 return false;
sherckuith 0:d5bb9a9c3e24 548 }
sherckuith 0:d5bb9a9c3e24 549
sherckuith 0:d5bb9a9c3e24 550 return true;
sherckuith 0:d5bb9a9c3e24 551 }
sherckuith 0:d5bb9a9c3e24 552
sherckuith 0:d5bb9a9c3e24 553
sherckuith 0:d5bb9a9c3e24 554
sherckuith 0:d5bb9a9c3e24 555
sherckuith 0:d5bb9a9c3e24 556
sherckuith 0:d5bb9a9c3e24 557 // Called in ISR context
sherckuith 0:d5bb9a9c3e24 558 // Set configuration. Return false if the
sherckuith 0:d5bb9a9c3e24 559 // configuration is not supported.
sherckuith 0:d5bb9a9c3e24 560 bool USBMSD::USBCallback_setConfiguration(uint8_t configuration) {
sherckuith 0:d5bb9a9c3e24 561 if (configuration != DEFAULT_CONFIGURATION) {
sherckuith 0:d5bb9a9c3e24 562 return false;
sherckuith 0:d5bb9a9c3e24 563 }
sherckuith 0:d5bb9a9c3e24 564
sherckuith 0:d5bb9a9c3e24 565 // Configure endpoints > 0
sherckuith 0:d5bb9a9c3e24 566 addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPBULK);
sherckuith 0:d5bb9a9c3e24 567 addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
sherckuith 0:d5bb9a9c3e24 568
sherckuith 0:d5bb9a9c3e24 569 //activate readings
sherckuith 0:d5bb9a9c3e24 570 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
sherckuith 0:d5bb9a9c3e24 571 return true;
sherckuith 0:d5bb9a9c3e24 572 }
sherckuith 0:d5bb9a9c3e24 573
sherckuith 0:d5bb9a9c3e24 574
sherckuith 0:d5bb9a9c3e24 575 uint8_t * USBMSD::stringIinterfaceDesc() {
sherckuith 0:d5bb9a9c3e24 576 static uint8_t stringIinterfaceDescriptor[] = {
sherckuith 0:d5bb9a9c3e24 577 0x08, //bLength
sherckuith 0:d5bb9a9c3e24 578 STRING_DESCRIPTOR, //bDescriptorType 0x03
sherckuith 0:d5bb9a9c3e24 579 'M',0,'S',0,'D',0 //bString iInterface - MSD
sherckuith 0:d5bb9a9c3e24 580 };
sherckuith 0:d5bb9a9c3e24 581 return stringIinterfaceDescriptor;
sherckuith 0:d5bb9a9c3e24 582 }
sherckuith 0:d5bb9a9c3e24 583
sherckuith 0:d5bb9a9c3e24 584 uint8_t * USBMSD::stringIproductDesc() {
sherckuith 0:d5bb9a9c3e24 585 static uint8_t stringIproductDescriptor[] = {
sherckuith 0:d5bb9a9c3e24 586 0x12, //bLength
sherckuith 0:d5bb9a9c3e24 587 STRING_DESCRIPTOR, //bDescriptorType 0x03
sherckuith 0:d5bb9a9c3e24 588 'M',0,'b',0,'e',0,'d',0,' ',0,'M',0,'S',0,'D',0 //bString iProduct - Mbed Audio
sherckuith 0:d5bb9a9c3e24 589 };
sherckuith 0:d5bb9a9c3e24 590 return stringIproductDescriptor;
sherckuith 0:d5bb9a9c3e24 591 }
sherckuith 0:d5bb9a9c3e24 592
sherckuith 0:d5bb9a9c3e24 593
sherckuith 0:d5bb9a9c3e24 594 uint8_t * USBMSD::configurationDesc() {
sherckuith 0:d5bb9a9c3e24 595 static uint8_t configDescriptor[] = {
sherckuith 0:d5bb9a9c3e24 596
sherckuith 0:d5bb9a9c3e24 597 // Configuration 1
sherckuith 0:d5bb9a9c3e24 598 9, // bLength
sherckuith 0:d5bb9a9c3e24 599 2, // bDescriptorType
sherckuith 0:d5bb9a9c3e24 600 LSB(9 + 9 + 7 + 7), // wTotalLength
sherckuith 0:d5bb9a9c3e24 601 MSB(9 + 9 + 7 + 7),
sherckuith 0:d5bb9a9c3e24 602 0x01, // bNumInterfaces
sherckuith 0:d5bb9a9c3e24 603 0x01, // bConfigurationValue: 0x01 is used to select this configuration
sherckuith 0:d5bb9a9c3e24 604 0x00, // iConfiguration: no string to describe this configuration
sherckuith 0:d5bb9a9c3e24 605 0xC0, // bmAttributes
sherckuith 0:d5bb9a9c3e24 606 100, // bMaxPower, device power consumption is 100 mA
sherckuith 0:d5bb9a9c3e24 607
sherckuith 0:d5bb9a9c3e24 608 // Interface 0, Alternate Setting 0, MSC Class
sherckuith 0:d5bb9a9c3e24 609 9, // bLength
sherckuith 0:d5bb9a9c3e24 610 4, // bDescriptorType
sherckuith 0:d5bb9a9c3e24 611 0x00, // bInterfaceNumber
sherckuith 0:d5bb9a9c3e24 612 0x00, // bAlternateSetting
sherckuith 0:d5bb9a9c3e24 613 0x02, // bNumEndpoints
sherckuith 0:d5bb9a9c3e24 614 0x08, // bInterfaceClass
sherckuith 0:d5bb9a9c3e24 615 0x06, // bInterfaceSubClass
sherckuith 0:d5bb9a9c3e24 616 0x50, // bInterfaceProtocol
sherckuith 0:d5bb9a9c3e24 617 0x04, // iInterface
sherckuith 0:d5bb9a9c3e24 618
sherckuith 0:d5bb9a9c3e24 619 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
sherckuith 0:d5bb9a9c3e24 620 7, // bLength
sherckuith 0:d5bb9a9c3e24 621 5, // bDescriptorType
sherckuith 0:d5bb9a9c3e24 622 PHY_TO_DESC(EPBULK_IN), // bEndpointAddress
sherckuith 0:d5bb9a9c3e24 623 0x02, // bmAttributes (0x02=bulk)
sherckuith 0:d5bb9a9c3e24 624 LSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (LSB)
sherckuith 0:d5bb9a9c3e24 625 MSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (MSB)
sherckuith 0:d5bb9a9c3e24 626 0, // bInterval
sherckuith 0:d5bb9a9c3e24 627
sherckuith 0:d5bb9a9c3e24 628 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
sherckuith 0:d5bb9a9c3e24 629 7, // bLength
sherckuith 0:d5bb9a9c3e24 630 5, // bDescriptorType
sherckuith 0:d5bb9a9c3e24 631 PHY_TO_DESC(EPBULK_OUT), // bEndpointAddress
sherckuith 0:d5bb9a9c3e24 632 0x02, // bmAttributes (0x02=bulk)
sherckuith 0:d5bb9a9c3e24 633 LSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (LSB)
sherckuith 0:d5bb9a9c3e24 634 MSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (MSB)
sherckuith 0:d5bb9a9c3e24 635 0 // bInterval
sherckuith 0:d5bb9a9c3e24 636 };
sherckuith 0:d5bb9a9c3e24 637 return configDescriptor;
sherckuith 0:d5bb9a9c3e24 638 }