USBHost_t36 USB Mass Storage Driver Experiments

UHS3.0 does this on the K66... You still will get a "wait" while enumerating, but it's fine after that.
The reason it has to "wait" is because it's doing a lot of work.
https://github.com/felis/UHS30
Also supports the SDcard on the 3.6 too, with just one simple modification... connecting the card detect line.
Why Paul didn't do that, I dunno, but it is a whole lot better than polling.
 
Sadly, this solution doesn't seems to work on Teensy 4.1. Back to the drawing board.

That is sad - though not unexpected. Not that TeensyThreads isn't a well done impressive piece of work as far as it goes. Just that parking a task, as it is designed to do, seems fraught with peril for certain types of 'tasks'.

It is great that it assures timely attention for critical tasks - from those that can handle extended interrupts.
 
It's particularly frustrating when it works on one platform and not not the other. Today I rewrote the USB drive begin() function as non-blocking. It takes care of the system hanging when first opening a drive. Still need to implement the find partition part, but shouldn't be too much trouble.
 
I found an issue with some USB Flash devices, and I'm not sure fix it. Apparently some devices with issue a STALL when you request getMaxLUN(). In that case we need to reset somehow, and I'm not entirely sure how that is to be done. Currently, if I request max LUN on that drive, the Teensy crashes, so for now I'm just skipping that request entirely.

Screenshot 2023-02-26 133200.jpg
 
Last edited:
I found an issue with some USB Flash devices, and I'm not sure fix it. Apparently some devices with issue a STALL when you request getMaxLUN(). In that case we need to reset somehow, and I'm not entirely sure how that is to be done. Currently, if I request max LUN on that drive, the Teensy crashes, so for now I'm just skipping that request entirely.

View attachment 30501

This is something that I knew about and played with for quite a while. I never had an mass storage device available that had more than one logical unit number or would cause the device to stall. When you say it crashes do you mean that it hangs? Have you tried turning debug on to see where it crashes or hangs? It would be interesting to see what the debug output is.

There are a couple of things you can do to try and overcome the issue. In mscInit():
Code:
	msReset();
	// delay(500); // Not needed any more.
	maxLUN = msGetMaxLun();

//	msResult = msReportLUNs(&maxLUN);
//println("maxLUN = ");
//println(maxLUN);
//	delay(150);
	//-------------------------------------------------------
	msResult = msStartStopUnit(1);
	msResult = WaitMediaReady();
	if(msResult)
		return msResult;

You can uncomment 'delay(500)' to see if that helps. I have seen some examples of this being used. Also uncomment the 150 ms delay after the call to get maxLuns. Lastly try commenting out 'msStartStopUnit(1)'. This also has been known to cause some devices to stall.
If you know where it is hanging, try adding a timeout and then issue another 'msReset()'.

Again, I do not have any devices available to me that exhibit this issue:)
 
@Paul - Does the EHCI driver automatically clear endpoint stall conditions? It's been a long time since I looked at this. It looks like halted pipes might be handled in 'followup_error()' function.
 
@Paul - Does the EHCI driver automatically clear endpoint stall conditions? It's been a long time since I looked at this. It looks like halted pipes might be handled in 'followup_error()' function.

I'm pretty sure it does. The crash I was experiencing comes from a bug, which is fixed in the code below:
Code:
void USBFilesystem::end(bool update_list) {
	mscfs.end();
	//if (update_list) device->filesystem_assign_to_drive(this, false); <-- Crashes the system if device isn't set
	if (device && update_list) device->filesystem_assign_to_drive(this, false);
	device = nullptr;
}
 
Hi, I manufacture a board since few years, I first started with Teensy 3.2, last year I had to update to Teensy 4.0 due to lack of stock, so I think that the hard work was already made and the possibilities of new hardware are greater. Now my client ask me for data download to PC in USB instead of expensive GPRS o Ethernet external modules, so I give a try to Teensy 4.1.

With Teensyduino 1.57 I managed to read and write files, but I have problems with some usb drives, is not a option to buy the same unit, final customer will use any stick.

After trying few different drives there are some common symthoms:

- USB 3 drives use to fail in a high %, some are even not detected.
- Some of the other units fail to detect, the firmware hangs and as I had set watchdog the unit reset and after the reset with the stick plugged it works.
-Sometimes the teensy hangs just after connect the stick so maybe a current comsumption higher than expected.
-A couple of units detected but unable to write on it, after changing to GPT from MBR and reformated it works, all tests with FAT32 partition.

My tests was with low capacity drives, 16 to 32GB.

Even with included sample scripts the same unit works with one script and not with other, Listfiles work but can't write.


I am able to test anything to help if these problems are already detected and you are working on it.

Anything just comment and I will do my best.

Regards
 
The code is based on the one posted by wwatson here, this fails too.


As I mentioned before problems occurs with sample codes of teensyduino with the same sticks that fails in my script so I think must be a library problem related with different hardware or MBR/partitions types.

2 different sticks, others doesn't even initialize.

Code:
Initializing USB MSC drive...initialization done.

Testing Write, Copy and Read. BUF_SIZE = 8192

Writing to test.txt...Wrote 1024000 bytes 0.142000 seconds. Speed : 7.211000 MB/s
test.txt:
Copying test.txt to copy.txt...Copied 1024000 bytes 3.930000 seconds. Speed : 0.260000 MB/s
copy.txt:
Reading File: copy.txt...Read 1024000 bytes 0.091000 seconds. Speed : 11.252000 MB/s
Done..



Initializing USB MSC drive...initialization done.

Testing Write, Copy and Read. BUF_SIZE = 8192

Writing to test.txt..
 
Hi, I manufacture a board since few years, I first started with Teensy 3.2, last year I had to update to Teensy 4.0 due to lack of stock, so I think that the hard work was already made and the possibilities of new hardware are greater. Now my client ask me for data download to PC in USB instead of expensive GPRS o Ethernet external modules, so I give a try to Teensy 4.1.

With Teensyduino 1.57 I managed to read and write files, but I have problems with some usb drives, is not a option to buy the same unit, final customer will use any stick.

After trying few different drives there are some common symthoms:

- USB 3 drives use to fail in a high %, some are even not detected.
- Some of the other units fail to detect, the firmware hangs and as I had set watchdog the unit reset and after the reset with the stick plugged it works.
-Sometimes the teensy hangs just after connect the stick so maybe a current comsumption higher than expected.
-A couple of units detected but unable to write on it, after changing to GPT from MBR and reformated it works, all tests with FAT32 partition.

My tests was with low capacity drives, 16 to 32GB.

Even with included sample scripts the same unit works with one script and not with other, Listfiles work but can't write.


I am able to test anything to help if these problems are already detected and you are working on it.

Anything just comment and I will do my best.

Regards

I've spent weeks going over the MassStorage code and have pointed out several issues, but the maintainers of the code haven't attempted to fix them. Some of the issues are very simple fixes, others are much more involved. The code is complicated and working on such low level hurts the brain. Just to get things working at the level they do is quite a feat. Making a small change to the code involves a huge amount of testing and is very time consuming so I can understand that there's a lot of resistance to making changes. Until proper fixes come to the library, I don't think you should rely on it.

I've resorted to hacking my way to making it work for my needs, but even after my weeks of work there are times when things don't behave quite like they should, pointing to issues deeper down in the USBHost library. Much like the maintainers of the MassStorage driver, I've gotten it to work well enough for what I need to do, but have come short of getting rid of all the issues because there seems to be ghosts in the machine and tracking them down will lead to pain and suffering.
 
Hi, I manufacture a board since few years, I first started with Teensy 3.2, last year I had to update to Teensy 4.0 due to lack of stock, so I think that the hard work was already made and the possibilities of new hardware are greater. Now my client ask me for data download to PC in USB instead of expensive GPRS o Ethernet external modules, so I give a try to Teensy 4.1.

With Teensyduino 1.57 I managed to read and write files, but I have problems with some usb drives, is not a option to buy the same unit, final customer will use any stick.

After trying few different drives there are some common symthoms:

- USB 3 drives use to fail in a high %, some are even not detected.
- Some of the other units fail to detect, the firmware hangs and as I had set watchdog the unit reset and after the reset with the stick plugged it works.
-Sometimes the teensy hangs just after connect the stick so maybe a current comsumption higher than expected.
-A couple of units detected but unable to write on it, after changing to GPT from MBR and reformated it works, all tests with FAT32 partition.

My tests was with low capacity drives, 16 to 32GB.

Even with included sample scripts the same unit works with one script and not with other, Listfiles work but can't write.


I am able to test anything to help if these problems are already detected and you are working on it.

Anything just comment and I will do my best.

Regards

Let's see if we can figure out what is going on. First I assume you are using Arduino 1.8.19 along with Teensyduino 1.57. Next USB 3 drives have not been tested as the T4..x supports USB 2.0. Make sure the drives are formatted FAT32 or EXFAT. Again some thumb (stick) drives can take some time to initialize and become ready. Up to 30 seconds or more. In USBHost_t36.h at about line #63 you will see a commented define like this:
Code:
// Uncomment this line to see lots of debugging info!
//#define USBHOST_PRINT_DEBUG

Uncomment this define and compile the "driveinfo.ino" example file and upload it to one of the failing drives. Then you can copy and post the debug output. This will give us more of a chance to find out if and why it is failing.

One other thing you can try is increasing a couple of timeouts in "utility/msc.h" file starting at line #73.

From:
Code:
// These two defines are timeouts for detecting a connected drive
// and waiting for it to be operational.
#define MEDIA_READY_TIMEOUT 1000
#define MSC_CONNECT_TIMEOUT 4000

To:
Code:
// These two defines are timeouts for detecting a connected drive
// and waiting for it to be operational.
#define MEDIA_READY_TIMEOUT 5000
#define MSC_CONNECT_TIMEOUT 5000

I have a SSD drive that needs the timeouts to be 5000. Lastly, make sure the drive is not write protected.
There have been changes made since Teensyduino 1.57. I would suggest updating to TD1,58 Beta 2.

We really need some debug output to try to help.

Edit: If you can, please give some information on the thumb drives that are not working:)
 
Last edited:
@yeahtuna - Yes, I am leery of putting in PR requests for issues that I cannot duplicate. A lot of people and myself have put in countless hours testing and updating this library. Many devices have been tested and proven to work. Only with good debug output and examples of the failing code being used can we begin to track down issues...
 
Hi, these are log error for 2 different units. Same CSW Tag Error: 253

Code:
USB2 PLL running
 reset waited 6
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 2000A000
periodictable = 2000A000

Initializing USB MSC drive...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 81 07 90 55 00 01 01 02 03 01 
    VendorID = 0781, ProductID = 5590, Version = 0100
    Class/Subclass/Protocol = 0 / 0 / 0
    Number of Configurations = 1
enumeration:
enumeration:
Manufacturer: SanDisk
enumeration:
Product: Ultra
enumeration:
Serial Number: 4C530000061112120085
enumeration:
Config data length = 32
enumeration:
Configuration Descriptor:
  09 02 20 00 01 01 00 80 70 
    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=2000A1E0
USBHub memory usage = 960
USBHub claim_device this=2000A5A0
USBHub memory usage = 960
USBHub claim_device this=2000A960
USBHub memory usage = 960
USBHub claim_device this=2000AD20
USBDrive claim this=2000B0E0
Descriptor 4 = INTERFACE
USBDrive claim this=2000B0E0
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 (USBDrive) = 512
packet size out (USBDrive) = 512
polling intervalIn = 0
polling intervalOut = 0
new_Pipe
new_Pipe
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
control CallbackIn (USBDrive)
00 00 00 00 00 00 00 00 
control CallbackIn (USBDrive)
00 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 01 00 00 00 00 00 00 00 80 00 06 1B 01 00 00 01 00 00 00 00 00 00 00 00 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 01 00 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 02 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 02 00 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 03 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 36
00 80 06 12 43 00 00 00 53 61 6E 44 69 73 6B 00 55 6C 74 72 61 00 00 00 00 00 00 00 00 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 03 00 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 04 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 8
03 94 7F FF 00 00 02 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 04 00 00 00 00 00 00 00 00 
msReadBlocks()
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 05 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 512
41 4B 45 4F FC 31 C0 FA 8E D0 BC 00 7C FB 8E D8 BB 13 04 8B 07 83 E8 04 89 07 C1 E0 06 8E C0 B8 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 05 00 00 00 00 00 00 00 00 
msReadBlocks()
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 06 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 00 01 00 00 01 00 00 00 00 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 512
45 46 49 20 50 41 52 54 00 00 01 00 5C 00 00 00 4F 6A 60 D5 00 00 00 00 01 00 00 00 00 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 06 00 00 00 00 00 00 00 00 
msReadBlocks()
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 07 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 00 02 00 00 01 00 00 00 00 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 512
A2 A0 D0 EB E5 B9 33 44 87 C0 68 B6 B7 26 99 C7 C0 C8 6F 6B 99 B0 F0 4E 89 CF 7E 58 79 2B 76 2D 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 07 00 00 00 00 00 00 00 00 
msReadBlocks()
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 08 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 512
EB 58 90 4D 53 44 4F 53 35 2E 30 00 02 20 80 0D 02 00 00 00 00 F8 00 00 3F 00 FF 00 00 08 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 08 00 00 00 00 00 00 00 00 
msReadBlocks()
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 512
EB 58 90 4D 53 44 4F 53 35 2E 30 00 02 20 80 0D 02 00 00 00 00 F8 00 00 3F 00 FF 00 00 08 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 09 00 00 00 00 00 00 00 00 
initialization done.

Testing Write, Copy and Read. BUF_SIZE = 8192
msReadBlocks()
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 0A 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 88 00 00 00 01 00 00 00 00 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 512
4E 55 45 56 4F 20 56 4F 4C 20 20 08 00 00 00 00 00 00 00 00 00 00 FD 8C 6A 56 00 00 00 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 0A 00 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 0B 00 00 00 00 02 00 00 00 00 0A 2A 00 00 00 88 00 00 00 01 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)512
4E 55 45 56 4F 20 56 4F 4C 20 20 08 00 00 00 00 00 00 00 00 00 00 FD 8C 6A 56 00 00 00 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 64
USBDrive dataIn (static): 0
ERROR Followup
CSW Tag Error: 253
CSW Tag Error: 253

Writing to test.txt...msReadBlocks()
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 0C 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 15 80 00 00 01 00 00 00 00 00 00 00
Code:
USB2 PLL running
 reset waited 6
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 2000A000
periodictable = 2000A000

Initializing USB MSC drive...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 81 07 81 55 00 01 01 02 03 01 
    VendorID = 0781, ProductID = 5581, Version = 0100
    Class/Subclass/Protocol = 0 / 0 / 0
    Number of Configurations = 1
enumeration:
enumeration:
Manufacturer:  USB
enumeration:
Product:  SanDisk 3.2Gen1
enumeration:
Serial Number: 04014fae9ea771b62f585cc42d66b8a6e38dffc23bcc4a04c8c84c8969cbfcbe4afe0000000000000000000018746849008b62188155810795285b34
enumeration:
Config data length = 32
enumeration:
Configuration Descriptor:
  09 02 20 00 01 01 00 80 70 
    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=2000A1E0
USBHub memory usage = 960
USBHub claim_device this=2000A5A0
USBHub memory usage = 960
USBHub claim_device this=2000A960
USBHub memory usage = 960
USBHub claim_device this=2000AD20
USBDrive claim this=2000B0E0
Descriptor 4 = INTERFACE
USBDrive claim this=2000B0E0
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 (USBDrive) = 512
packet size out (USBDrive) = 512
polling intervalIn = 0
polling intervalOut = 0
new_Pipe
new_Pipe
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
control CallbackIn (USBDrive)
00 00 00 00 00 00 00 00 
control CallbackIn (USBDrive)
00 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 01 00 00 00 00 00 00 00 80 00 06 1B 01 00 00 01 00 00 00 00 00 00 00 00 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 01 00 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 02 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 02 00 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 03 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 36
00 80 06 12 43 00 00 00 20 55 53 42 00 00 00 00 20 53 61 6E 44 69 73 6B 20 33 2E 32 47 65 6E 31 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 03 00 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 04 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 8
03 94 7F FF 00 00 02 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 04 00 00 00 00 00 00 00 00 
msReadBlocks()
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 05 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 512
FA 33 C0 8E D0 BC 00 7C 8B F4 50 07 50 1F FB FC BF 00 06 B9 00 01 F2 A5 EA 1D 06 00 00 BE BE 07 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 05 00 00 00 00 00 00 00 00 
msReadBlocks()
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 06 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 512
EB 58 90 4D 53 57 49 4E 34 2E 31 00 02 10 20 00 02 00 00 00 00 F8 00 00 3F 00 FF 00 00 08 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 06 00 00 00 00 00 00 00 00 
msReadBlocks()
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 07 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 512
EB 58 90 4D 53 57 49 4E 34 2E 31 00 02 10 20 00 02 00 00 00 00 F8 00 00 3F 00 FF 00 00 08 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 07 00 00 00 00 00 00 00 00 
initialization done.

Testing Write, Copy and Read. BUF_SIZE = 8192
msReadBlocks()
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 08 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 ED 30 00 00 01 00 00 00 00 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 512
42 20 00 49 00 6E 00 66 00 6F 00 0F 00 72 72 00 6D 00 61 00 74 00 69 00 6F 00 00 00 6E 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 08 00 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 09 00 00 00 00 02 00 00 00 00 0A 2A 00 00 00 ED 30 00 00 01 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)512
42 20 00 49 00 6E 00 66 00 6F 00 0F 00 72 72 00 6D 00 61 00 74 00 69 00 6F 00 00 00 6E 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 64
USBDrive dataIn (static): 0
ERROR Followup
CSW Tag Error: 253
CSW Tag Error: 253

Writing to test.txt...msReadBlocks()
USBDrive CallbackOut (static)
transfer->qtd.token = 0
USBDrive dataOut (static)31
55 53 42 43 0A 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 08 20 00 00 01 00 00 00 00 00 00 00

I hope it helps
 
I've spent weeks going over the MassStorage code and have pointed out several issues, but the maintainers of the code haven't attempted to fix them. Some of the issues are very simple fixes, others are much more involved. The code is complicated and working on such low level hurts the brain. Just to get things working at the level they do is quite a feat. Making a small change to the code involves a huge amount of testing and is very time consuming so I can understand that there's a lot of resistance to making changes. Until proper fixes come to the library, I don't think you should rely on it.

I've resorted to hacking my way to making it work for my needs, but even after my weeks of work there are times when things don't behave quite like they should, pointing to issues deeper down in the USBHost library. Much like the maintainers of the MassStorage driver, I've gotten it to work well enough for what I need to do, but have come short of getting rid of all the issues because there seems to be ghosts in the machine and tracking them down will lead to pain and suffering.

Sorry, I am not sure who the "maintainers" are?

The only person who can merge in any changes to this library is the Paul. @wwatson, who did most of the original MasStoreage work, has been very active on this thread and project. A few others of us like @mjs513 and myself, have done some of the intermediate glue work, @defragster has helped with a lot of the testing...

But it is up to Paul to decide when and of things will get merged in. And needless to say, with all of the chip shortages and the like he has had his hands full with other things, like having boards to sell.

With some of this functionality and libraries, there are areas where Paul needs to decide on how certain things will be changed. For example, extensions to FS.h to support things like File system notifications (when is a CD installed), who notifies MTP when an underlying file changes. How does the sketch know when files were changed on the host over MTP... So, I personally am off playing on some other unrelated stuff. But at some point, will likely jump back into this.

Suggestions: If you do have some simple obvious fixes to the library, create a github Pull Request, with the fix. If it makes sense, you may want to @<some of us> into the PR, such that we might, try it out and comment.

As for more complex changes, or architectural changes like using threads or RTOS and the like, I might personally agree in several cases it would be nice. But...

Good luck.
 
This one doesn't even initialize

Code:
USB2 PLL running
 reset waited 5
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 2000A000
periodictable = 2000A000

Initializing USB MSC drive...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 30 09 45 65 10 01 01 02 03 01 
    VendorID = 0930, ProductID = 6545, Version = 0110
    Class/Subclass/Protocol = 0 / 0 / 0
    Number of Configurations = 1
enumeration:
enumeration:
Manufacturer: Kingston
enumeration:
Product: DataTraveler G2
enumeration:
Serial Number: 001D0F1314D5B911131A0100
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 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=2000A1E0
USBHub memory usage = 960
USBHub claim_device this=2000A5A0
USBHub memory usage = 960
USBHub claim_device this=2000A960
USBHub memory usage = 960
USBHub claim_device this=2000AD20
USBDrive claim this=2000B0E0
Descriptor 4 = INTERFACE
USBDrive claim this=2000B0E0
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 (USBDrive) = 512
packet size out (USBDrive) = 512
polling intervalIn = 0
polling intervalOut = 0
new_Pipe
new_Pipe
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
control CallbackIn (USBDrive)
00 00 00 00 00 00 00 00 
control CallbackIn (USBDrive)
00 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 1
USBDrive dataOut (static)31
55 53 42 43 01 00 00 00 00 00 00 00 80 00 06 1B 01 00 00 01 00 00 00 00 00 00 00 00 00 00 00 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 01 00 00 00 00 00 00 00 00 
USBDrive CallbackOut (static)
transfer->qtd.token = 1
USBDrive dataOut (static)31
55 53 42 43 02 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 02 00 00 00 00 00 00 00 01 
USBDrive CallbackOut (static)
transfer->qtd.token = 1
USBDrive 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 03 00 00 00 00 00 00 00 01 
USBDrive CallbackOut (static)
transfer->qtd.token = 1
USBDrive 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 

.
.
.
.
.
.
.

USBDrive dataOut (static)31
55 53 42 43 9E 0F 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 9E 0F 00 00 00 00 00 00 01 
USBDrive CallbackOut (static)
transfer->qtd.token = 1
USBDrive dataOut (static)31
55 53 42 43 9F 0F 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 
USBDrive CallbackIn (static)
transfer->qtd.token = 0
USBDrive dataIn (static): 13
55 53 42 53 9F 0F 00 00 00 00 00 00 01 
initialization failed!
After more than 65k lines from
55 53 42 43 01 00 00 00 00 00 00 00 80 00 06 1B 01 00 00 01 00 00 00 00 00 00 00 00 00 00 00
55 53 42 43 02 00 00 00 00 00 00 00 80 00 06 1B 01 00 00 01 00 00 00 00 00 00 00 00 00 00 00

to

55 53 42 43 9E 0F 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
55 53 42 43 9F 0F 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

finally get the message initialization failed!
 
Do you have any links, for example on Amazon for some of these drives?
Preferably ones that are pretty cheap?
 
Do you have any links, for example on Amazon for some of these drives?
Preferably ones that are pretty cheap?

I've bought some cheap PNY 2.0 16 GB drives, same model in same order and evey one have different chipset, so that won't help, the one that doesn't initializes is an old Kingston Datatraverler G2, difficult to buy I think.
kingston-dtig2-8gb__1_400x.jpg

I made test with every stick I've found.
 
Last edited:
I've bought some cheap PNY 2.0 16 GB drives, same model in same order and evey one have different chipset, so that won't help, the one that doesn't initializes is an old Kingston Datatraverler G2, difficult to buy I think.
View attachment 30610

I made test with every stick I've found.

Did you ever try changing the timeouts in post # 638?
Code:
// These two defines are timeouts for detecting a connected drive
// and waiting for it to be operational.
#define MEDIA_READY_TIMEOUT 5000
#define MSC_CONNECT_TIMEOUT 5000

I did have a PNY 16G that magically became write protected and never was able to undo the write protect...
 
Note: I looked up at amazon, and they have a few Kingston Datatraveler G2 drives, but none look like the one in picture. So not sure if they would be apple to apple...
And if they are all different not sure worth picking up any as may not reproduce the issue you have. Also if the ones that have issues are no longer available, then harder to get motivated...
 
Indeed it doesn't worth you time, very old unit, I'm testing with 1.57 Beta 3 and results are differents, I will try get somo logic in the errors.

Thank you all for your efforts.
 
Note: I looked up at amazon, and they have a few Kingston Datatraveler G2 drives, but none look like the one in picture. So not sure if they would be apple to apple...
And if they are all different not sure worth picking up any as may not reproduce the issue you have. Also if the ones that have issues are no longer available, then harder to get motivated...

I found this:
https://www.tigerdirect.com/applications/SearchTools/item-details.asp?EdpNo=4433961

But they are out of stock. I am really curious as to what the problem is. The only time I have seen the tag errors was when I was trying to run MSC without checking for transfer completion. But with all of the thumb drives I have tested only one Sandisk 8G and a PNY 16G failed. Both of those write protected them selves. The biggest problem I saw was with the amount of time it took for some drives to become available. Some hard drives took up to 30 or more seconds to become available. Also had to increase the timeouts for a Targus SD card reader I have. Lastly the Kingston 120G SSD drive had problems with the default timeouts...

I did have a PR in for increasing the timeouts but I don't see it now...
 
Last edited:
Back
Top