USBHost_t36 USB Mass Storage Driver Experiments

@KurtE

Can you? I managed to get CANFD have working - I can transmit a message from the T4 to the EVK now and I want to see whats going on with receive. I found the problem that was driving me crazy. Going to post that one on the T4 thread. Hoping to get it working today so I can go on to other distractions :)
 
...
Code:
(Here we ask for the media ready)
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 35 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 


(Response - ends with 01 - fail)
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 35 00 00 00 00 00 00 00 01 
** CSWSIGNATURE

(Now ask for request sense)
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 36 00 00 00 12 00 00 00 80 00 06 03 00 00 00 12 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0

(response of sense)
msController dataIn (static): 18
70 00 02 00 00 00 00 0A 00 00 00 00 3A 00 00 00 00 00 
** ????
msDoCommand after msOutCompleted loop
msDoCommand after msInCompleted loop
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 36 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
(I had the waitMedia also dump out the response)...
WaitMediaReady RSP:70 00 02 00 00 00 00 0A 00 00 00 00 3A 00 

.... Repeats for ever or until I unplug

Now to look up what the response codes are...
Follow on to this...

Looking at the line: WaitMediaReady RSP:70 00 02 00 00 00 00 0A 00 00 00 00 3A 00
Looking at the structure returned, the interesting info is the 0x3A

Which from the site: http://www.t10.org/lists/asc-num.htm
Code:
3A/00  DZT ROM  BK    MEDIUM NOT PRESENT
3A/01  DZT ROM  BK    MEDIUM NOT PRESENT - TRAY CLOSED
3A/02  DZT ROM  BK    MEDIUM NOT PRESENT - TRAY OPEN
3A/03  DZT ROM  B     MEDIUM NOT PRESENT - LOADABLE
3A/04  DZT RO   B     MEDIUM NOT PRESENT - MEDIUM AUXILIARY MEMORY ACCESSIBLE
I believe the 0 after 3A is sub code here ... So simply "Medium not present"

And never is... ???

Wondering many of these commands have logical unit number and we always pass 0... Wonder if some of these devices have more than 1? and media on different one???
 
@KurtE

Can you? I managed to get CANFD have working - I can transmit a message from the T4 to the EVK now and I want to see whats going on with receive. I found the problem that was driving me crazy. Going to post that one on the T4 thread. Hoping to get it working today so I can go on to other distractions :)
Sounds good, I posted possible code for you try in previous posting (previous page)
 
@KurtE
Looks like your modified claim code worked for my memory stick to make a long story short. This is what I am now seeing:
Code:
Test Drive Inquiry with uSDFS
Waiting For Device: 2:/
USB2 PLL running
 reset waited 6
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 20004000
periodictable = 20004000
port change: 10001803
    connect
  begin reset
port change: 18001205
  port enabled
  end recovery
new_Device: 480 Mbit/sec
new_Pipe
enumeration:
enumeration:
enumeration:
Device Descriptor:
  12 01 00 02 00 00 00 40 07 13 63 01 00 01 01 02 03 01 
    VendorID = 1307, ProductID = 0163, Version = 0100
    Class/Subclass/Protocol = 0 / 0 / 0
    Number of Configurations = 1
enumeration:
enumeration:
Manufacturer: USB 2.0
enumeration:
Product: Flash Disk
enumeration:
Serial Number: 0ee644744fd53c
enumeration:
Config data length = 39
enumeration:
Configuration Descriptor:
  09 02 27 00 01 01 00 80 28 
    NumInterfaces = 1
    ConfigurationValue = 1
  09 04 00 00 03 08 06 50 00 
    Interface = 0
    Number of endpoints = 3
    Class/Subclass/Protocol = 8(Mass Storage) / 6(SCSI) / 80(Bulk Only)
  07 05 01 02 00 02 01 
    Endpoint = 1 OUT
    Type = Bulk
    Max Size = 512
    Polling Interval = 1
  07 05 82 02 00 02 01 
    Endpoint = 2 IN
    Type = Bulk
    Max Size = 512
    Polling Interval = 1
  07 05 83 03 40 00 08 
    Endpoint = 3 IN
    Type = Interrupt
    Max Size = 64
    Polling Interval = 8
enumeration:
msController claim this=20002F00
Descriptor 4 = INTERFACE
msController claim this=20002F00
09 04 00 00 03 08 06 50 00 07 05 01 02 00 02 01 07 05 82 02 00 02 01 07 05 83 03 40 00 08 
numendpoint=3
endpointIn=82
endpointOut=1
packet size in (msController) = 512
packet size out (msController) = 512
polling intervalIn = 1
polling intervalOut = 1
new_Pipe
new_Pipe
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 02 00 00 00 00 00 00 00 80 00 06 1B 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 02 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 03 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 03 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 04 00 00 00 24 00 00 00 80 00 06 12 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 36
00 80 02 02 1F 00 00 00 55 53 42 20 32 2E 30 20 46 6C 61 73 68 20 44 69 73 6B 20 20 20 20 20 20 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 04 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 05 00 00 00 08 00 00 00 80 00 0A 25 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 8
00 1E 1F FE 00 00 02 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 05 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 06 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 06 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 07 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 512
33 C0 8E D0 BC 00 7C FB 50 07 50 1F FC BE 1B 7C BF 1B 06 50 57 B9 E5 01 F3 A4 CB BD BE 07 B1 04 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 07 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 08 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 08 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 09 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 00 3F 00 00 01 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 512
EB 58 90 4D 53 44 4F 53 35 2E 30 00 02 08 00 11 02 00 00 00 00 F8 00 00 3F 00 FF 00 3F 00 00 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 09 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 0A 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 0A 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 0B 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 00 40 00 00 01 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 512
52 52 61 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 0B 00 00 00 00 00 00 00 00 
** CSWSIGNATURE

Change drive

Do Device Inquiry
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 0C 00 00 00 24 00 00 00 80 00 06 12 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 36
00 80 02 02 1F 00 00 00 55 53 42 20 32 2E 30 20 46 6C 61 73 68 20 44 69 73 6B 20 20 20 20 20 20 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 0C 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
Removable Device: YES
        VendorID: USB 2.0 
       ProductID: Flash Disk      
      RevisionID: 0.00

Get Device Capacity Specs
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 0D 00 00 00 08 00 00 00 80 00 0A 25 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 8
00 1E 1F FE 00 00 02 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 0D 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
    Sector Count: 1974270
     Sector size: 512
   Disk Capacity: 1974270 * 512 Bytes

Device Inquiry Test Finished.
 
@KurtE and others
Tried the SSD drive again and now get a failed with RC=13, figured I would just give it a try:
Code:
Test Drive Inquiry with uSDFS
Waiting For Device: 2:/
USB2 PLL running
 reset waited 6
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 20004000
periodictable = 20004000
port change: 10001803
    connect
  begin reset
port change: 18001205
  port enabled
  end recovery
new_Device: 480 Mbit/sec
new_Pipe
enumeration:
enumeration:
enumeration:
Device Descriptor:
  12 01 10 02 00 00 00 40 2D 15 78 05 09 05 01 02 03 01 
    VendorID = 152D, ProductID = 0578, Version = 0509
    Class/Subclass/Protocol = 0 / 0 / 0
    Number of Configurations = 1
enumeration:
enumeration:
Manufacturer: JMicron
enumeration:
Product: External USB 3.0
enumeration:
Serial Number: 0123456789CB
enumeration:
Config data length = 85
enumeration:
Configuration Descriptor:
  09 02 55 00 01 01 00 80 FA 
    NumInterfaces = 1
    ConfigurationValue = 1
  09 04 00 00 02 08 06 50 00 
    Interface = 0
    Number of endpoints = 2
    Class/Subclass/Protocol = 8(Mass Storage) / 6(SCSI) / 80(Bulk Only)
  07 05 81 02 00 02 00 
    Endpoint = 1 IN
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  07 05 02 02 00 02 00 
    Endpoint = 2 OUT
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  09 04 00 01 04 08 06 62 00 
    Interface = 0
    Number of endpoints = 4
    Class/Subclass/Protocol = 8(Mass Storage) / 6(SCSI) / 98(UAS)
  07 05 01 02 00 02 00 
    Endpoint = 1 OUT
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  04 24 01 00 
  07 05 82 02 00 02 00 
    Endpoint = 2 IN
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  04 24 02 00 
  07 05 83 02 00 02 00 
    Endpoint = 3 IN
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  04 24 03 00 
  07 05 04 02 00 02 00 
    Endpoint = 4 OUT
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  04 24 04 00 
enumeration:
msController claim this=20002F00
Descriptor 4 = INTERFACE
msController claim this=20002F00
09 04 00 00 02 08 06 50 00 07 05 81 02 00 02 00 07 05 02 02 00 02 00 09 04 00 01 04 08 06 62 00 07 05 01 02 00 02 00 04 24 01 00 07 05 82 02 00 02 00 04 24 02 00 07 05 83 02 00 02 00 04 24 03 00 07 05 04 02 00 02 00 04 24 04 00 
numendpoint=2
endpointIn=81
endpointOut=2
packet size in (msController) = 512
packet size out (msController) = 512
polling intervalIn = 0
polling intervalOut = 0
new_Pipe
new_Pipe
[COLOR="#FF0000"]Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
Descriptor 5 = ENDPOINT
Descriptor 36 =  ???
Descriptor 5 = ENDPOINT
Descriptor 36 =  ???
Descriptor 5 = ENDPOINT
Descriptor 36 =  ???
Descriptor 5 = ENDPOINT
Descriptor 36 =  ???[/COLOR]
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 02 00 00 00 00 00 00 00 80 00 06 1B 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 02 00 00 00 00 00 00 00 01 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 03 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 03 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 04 00 00 00 24 00 00 00 80 00 06 12 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 36
00 00 06 12 5B 00 00 00 48 50 20 53 53 44 20 53 36 30 30 20 31 32 30 47 42 20 20 20 20 20 20 20 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 04 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 05 00 00 00 08 00 00 00 80 00 0A 25 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 8
0D F9 4B AF 00 00 02 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 05 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 06 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 06 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 07 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 512
33 C0 8E D0 BC 00 7C 8E C0 8E D8 BE 00 7C BF 00 06 B9 00 02 FC F3 A4 50 68 1C 06 CB FB B9 04 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 07 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 08 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 08 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 09 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 08 00 00 00 01 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 512
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 09 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
Mount: Failed with rc=13.
If you notice it has a descriptor that I don't think it knows about: Descriptor 36 = ???
 
@mjs513 and ...

Neither did I know about descriptor 0x24...

It is a class specific descriptor... Took me awhile to find: https://www.usb.org/sites/default/files/Mass_Storage_Specification_Overview_v1.4_2-19-2010.pdf]

24h Pipe Usage Class Specific DescriptorAllocated by USB-IF for UAS. UAS is defined outside of USB

As for your error code 13 - I believe that comes from ff.h
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */

I have not dug in that far yet to know how that is determined...
 
@KurtE
Interesting. I formatted to exFAT on the PC but it seems every time I run the example sketch using the drive it tells me I have to reformat when I hook it back up into the PC. Reformatting again as a double check will post update.
 
As for your error code 13 - I believe that comes from ff.h
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */

I have not dug in that far yet to know how that is determined...

You may wanted to try this sketch
Code:
#include "uSDFS.h"
#include "diskio.h"
/*
* for APL see http://elm-chan.org/fsw/ff/00index_e.html
*/
#define TEST_DRV 2
//
#if TEST_DRV == 0
  const char *Dev = "0:/";  // SPI
#elif TEST_DRV == 1
  const char *Dev = "1:/";  // SDHC
#elif TEST_DRV == 2
  const char *Dev = "2:/";  // USB
#endif

struct partitionTable {
  uint8_t  boot;
  uint8_t  beginHead;
  unsigned beginSector : 6;
  unsigned beginCylinderHigh : 2;
  uint8_t  beginCylinderLow;
  uint8_t  type;
  uint8_t  endHead;
  unsigned endSector : 6;
  unsigned endCylinderHigh : 2;
  uint8_t  endCylinderLow;
  uint32_t firstSector;
  uint32_t totalSectors;
} __attribute__((packed));
typedef struct partitionTable part_t;

struct masterBootRecord {
  uint8_t  codeArea[440];
  uint32_t diskSignature;
  uint16_t usuallyZero;
  part_t   part[4];
  uint8_t  mbrSig0;
  uint8_t  mbrSig1;
} __attribute__((packed));
typedef struct masterBootRecord mbr_t;

uint32_t buffer[128];
void setup() {
  // put your setup code here, to run once:

  while(!Serial);
  
  BYTE pdrv = TEST_DRV;
  
  DSTATUS stat = disk_initialize(TEST_DRV);
  Serial.print("Disk initialize Status: "); Serial.println(stat);

  BYTE* buff = (BYTE *) buffer;
  DWORD sector = 0;
  UINT count = 1;
  DRESULT res = disk_read (pdrv, buff, sector, count);
  Serial.print("Disk read Result: "); Serial.println(res);
  for(int ii=0;ii<512; ii++)
  if((ii+1)%16) Serial.printf("%02x ",buff[ii]); else Serial.printf("%02x\n",buff[ii]);

  mbr_t *mbr = (mbr_t *) buffer;
  Serial.println("\nMaster Boot Record");
  for(int ii=0;ii<4;ii++)
  {
    Serial.print("  Partition: "); Serial.print(ii);
    Serial.print(" first Sector: ");
    Serial.print(mbr->part[ii].firstSector);
    Serial.print(" total Sectors: ");
    Serial.println(mbr->part[ii].totalSectors);
  }
  pinMode(13,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWriteFast(13,!digitalReadFast(13));
  delay(1000);
}
it should give something like this
Code:
Disk initialize Status: 0
Disk read Result: 0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a
09 02 07 fe ff ff 00 80 00 00 00 78 f7 0e 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa

Master Boot Record
  Partition: 0 first Sector: 32768 total Sectors: 251099136
  Partition: 1 first Sector: 0 total Sectors: 0
  Partition: 2 first Sector: 0 total Sectors: 0
  Partition: 3 first Sector: 0 total Sectors: 0
 
@KurtE
Interesting. I formatted to exFAT on the PC but it seems every time I run the example sketch using the drive it tells me I have to reformat when I hook it back up into the PC. Reformatting again as a double check will post update.

It seems the Win10 Format does not anymore introduce MBR (which is used by ff.c)
you need official SD Formatter (see also my reply to @KurtE)
 
@WMXZ, @KurtE and @wwatson

Just ran the new test sketch (left the debugging stuff in) and do see the disk read and MBR:
Code:
USB2 PLL running
 reset waited 6
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 20003000
periodictable = 20003000
port change: 10001803
    connect
  begin reset
port change: 18001205
  port enabled
  end recovery
new_Device: 480 Mbit/sec
new_Pipe
enumeration:
enumeration:
enumeration:
Device Descriptor:
  12 01 10 02 00 00 00 40 2D 15 78 05 09 05 01 02 03 01 
    VendorID = 152D, ProductID = 0578, Version = 0509
    Class/Subclass/Protocol = 0 / 0 / 0
    Number of Configurations = 1
enumeration:
enumeration:
Manufacturer: JMicron
enumeration:
Product: External USB 3.0
enumeration:
Serial Number: 0123456789CB
enumeration:
Config data length = 85
enumeration:
Configuration Descriptor:
  09 02 55 00 01 01 00 80 FA 
    NumInterfaces = 1
    ConfigurationValue = 1
  09 04 00 00 02 08 06 50 00 
    Interface = 0
    Number of endpoints = 2
    Class/Subclass/Protocol = 8(Mass Storage) / 6(SCSI) / 80(Bulk Only)
  07 05 81 02 00 02 00 
    Endpoint = 1 IN
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  07 05 02 02 00 02 00 
    Endpoint = 2 OUT
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  09 04 00 01 04 08 06 62 00 
    Interface = 0
    Number of endpoints = 4
    Class/Subclass/Protocol = 8(Mass Storage) / 6(SCSI) / 98(UAS)
  07 05 01 02 00 02 00 
    Endpoint = 1 OUT
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  04 24 01 00 
  07 05 82 02 00 02 00 
    Endpoint = 2 IN
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  04 24 02 00 
  07 05 83 02 00 02 00 
    Endpoint = 3 IN
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  04 24 03 00 
  07 05 04 02 00 02 00 
    Endpoint = 4 OUT
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  04 24 04 00 
enumeration:
msController claim this=20002900
Descriptor 4 = INTERFACE
msController claim this=20002900
09 04 00 00 02 08 06 50 00 07 05 81 02 00 02 00 07 05 02 02 00 02 00 09 04 00 01 04 08 06 62 00 07 05 01 02 00 02 00 04 24 01 00 07 05 82 02 00 02 00 04 24 02 00 07 05 83 02 00 02 00 04 24 03 00 07 05 04 02 00 02 00 04 24 04 00 
numendpoint=2
endpointIn=81
endpointOut=2
packet size in (msController) = 512
packet size out (msController) = 512
polling intervalIn = 0
polling intervalOut = 0
new_Pipe
new_Pipe
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
Descriptor 4 = INTERFACE
Descriptor 5 = ENDPOINT
Descriptor 36 =  ???
Descriptor 5 = ENDPOINT
Descriptor 36 =  ???
Descriptor 5 = ENDPOINT
Descriptor 36 =  ???
Descriptor 5 = ENDPOINT
Descriptor 36 =  ???
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 02 00 00 00 00 00 00 00 80 00 06 1B 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 02 00 00 00 00 00 00 00 01 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 03 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 03 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 04 00 00 00 24 00 00 00 80 00 06 12 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 36
00 00 06 12 5B 00 00 00 48 50 20 53 53 44 20 53 36 30 30 20 31 32 30 47 42 20 20 20 20 20 20 20 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 04 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 05 00 00 00 08 00 00 00 80 00 0A 25 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 8
0D F9 4B AF 00 00 02 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 05 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
[COLOR="#FF0000"]Disk initialize Status: 0[/COLOR]
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 06 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 06 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 07 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 512
33 C0 8E D0 BC 00 7C 8E C0 8E D8 BE 00 7C BF 00 06 B9 00 02 FC F3 A4 50 68 1C 06 CB FB B9 04 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 07 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
[COLOR="#FF0000"]Disk read Result: 0[/COLOR]
33 c0 8e d0 bc 00 7c 8e c0 8e d8 be 00 7c bf 00
06 b9 00 02 fc f3 a4 50 68 1c 06 cb fb b9 04 00
bd be 07 80 7e 00 00 7c 0b 0f 85 0e 01 83 c5 10
e2 f1 cd 18 88 56 00 55 c6 46 11 05 c6 46 10 00
b4 41 bb aa 55 cd 13 5d 72 0f 81 fb 55 aa 75 09
f7 c1 01 00 74 03 fe 46 10 66 60 80 7e 10 00 74
26 66 68 00 00 00 00 66 ff 76 08 68 00 00 68 00
7c 68 01 00 68 10 00 b4 42 8a 56 00 8b f4 cd 13
9f 83 c4 10 9e eb 14 b8 01 02 bb 00 7c 8a 56 00
8a 76 01 8a 4e 02 8a 6e 03 cd 13 66 61 73 1c fe
4e 11 75 0c 80 7e 00 80 0f 84 8a 00 b2 80 eb 84
55 32 e4 8a 56 00 cd 13 5d eb 9e 81 3e fe 7d 55
aa 75 6e ff 76 00 e8 8d 00 75 17 fa b0 d1 e6 64
e8 83 00 b0 df e6 60 e8 7c 00 b0 ff e6 64 e8 75
00 fb b8 00 bb cd 1a 66 23 c0 75 3b 66 81 fb 54
43 50 41 75 32 81 f9 02 01 72 2c 66 68 07 bb 00
00 66 68 00 02 00 00 66 68 08 00 00 00 66 53 66
53 66 55 66 68 00 00 00 00 66 68 00 7c 00 00 66
61 68 00 00 07 cd 1a 5a 32 f6 ea 00 7c 00 00 cd
18 a0 b7 07 eb 08 a0 b6 07 eb 03 a0 b5 07 32 e4
05 00 07 8b f0 ac 3c 00 74 09 bb 07 00 b4 0e cd
10 eb f2 f4 eb fd 2b c9 e4 64 eb 00 24 02 e0 f8
24 02 c3 49 6e 76 61 6c 69 64 20 70 61 72 74 69
74 69 6f 6e 20 74 61 62 6c 65 00 45 72 72 6f 72
20 6c 6f 61 64 69 6e 67 20 6f 70 65 72 61 74 69
6e 67 20 73 79 73 74 65 6d 00 4d 69 73 73 69 6e
67 20 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74
65 6d 00 00 00 63 7b 9a 09 dc 4f 48 00 00 00 20
21 00 07 fe ff ff 00 08 00 00 00 38 f9 0d 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa

Master Boot Record
  Partition: 0 first Sector: 2048 total Sectors: 234436608
  Partition: 1 first Sector: 0 total Sectors: 0
  Partition: 2 first Sector: 0 total Sectors: 0
  Partition: 3 first Sector: 0 total Sectors: 0
So at least looks like it working at the diskio level, I think
 
@Kurte

Thanks for updating
Code:
bool msController::claim(Device_t *dev, int type, const uint8_t *descriptors, uint32_t len)
.

I have Targus Multi card reader which would not work with MSC. After applying your version I was able to read and write to various types of SD cards.

Awesome work. I cannot believe how fast you can figure out program this stuff.

Here is the output for the Multi card reader:

Code:
Test Drive Inquiry with uSDFS
Waiting For Device: 2:/
sizeof Device = 36
sizeof Pipe = 96
sizeof Transfer = 64
power up USBHS PHY
 reset waited 5
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 1FFF3000
periodictable = 1FFF3000
port change: 10001803
    connect
  begin reset
port change: 18001205
  port enabled
  end recovery
new_Device: 480 Mbit/sec
new_Pipe
enumeration:
enumeration:
enumeration:
Device Descriptor:
  12 01 00 02 00 00 00 40 8F 05 66 63 00 01 01 02 03 01 
    VendorID = 058F, ProductID = 6366, Version = 0100
    Class/Subclass/Protocol = 0 / 0 / 0
    Number of Configurations = 1
enumeration:
enumeration:
Manufacturer: Generic
enumeration:
Product: Mass Storage Device
enumeration:
Serial Number: 058F63666471
enumeration:
Config data length = 32
enumeration:
Configuration Descriptor:
  09 02 20 00 01 01 00 80 32 
    NumInterfaces = 1
    ConfigurationValue = 1
  09 04 00 00 02 08 06 50 00 
    Interface = 0
    Number of endpoints = 2
    Class/Subclass/Protocol = 8(Mass Storage) / 6(SCSI) / 80(Bulk Only)
  07 05 01 02 00 02 00 
    Endpoint = 1 OUT
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  07 05 82 02 00 02 00 
    Endpoint = 2 IN
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
enumeration:
msController claim this=1FFF2700
Descriptor 4 = INTERFACE
msController claim this=1FFF2700
09 04 00 00 02 08 06 50 00 07 05 01 02 00 02 00 07 05 82 02 00 02 00 
numendpoint=2
endpointIn=82
endpointOut=1
packet size in (msController) = 512
packet size out (msController) = 512
polling intervalIn = 0
polling intervalOut = 0
new_Pipe
new_Pipe
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 02 00 00 00 00 00 00 00 80 00 06 1B 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 02 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 03 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 03 00 00 00 00 00 00 00 01 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 04 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 04 00 00 00 00 00 00 00 01 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 05 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 05 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 06 00 00 00 24 00 00 00 80 00 06 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 36
00 80 00 00 1F 00 00 00 4D 75 6C 74 69 20 20 20 46 6C 61 73 68 20 52 65 61 64 65 72 20 20 20 20 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 06 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 07 00 00 00 08 00 00 00 80 00 0A 25 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 8
00 EC DF FF 00 00 02 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 07 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 08 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 512
FA B8 00 10 8E D0 BC 00 B0 B8 00 00 8E D8 8E C0 FB BE 00 7C BF 00 06 B9 00 02 F3 A4 EA 21 06 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 08 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 09 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 08 00 00 00 01 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 512
EB 58 90 6D 6B 66 73 2E 66 61 74 00 02 08 20 00 02 00 00 00 00 F8 00 00 3E 00 F5 00 00 08 00 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 09 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 0A 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 08 01 00 00 01 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 512
52 52 61 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 0A 00 00 00 00 00 00 00 00 
** CSWSIGNATURE

Change drive

Do Device Inquiry
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 0B 00 00 00 24 00 00 00 80 00 06 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 36
00 80 00 00 1F 00 00 00 4D 75 6C 74 69 20 20 20 46 6C 61 73 68 20 52 65 61 64 65 72 20 20 20 20 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 0B 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
Removable Device: YES
        VendorID: Multi   
       ProductID: Flash Reader    
      RevisionID: 1.00

Get Device Capacity Specs
msController CallbackOut (static)
transfer->qtd.token = 1
msController dataOut (static)31
55 53 42 43 0C 00 00 00 08 00 00 00 80 00 0A 25 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 8
00 EC DF FF 00 00 02 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 0C 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
    Sector Count: 15523839
     Sector size: 512
   Disk Capacity: 15523839 * 512 Bytes

Now I am going to work with reading and decode sense codes.

I just tested Hot Plugging with the card reader and it works.
 
Last edited:
@wwatson @mjs513 @WMXZ - Glad we are making some progress here.. As we mentioned earlier on Bluetooth thread, it would be great to support some mass storage devices.

I thought I would try with an Toshiba 1GB external hard disk I had sitting around.... Had Windows format it exFat... SDFormatter did not see it...

Tried both test programs and both are dying...



Code:
USB2 PLL running
 reset waited 6
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 20004000
periodictable = 20004000
port change: 10001803
    connect
  begin reset
port change: 18001205
  port enabled
  end recovery
new_Device: 480 Mbit/sec
new_Pipe
enumeration:
enumeration:
enumeration:
Device Descriptor:
  12 01 00 02 00 00 00 40 39 09 13 0B 00 01 01 02 03 01 
    VendorID = 0939, ProductID = 0B13, Version = 0100
    Class/Subclass/Protocol = 0 / 0 / 0
    Number of Configurations = 1
enumeration:
enumeration:
Manufacturer: TOSHIBA 
enumeration:
Product: External HDD    
enumeration:
Serial Number: 0010101A402E78AF0
enumeration:
Config data length = 32
enumeration:
Configuration Descriptor:
  09 02 20 00 01 01 00 C0 01 
    NumInterfaces = 1
    ConfigurationValue = 1
  09 04 00 00 02 08 06 50 00 
    Interface = 0
    Number of endpoints = 2
    Class/Subclass/Protocol = 8(Mass Storage) / 6(SCSI) / 80(Bulk Only)
  07 05 81 02 00 02 00 
    Endpoint = 1 IN
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  07 05 02 02 00 02 00 
    Endpoint = 2 OUT
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
enumeration:
USBHub memory usage = 960
USBHub claim_device this=20002D40
msController claim this=20003120
Descriptor 4 = INTERFACE
msController claim this=20003120
09 04 00 00 02 08 06 50 00 07 05 81 02 00 02 00 07 05 02 02 00 02 00 
numendpoint=2
endpointIn=81
endpointOut=2
packet size in (msController) = 512
packet size out (msController) = 512
polling intervalIn = 0
polling intervalOut = 0
new_Pipe
new_Pipe
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
control CallbackIn (msController)
01 00 00 00 00 00 00 00 
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 02 00 00 00 00 00 00 00 80 00 06 1B 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 02 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 03 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 03 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 04 00 00 00 24 00 00 00 80 00 06 12 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 36
05 80 00 21 1F 00 00 00 54 4F 53 48 49 42 41 20 56 69 72 74 75 61 6C 20 43 64 72 6F 6D 20 20 20 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 04 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 05 00 00 00 08 00 00 00 80 00 0A 25 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 8
00 01 F3 FF 00 00 08 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 05 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
Disk initialize Status: 0
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 06 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 06 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 07 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 64
msController dataIn (static): 0
ERROR Followup
But it could be some of my hacking that failed...
Although I think this is probably after my hacking...
 
@Kurte

Code:
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 07 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 
msController CallbackIn (static)
[COLOR="#FF0000"]transfer->qtd.token = 64[/COLOR]
msController dataIn (static): 0
[COLOR="#FF0000"]ERROR Followup[/COLOR]

I see the qtd.token has bit 6 set. The Host controller sets this to 1 on a HALT due to an error.

Check page 44 of the EHCI PDF manual which can be downloaded here. https://www.intel.com/content/www/us/en/products/docs/io/universal-serial-bus/ehci-specification-for-usb.html

If I remember right, the followup error is due to a incomplete pending transfer. Probably should check the ehci.cpp file (lines 344-362) for that.
 
To facilitate rc=xx understanding, I added error strings to uSDFS.h (latest gitgub version)
 
Last edited:
Thanks @...

Not sure how much more I will be able to do here for awhile. Like it might be awhile before I look at the Toshiba hard disk issue.

I have not debugged the last command that error-ed out. As you mentioned it implies a transfer did not complete...

Thanks @WMXZ - Having textual outputs can help!

@wwatson - the SCSI documents on seagate links do not work for me.

Again looking like some good progress.

It will be great to have all of this working.

Now getting ready for other distractions.
 
@WMXZ, @KurtE and @wwatson

Not sure what @WMXZ changed in the library but I just reran the uSDFS_test sketch in the uSDS library and the HP 120GB SSD I was using is now working:
Code:
Test uSDFS
2:/

Change drive

Create a new subdirectories.

Create a new file /Ascii/HELLO12.TXT.
Write some text lines. (Hello world!)
Close the file.

Open same file /Ascii/HELLO12.TXT.
Get the file content.
Hello world!
Second Line
Third Line
Fourth Line
Habe keine Phantasie
Close the file.

open binary file
write file
close file
Binary test done

Open root directory.
Directory listing...
   <dir>  System Volume Information
   <dir>  Ascii
   <dir>  Binary

Test completed.
@KurtE you might update the uSDFS lib and give your HDD a try. Reran it just to see what text strings would give me.

OH, @WMXZ - need to make one change to the uSDFS.h file:
Code:
const char *STAT_ERROR_STRING = {
needs to be changed to:
Code:
const char *STAT_ERROR_STRING[] = {
 
@mjs513

Actually there was two files that needed to be changed. Not diskio.h but uSDFS.h line 3 and uSDFS_test.ino line 31.
In uSDFS.h add sqaure brackets
Code:
const char *STAT_ERROR_STRING[] = {
and
in uSDFS_test.ino change line 31:
Code:
FR_ERROR_STRING(rc)
to:
Code:
FR_ERROR_STRING[rc]

@WMXZ
I like it, I do better with words than numbers.
Thanks
 
@mjs513

Actually there was two files that needed to be changed. Not diskio.h but uSDFS.h line 3 and uSDFS_test.ino line 31.
....

@WMXZ
I like it, I do better with words than numbers.
Thanks

Was typical cut/paste error (jet-lag), corrected now

@wwatson, is there a github or new zip file with latest MSC?
 
@wwatson, @WMXZ, @mjs513...

I may not have much time to play here today, so thought I would revisit why the 1GB CRUZER (SanDisk) is not working... Endless loop waiting for media available...
And document what I have found, in case someone else can pick up where I leave off...

So wondered if maybe it has multiple logical units... So thought about adding the code for it... Then saw it was already there...

Changed the init code to print out the result, like:
Code:
	msResult = msDrive1.msGetMaxLun();
	Serial.printf("## mscInit after msgGetMaxLun: %d\n", msResult);
	delay(150);
And for working disk and this non-working disk they showed 0 printed...

Then I looked a little closer at it. The code for getting max lun...
Code:
uint8_t msController::msGetMaxLun() {

	mk_setup(setup, 0xa1, 0xfe, 0, 0, 1);
	queue_Control_Transfer(device, &setup, report, this);
	return report[0];
}
This won't work as you have only queued the request and then return the data before it ever has chance to be filled in...

Now looking at output of my non-working drive:
Code:
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
## mscInit after msgGetMaxLun: 0
control CallbackIn (msController)
01 00 00 00 00 00 00 00 
msController CallbackOut (static)
You will see the Callback showing a value of 1...
And going back to look at the other thumb drive that is returning data:
Code:
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
## mscInit after msgGetMaxLun: 0
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
msController CallbackOut (static)
It does show 0 as the last valid LUN...

So thinking maybe in this case, (after fixing the code to wait for callback before returning, which I have not done yet),
Maybe if media is not available on LUN=0, need to try others up to MAX and/or maybe always try the MAX one first?

If this is the issue, will need to change several low level functions, to take in the LUN to pass as either parameter or some global setting....

Kurt
 
@KurtE

That's interesting on you 1GB SanDisk Cruzer. Reason I am saying this is that I tried a 2Gb SanDisk Cruzer and it worked. It does have 2 partitions on it - one for the U3 system and the second for the data. It read the data partition no problem. I did reformat it though - I think for exFat or FAT32 - don't remember now will have to recheck and retest.

Mike
 
So I got me a Transcend 8GB stick (FAT32 formated)
with debug on and program (#58) I get the following
Code:
USB2 PLL running
 reset waited 6
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 20003000
periodictable = 20003000
port change: 10001803
    connect
  begin reset
port change: 18001205
  port enabled
  end recovery
new_Device: 480 Mbit/sec
new_Pipe
enumeration:
enumeration:
enumeration:
Device Descriptor:
  12 01 10 02 00 00 00 40 64 85 00 10 00 11 01 02 03 01 
    VendorID = 8564, ProductID = 1000, Version = 1100
    Class/Subclass/Protocol = 0 / 0 / 0
    Number of Configurations = 1
enumeration:
enumeration:
Manufacturer: JetFlash
enumeration:
Product: Mass Storage Device
enumeration:
Serial Number: 17Q880DIDAVC35MP
enumeration:
Config data length = 32
enumeration:
Configuration Descriptor:
  09 02 20 00 01 01 00 80 96 
    NumInterfaces = 1
    ConfigurationValue = 1
  09 04 00 00 02 08 06 50 00 
    Interface = 0
    Number of endpoints = 2
    Class/Subclass/Protocol = 8(Mass Storage) / 6(SCSI) / 80(Bulk Only)
  07 05 01 02 00 02 00 
    Endpoint = 1 OUT
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  07 05 82 02 00 02 00 
    Endpoint = 2 IN
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
enumeration:
msController claim this=20002AA0
Descriptor 4 = INTERFACE
msController claim this=20002AA0
09 04 00 00 02 08 06 50 00 07 05 01 02 00 02 00 07 05 82 02 00 02 00 
endpointType = 2
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
and then nothing

OK, I still using the program V2 from earlier zip

Any possibility to get a new zip file with update MSC?
If USBHost_t3 still the same?
 
@WMXZ
This is what I have been using - pretty sure it has all the changes talked about.
 

Attachments

  • MSC.zip
    25.5 KB · Views: 81
@mjs513, thanks, now it is running through
Code:
USB2 PLL running
 reset waited 6
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 20003000
periodictable = 20003000
port change: 10001803
    connect
  begin reset
port change: 18001205
  port enabled
  end recovery
new_Device: 480 Mbit/sec
new_Pipe
enumeration:
enumeration:
enumeration:
Device Descriptor:
  12 01 10 02 00 00 00 40 64 85 00 10 00 11 01 02 03 01 
    VendorID = 8564, ProductID = 1000, Version = 1100
    Class/Subclass/Protocol = 0 / 0 / 0
    Number of Configurations = 1
enumeration:
enumeration:
Manufacturer: JetFlash
enumeration:
Product: Mass Storage Device
enumeration:
Serial Number: 17Q880DIDAVC35MP
enumeration:
Config data length = 32
enumeration:
Configuration Descriptor:
  09 02 20 00 01 01 00 80 96 
    NumInterfaces = 1
    ConfigurationValue = 1
  09 04 00 00 02 08 06 50 00 
    Interface = 0
    Number of endpoints = 2
    Class/Subclass/Protocol = 8(Mass Storage) / 6(SCSI) / 80(Bulk Only)
  07 05 01 02 00 02 00 
    Endpoint = 1 OUT
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  07 05 82 02 00 02 00 
    Endpoint = 2 IN
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
enumeration:
msController claim this=20002AC0
Descriptor 4 = INTERFACE
msController claim this=20002AC0
09 04 00 00 02 08 06 50 00 07 05 01 02 00 02 00 07 05 82 02 00 02 00 
numendpoint=2
endpointIn=82
endpointOut=1
packet size in (msController) = 512
packet size out (msController) = 512
polling intervalIn = 0
polling intervalOut = 0
new_Pipe
new_Pipe
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
control CallbackIn (msController)
00 00 00 00 00 00 00 00 
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 02 00 00 00 00 00 00 00 80 00 06 1B 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 02 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 03 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 03 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 04 00 00 00 24 00 00 00 80 00 06 12 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 36
00 80 06 02 1F 73 6D 69 4A 65 74 46 6C 61 73 68 54 72 61 6E 73 63 65 6E 64 20 38 47 42 20 20 20 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 04 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 05 00 00 00 08 00 00 00 80 00 0A 25 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 8
00 E1 3F FF 00 00 02 00 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 05 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
Disk initialize Status: STA_OK
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 06 00 00 00 00 00 00 00 80 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 06 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
msController CallbackOut (static)
transfer->qtd.token = 0
msController dataOut (static)31
55 53 42 43 07 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 512
33 C0 8E D0 BC 00 7C FB 50 07 50 1F FC BE 1B 7C BF 1B 06 50 57 B9 E5 01 F3 A4 CB BD BE 07 B1 04 
** ????
msController CallbackIn (static)
transfer->qtd.token = 0
msController dataIn (static): 13
55 53 42 53 07 00 00 00 00 00 00 00 00 
** CSWSIGNATURE
Disk read Result: FR_OK
33 c0 8e d0 bc 00 7c fb 50 07 50 1f fc be 1b 7c
bf 1b 06 50 57 b9 e5 01 f3 a4 cb bd be 07 b1 04
38 6e 00 7c 09 75 13 83 c5 10 e2 f4 cd 18 8b f5
83 c6 10 49 74 19 38 2c 74 f6 a0 b5 07 b4 07 8b
f0 ac 3c 00 74 fc bb 07 00 b4 0e cd 10 eb f2 88
4e 10 e8 46 00 73 2a fe 46 10 80 7e 04 0b 74 0b
80 7e 04 0c 74 05 a0 b6 07 75 d2 80 46 02 06 83
46 08 06 83 56 0a 00 e8 21 00 73 05 a0 b6 07 eb
bc 81 3e fe 7d 55 aa 74 0b 80 7e 10 00 74 c8 a0
b7 07 eb a9 8b fc 1e 57 8b f5 cb bf 05 00 8a 56
00 b4 08 cd 13 72 23 8a c1 24 3f 98 8a de 8a fc
43 f7 e3 8b d1 86 d6 b1 06 d2 ee 42 f7 e2 39 56
0a 77 23 72 05 39 46 08 73 1c b8 01 02 bb 00 7c
8b 4e 02 8b 56 00 cd 13 73 51 4f 74 4e 32 e4 8a
56 00 cd 13 eb e4 8a 56 00 60 bb aa 55 b4 41 cd
13 72 36 81 fb 55 aa 75 30 f6 c1 01 74 2b 61 60
6a 00 6a 00 ff 76 0a ff 76 08 6a 00 68 00 7c 6a
01 6a 10 b4 42 8b f4 cd 13 61 61 73 0e 4f 74 0b
32 e4 8a 56 00 cd 13 eb d6 61 f9 c3 49 6e 76 61
6c 69 64 20 70 61 72 74 69 74 69 6f 6e 20 74 61
62 6c 65 00 45 72 72 6f 72 20 6c 6f 61 64 69 6e
67 20 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74
65 6d 00 4d 69 73 73 69 6e 67 20 6f 70 65 72 61
74 69 6e 67 20 73 79 73 74 65 6d 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 2c 44 63 18 2e 07 c3 00 00 00 20
21 00 0c fe ff 95 00 08 00 00 00 30 e1 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa

Master Boot Record
  Partition: 0 first Sector: 2048 total Sectors: 14757888
  Partition: 1 first Sector: 0 total Sectors: 0
  Partition: 2 first Sector: 0 total Sectors: 0
  Partition: 3 first Sector: 0 total Sectors: 0

BTW, it is Fat32 formatted by Win32
 
Back
Top