I received the UAM6 version (older usb3) and hooked it up and tried a few things.
1. Ran the USHost drive info sketch and that seemed to work. Here is what I mean:
It always prints the directory but the drive info did not show up - add a delay(5) before printing and it got a bit better:Code:Device Info: connected: 1 initialized: 0 USB Vendor ID: 0000 USB Product ID: 0000 HUB Number: 0 HUB Port: 0 Device Address: 0 Removable Device: NO VendorID: ProductID: RevisionID: Version: 0 Sector Count: 0 Sector size: 0 Disk Capacity: 0 Bytes Volume name: Volume type: FAT32 Cluster Size: 16384 bytes Volume size: 30769037312 bytes Space used: 1654784 bytes (917 ms to compute) Files: 2021-09-23 13:01 552605 Install SanDisk Software.dmg 2021-09-23 13:02 707152 Install SanDisk Software.exe 2021-09-23 13:01 300509 SanDisk Software.pdf
but its hit or miss if it picks up the drive info.Code:Partition Table part,boot,bgnCHS[3],type,endCHS[3],start,length FAT32: 1,0,0x82,0x3,0x0,0xC,0xFE,0xFF,0xFF,8192,60116992 pt_#0: 2,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0 pt_#0: 3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0 pt_#0: 4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0 Device Info: connected: 1 initialized: 1 USB Vendor ID: 0781 USB Product ID: 5581 HUB Number: 0 HUB Port: 0 Device Address: 1 Removable Device: YES VendorID: USB ProductID: SanDisk 3.2Gen1 RevisionID: 1.00 Version: 6 Sector Count: 60125183 Sector size: 512 Disk Capacity: 30784093696 Bytes
2. Tried with a MTP Test sketch that we have
- Attached the drive no issue
- Displayed the directory no issue
- Opened a file from the drive no issue
- NOT ABLE TO COPY FILE TO DISK
- NOT ABLE to WRITE a TEST FILE TO THE DISK
3. Tried the following sketch (Note not sure its right):
but hangs on writing to the disk.Code:#include <USBHost_t36.h> // Setup USBHost_t36 and as many HUB ports as needed. USBHost myusb; USBHub hub1(myusb); // Instances for one drive USBDrive myDrive(myusb); // Instances for accessing the files on the drive USBFilesystem myFiles(myusb); // Show USB drive information for the selected USB drive. void printDriveInfo(USBDrive &drive) { // Print USB drive information. delay(5); Serial.printf(F(" connected: %d\n"), drive.msDriveInfo.connected); Serial.printf(F(" initialized: %d\n"), drive.msDriveInfo.initialized); Serial.printf(F(" USB Vendor ID: %4.4x\n"), drive.msDriveInfo.idVendor); Serial.printf(F(" USB Product ID: %4.4x\n"), drive.msDriveInfo.idProduct); Serial.printf(F(" HUB Number: %d\n"), drive.msDriveInfo.hubNumber); Serial.printf(F(" HUB Port: %d\n"), drive.msDriveInfo.hubPort); Serial.printf(F(" Device Address: %d\n"), drive.msDriveInfo.deviceAddress); Serial.printf(F("Removable Device: ")); if(drive.msDriveInfo.inquiry.Removable == 1) { Serial.printf(F("YES\n")); } else { Serial.printf(F("NO\n")); } Serial.printf(F(" VendorID: %8.8s\n"), drive.msDriveInfo.inquiry.VendorID); Serial.printf(F(" ProductID: %16.16s\n"), drive.msDriveInfo.inquiry.ProductID); Serial.printf(F(" RevisionID: %4.4s\n"), drive.msDriveInfo.inquiry.RevisionID); Serial.printf(F(" Version: %d\n"), drive.msDriveInfo.inquiry.Version); Serial.printf(F(" Sector Count: %ld\n"), drive.msDriveInfo.capacity.Blocks); Serial.printf(F(" Sector size: %ld\n"), drive.msDriveInfo.capacity.BlockSize); uint64_t drivesize = drive.msDriveInfo.capacity.Blocks; drivesize *= drive.msDriveInfo.capacity.BlockSize; Serial.print(F(" Disk Capacity: ")); Serial.print(drivesize); Serial.println(" Bytes"); drive.printPartionTable(Serial); Serial.println(); } // Show USB filesystem information void printFilesystemInfo(USBFilesystem &fs) { // print the type and size of the first FAT-type volume char volname[32]; fs.mscfs.getVolumeLabel(volname, sizeof(volname)); Serial.print("Volume name: "); Serial.println(volname); Serial.print("Volume type: FAT"); Serial.println(fs.mscfs.fatType(), DEC); Serial.print("Cluster Size: "); Serial.print(fs.mscfs.bytesPerCluster()); Serial.println(" bytes"); Serial.print("Volume size: "); Serial.print(fs.totalSize()); Serial.println(" bytes"); Serial.print(" Space used: "); elapsedMillis ms = 0; Serial.print(fs.usedSize()); Serial.print(" bytes ("); Serial.print(ms); Serial.println(" ms to compute)"); Serial.println(); Serial.println("Files:"); fs.mscfs.ls(LS_R | LS_DATE | LS_SIZE); Serial.println(); } void setup() { Serial.begin(9600); while (!Serial) { ; // wait for Arduino Serial Monitor to connect. } myusb.begin(); Serial.println("\nWaiting for Drive to initialize..."); // Wait for the drive to start. while (!myDrive) { myusb.Task(); } Serial.printf("Device Info:\n"); printDriveInfo(myDrive); elapsedMillis em; while (!myFiles && (em < 1000)) { myusb.Task(); } if (myFiles) { printFilesystemInfo(myFiles); } else { Serial.println("\n*** No Fat Filesystem Partitions found on drive **"); } File myFile = myFiles.open("test.txt", FILE_WRITE); // if the file opened okay, write to it: if (myFile) { Serial.print("Writing to test.txt..."); myFile.println("testing 1, 2, 3."); // close the file: myFile.close(); Serial.println("done."); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } // re-open the file for reading: myFile = myFiles.open("test.txt"); if (myFile) { Serial.println("test.txt:"); // read from the file until there's nothing else in it: while (myFile.available()) { Serial.write(myFile.read()); } // close the file: myFile.close(); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } } void loop(void) { }
After the hang and restart it does create a 0 byte file
but if there is problems with this file - if you try and erase it in windows it gives an error messageCode:Volume name: Volume type: FAT32 Cluster Size: 32768 bytes Volume size: 30771511296 bytes Space used: 131072 bytes (459 ms to compute) Files: 0 USBC
Note:
Tried it with 2 different hubs as well. One of which was a powered hub
with the write files test sketch I am seeing the following:
CSW TAG Errors???Code:... CSWResult: 0 CD:28 msProcessError() 65536 bytes (1027 ms to compute) Files: checkConnectedInitialized()msReadBlocks() msDoCommand() USBDrive CallbackOut (static) transfer->qtd.token = 0 USBDrive dataOut (static)31 55 53 42 43 0E 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 88 40 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 msGetCSW() USBDrive CallbackIn (static) transfer->qtd.token = 0 USBDrive dataIn (static): 13 55 53 42 53 0E 00 00 00 00 00 00 00 00 msProcessError() checkConnectedInitialized()msWriteBlocks() msDoCommand() USBDrive CallbackOut (static) transfer->qtd.token = 0 USBDrive dataOut (static)31 55 53 42 43 0F 00 00 00 00 02 00 00 00 00 0A 2A 00 00 00 88 40 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 msGetCSW() USBDrive CallbackIn (static) transfer->qtd.token = 64 USBDrive dataIn (static): 0 ERROR Followup msProcessError() CSW Tag Error: 253 msProcessError() CSW Tag Error: 253 Writing to test.txt...checkConnectedInitialized()msReadBlocks() msDoCommand() USBDrive CallbackOut (static) transfer->qtd.token = 0 USBDrive dataOut (static)31 55 53 42 43 10 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 15 A2 00 00 01 00 00 00 00 00 00 00
It looks like it sent the bytes but then no response from usb stick.
It does look like there is no response but this:
does not make sense. CSW size should be 13 bytes if I remember correctly. not sure where the 64 bytes are coming from. I should be getting my device tommorow. I need to read up on this again. Been a whileCode:transfer->qtd.token = 64
Edit: found this:
Hopefully something to go on...Code:3.3 Host/Device Packet Transfer Order The host shall send the CBW before the associated Data-Out, and the device shall send Data-In after the associated CBW and before the associated CSW. The host may request Data-In or CSW before sending the associated CBW. If the dCBWDataTransferLength is zero, the device and the host shall transfer no data between the CBW and the associated CSW. 3.4 Command Queuing The host shall not transfer a CBW to the device until the host has received the CSW for any outstanding CBW. If the host issues two consecutive CBWs without an intervening CSW or reset, the device response to the second CBW is indeterminate.
Last edited by wwatson; 03-21-2023 at 10:49 PM. Reason: More info...
@mjs513 - Just tried using Windows to compile "DriveInfo.ino". This is with a Kingston 128G USB stick.
Fist time:
Second Time:Code:Waiting for Drive to initialize... === Task() Drive 0x200035e0 connected === >> USBDrive::startFilesystems called 0x200035e0 mscInit() >>msReset() >>Partition 1 VT:1 T:7 2048 241657856 >>USBFilesystem::claimPartition 0x1 called >>USBFilesystem::check_voltype_guid(1, 0x20067f88) + Claimed Try Partition list>>USBDrive::printPartionTable Partition Table part,boot,bgnCHS[3],type,endCHS[3],start,length exFAT: 1,0,0x4,0x1,0x4,0x7,0xFE,0xC2,0xFF,2048,241657856 pt_#0: 2,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0 pt_#0: 3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0 pt_#0: 4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0 < unused area starting at: 241659904 length 1011 > Device Info: connected: 1 initialized: 1 USB Vendor ID: 0951 USB Product ID: 1666 HUB Number: 0 HUB Port: 0 Device Address: 1 Removable Device: YES VendorID: Kingston ProductID: DataTraveler 3.0 RevisionID: Version: 6 Sector Count: 241660915 Sector size: 512 Disk Capacity: 123730388480 Bytes >>USBDrive::printPartionTable Partition Table part,boot,bgnCHS[3],type,endCHS[3],start,length exFAT: 1,0,0x4,0x1,0x4,0x7,0xFE,0xC2,0xFF,2048,241657856 pt_#0: 2,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0 pt_#0: 3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0 pt_#0: 4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0 < unused area starting at: 241659904 length 1011 > Volume name: 128GEXFAT Volume type: FAT64 Cluster Size: 131072 bytes Volume size: 123723579392 bytes Space used: 33292288 bytes (90 ms to compute) Files: 2019-01-01 08:15 32767488 32MEGfile.dat 2023-01-01 00:00 36 test.txt
The drive is formatted to EXFAT. Arduino 1.8.19, TD1.58B3. I think there is another problem here. Going back to Linux to see if I can duplicate the problem there.Code:Waiting for Drive to initialize... Device Info: connected: 1 initialized: 0 USB Vendor ID: 0000 USB Product ID: 0000 HUB Number: 0 HUB Port: 0 Device Address: 0 Removable Device: NO VendorID: ProductID: RevisionID: Version: 0 Sector Count: 0 Sector size: 0 Disk Capacity: 0 Bytes Volume name: 128GEXFAT Volume type: FAT64 Cluster Size: 131072 bytes Volume size: 123723579392 bytes Space used: 33292288 bytes (91 ms to compute) Files: 2019-01-01 08:15 32767488 32MEGfile.dat 2023-01-01 00:00 36 test.txt
Time for bed...
Quick note, I picked up my delivery of 4 of the Sanddisk ulta Flair 32gbs...
Looks more or less identical to what @mjs513 showed yesterday...
I did also try reformatting it on PC to FAT32 and no differences. MTP does not want to write a new file to it.
Note: I am running the simplified MTP with USB... sketchCode:14204 RESP:2001(RSP:OK)l: 12 T:2b loop:14204 CMD: 9803(GET_OBJECT_PROP_VALUE)l: 20 T:2c : 10 dc44 (NAME) 14204 RESP:2001(RSP:OK)l: 12 T:2c loop:26649 CMD: 100c(SEND_OBJECT_INFO)l: 20 T:2d : 20001 ffffffff SendObjectInfo: 20001 ffffffff Dataset len=162 File "annie1.bmp" size:230454 Created:641aea58 Modified:61e3a02e read consumed all data (TODO: how to check ZLP) checkConnectedInitialized()msWriteBlocks() msDoCommand() USBDrive CallbackOut (static) transfer->qtd.token = 0 USBDrive dataOut (static)31 55 53 42 43 0E 00 00 00 00 02 00 00 00 00 0A 2A 00 00 00 80 20 00 00 01 00 00 00 00 00 00 00 USBDrive CallbackOut (static) transfer->qtd.token = 0 USBDrive dataOut (static)512 55 53 42 43 0F 00 00 00 00 02 00 00 00 00 0A 2A 00 00 00 80 20 00 00 01 00 00 00 00 00 00 00 00 msGetCSW() USBDrive CallbackIn (static) transfer->qtd.token = 64 USBDrive dataIn (static): 0 ERROR Followup msProcessError() CSW Tag Error: 253 msProcessError() CSW Tag Error: 253 checkConnectedInitialized()msWriteBlocks() msDoCommand() USBDrive CallbackOut (static) transfer->qtd.token = 0 USBDrive dataOut (static)31 55 53 42 43 0F 00 00 00 00 02 00 00 00 00 0A 2A 00 00 00 80 20 00 00 01 00 00 00 00 00 00 00 USBDrive CallbackOut (static) transfer->qtd.token = 65 USBDrive dataOut (static)0 ERROR Followup msGetCSW()
EDIT: the error code: CSW Tag Error: 253
Code://------------------------------------------------------- // Start/Stop unit on hold for now. Not all devices respond to it // the same way. Is it really needed for most devices? Not understanding // it's use. Am able to to plug in a CDROM and load or eject the media. // But that's all that works consistently with drives:( // msResult = msStartStopUnit(1); // 0 = transition to stopped power contition // 1 = transition to active power contition // 2 = load media, tested on SATA CDROM // 3 = eject media, Tested on SATA CDROM msDriveInfo[device].connected = true; // Device connected. msDriveInfo[device].initialized = true; msDriveInfo[device].hubNumber = mscDrives[device]->getHubNumber(); // Which HUB. msDriveInfo[device].hubPort = mscDrives[device]->getHubPort(); // Which HUB port. msDriveInfo[device].deviceAddress = mscDrives[device]->getDeviceAddress(); // Which HUB. msDriveInfo[device].idVendor = mscDrives[device]->getIDVendor(); // USB Vendor ID. msDriveInfo[device].idProduct = mscDrives[device]->getIDProduct(); // USB Product ID. msResult = getDriveInquiry(device); msResult = getDriveCapacity(device); // if device is not like hard disk, probably won't work! example CDROM... if (msDriveInfo[device].inquiry.DeviceType != 0) return MS_CSW_TAG_ERROR; //-------------------------------------------------------
Last edited by KurtE; 03-22-2023 at 06:59 PM.
@kurtE - @wwatson
Interesting - wondering what version I am running since I am seeing this:
which is totally different than what you have.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; // Retrieve drive information. msDriveInfo.initialized = true; msDriveInfo.hubNumber = getHubNumber(); // Which HUB. msDriveInfo.hubPort = getHubPort(); // Which HUB port. msDriveInfo.deviceAddress = getDeviceAddress(); // Device addreess. msDriveInfo.idVendor = getIDVendor(); // USB Vendor ID. msDriveInfo.idProduct = getIDProduct(); // USB Product ID. msResult = msDeviceInquiry(&msInquiry); // Config Info. if(msResult) return msResult; msResult = msReadDeviceCapacity(&msCapacity); // Size Info. if(msResult) return msResult; memcpy(&msDriveInfo.inquiry, &msInquiry, sizeof(msInquiryResponse_t)); memcpy(&msDriveInfo.capacity, &msCapacity, sizeof(msSCSICapacity_t)); return msResult; }
@mjs513 @KurtE - Just got my drive and tested. Same results as you guys. Going to start walking back through the different versions of TD to see if anything changes. Beings how this only seems to happen with these drives I am really curious as to why I am seeing this:
Normally the qtd.token = 0 and datain should = 13. Stumped at this pointCode:msGetCSW() USBDrive CallbackIn (static) transfer->qtd.token = 64 USBDrive dataIn (static): 0 ERROR Followup msProcessError() CSW Tag Error: 253 msProcessError() CSW Tag Error: 253 Writing to test.txt...checkConnectedInitialized() msReadBlocks() msDoCommand() USBDrive CallbackOut (static) transfer->qtd.token = 0 USBDrive dataOut (static)31 55 53 42 43 0F 00 00 00 00 02 00 00 80 00 0A 28 00 00 00 00 3E 00 00 01 00 00 00 00 00 00 00
More testing needed...
Ok, have narrowed it down to a failed command error. Bit 0 is set in the CSW status byte. Possibly a command not recognized by the USB stick. See below:
Done for tonight...Code:msWriteBlocks() msDoCommand() USBDrive CallbackOut (static) transfer->qtd.token = 0 USBDrive dataOut (static)31 55 53 42 43 0F 00 00 00 00 02 00 00 00 00 0A 2A 00 00 00 72 C0 00 00 01 00 00 00 00 00 00 00 USBDrive CallbackOut (static) transfer->qtd.token = 0 USBDrive dataOut (static)512 41 33 00 32 00 4D 00 45 00 47 00 0F 00 0F 66 00 69 00 6C 00 65 00 2E 00 64 00 00 00 61 00 74 00 msGetCSW() USBDrive CallbackIn (static) transfer->qtd.token = 64 USBDrive dataIn (static): 0 ERROR Followup StatusBlockWrapper.DataResidue = 0 msProcessError() CSW Tag Error: 253 CSWResult: fd CD:2a msProcessError() CSW Tag Error: 253
Edit:
Code:bCSWStatus: bCSWStatus indicates the success or failure of the command. The device shall set this byte to zero if the command completed successfully. A non-zero value shall indicate a failure during command execution according to the following table
Last edited by wwatson; 03-23-2023 at 02:31 AM. Reason: More Info...
Any luck on this yet?
I will try to take another look soon. Right now doing fun things like: cutting Himalayan Berry vines out and chipping them.
Not yetJust got home from work. Will play a little more tonight. Looks like I am going to have to got into the lowest levels. Try a single sector write and see what happens. It's complaining about an unrecognized CBW command, I just don't know what it is yet...
Hopefully those vines are not like blackberry vines that cut you to shreds![]()
Not yetJust got home from work. Will play a little more tonight. Looks like I am going to have to go into the lowest levels. Try a single sector write and see what happens. It's complaining about an unrecognized CBW command, I just don't know what it is yet...
Hopefully those vines are not like blackberry vines that cut you to shreds![]()
Last edited by wwatson; 03-23-2023 at 10:11 PM. Reason: Typos...
@KurtE and @mjs513 - Referring to post #664, the command code is indeed the SCSI write(10) command, Instead of showing the tag error first I need to check the CSW status byte bit 0 first and if not 0 do a request for additional sense code(s). These gives more detail about what went wrong.
If you look here you will see that there are quite a few different write commands. Maybe the device is using one of them. Not sure yet...
Yes those are the ones. The ones that grow maybe near an inch wide, and maybe 50' long, with long sharp thorns...
These gloves help: https://www.amazon.com/Leather-Cowhi...dp/B08V5MFC9Q/
Will play some today.
Good Morning All
Was curious how the problematic drive behaved on windows vs one of my microcenter ones that work fine with USBHost.
Test 1. Copied the same files from the PC to each drive.
Image 1: UAM6 - start of copying files:
Image2: Microcenter 64gb drive
Looking at the Wireshark data I really didn't see a difference. But may help to debug whats going on with mass storage.
@wwatson - @KurtE
loaded the wireshark files up on google will send you all the invitation
ee1 - UAM when first inserted into PC - look for 1.20.x addresses
ee2 - UAM copying files from PC to drive
ff1 - micro center 64gb drive inserted into pc - look for 1.21.x addresses
ff2 - copying files from pc to drive
Will have to take a look at those.
But first I am curious about the failure:
The first data out of 31 bytes, came back on callback OUT with the QTD.token = 0Code:File "annie3 - Copy.bmp" size:230454 Created:641d6f21 Modified:61e3a02e read consumed all data (TODO: how to check ZLP) checkConnectedInitialized()msWriteBlocks() msDoCommand() USBDrive CallbackOut (static) transfer->qtd.token = 0 USBDrive dataOut (static)31 55 53 42 43 0E 00 00 00 00 02 00 00 00 00 0A 2A 00 00 00 80 20 00 00 01 00 00 00 00 00 00 00 USBDrive CallbackOut (static) transfer->qtd.token = 0 USBDrive dataOut (static)512 55 53 42 43 0F 00 00 00 FC 00 00 00 80 00 06 03 00 00 00 FC 00 00 00 00 00 00 00 00 00 00 00 00 msGetCSW() USBDrive CallbackIn (static) transfer->qtd.token = 64 800D8140 USBDrive dataIn (static): 0 ERROR Followup msGetCSW TAG_ERROR: sig:53425355 Tag:0 DR:0 ST:0 msProcessError() CSW Tag Error: 253 msRequestSense() msDoCommand() USBDrive CallbackOut (static) transfer->qtd.token = 0 USBDrive dataOut (static)31
Where the RED one was 512 bytes and callback was on the IN, with the last byte of QTD of 64.
I also printed out the whole QTD in hex. So last byte is 0x40 or bit 6 set. Which means:
So I am assuming everything after this is garbage.Halted. Set to one by the Host Controller during status updates to indicate that a
serious error has occurred at the device/endpoint addressed by this qTD. This
can be caused by babble, the error counter counting down to zero, or reception
of the STALL handshake from the device during a transaction. Any time that a
transaction results in the Halted bit being set to a one, the Active bit is also set to
zero.
EDIT: forgot to mention, that in the with the full QTX token: 800D8140
bits 16-30 are how many bytes left to transfer
So that is: D (13 bytes left)
Bits: 8-9 are the PID Code which is: 01 (IN Token generates token (69H) )
Bits 10-11 is the count down error count: 00
12-14 is current page: 0
15 is interrupt on completion: 1
Last edited by KurtE; 03-24-2023 at 07:44 PM.
@KurtE
That makes sense. 13 bytes is the size of the CSW and probably why we are seeing:EDIT: forgot to mention, that in the with the full QTX token: 800D8140
bits 16-30 are how many bytes left to transfer
So that is: D (13 bytes left)
Bits: 8-9 are the PID Code which is: 01 (IN Token generates token (69H) )
Bits 10-11 is the count down error count: 00
12-14 is current page: 0
15 is interrupt on completion: 1
I think. But why...Code:USBDrive dataIn (static): 0 ERROR Followup
Missing something. Working on that right now.
@KurtE @mjs513 - A little progressI have stooped to single sector reads and writes. Here is a sketch that appears to be working:
This is writing "this is a test." to sector 1000000. Obviously will destroy any data in that sector. It started out by accidentally uploading this sketch without the drive plugged in. Noticed that and plugged in the SanDisk drive. It worked. It would continuously write to the sector with each key press without error. This was the first clue that it was a init problem. Something missing or something that should not be there for this drive. So I started eliminating delays and other initializations and wound up with the above test.Code:#include <Arduino.h> #include "USBHost_t36.h" // For this sketch we need to define USE_EXTENAL_INIT in // MassStorage.h. Explained there. USBHost myusb; USBHub hub1(myusb); USBHub hub2(myusb); USBHub hub3(myusb); USBHub hub4(myusb); USBDrive msDrive1(myusb); USBDrive msDrive2(myusb); // Instances for accessing the files on each drive USBFilesystem drv1(myusb); USBFilesystem drv2(myusb); USBDrive *drive_list[] = {&msDrive1, &msDrive2}; char sbuff[256]; // readLine buffer. uint8_t cbuff[512]; // Fill sector buffer with a uint8_t char. void fillBuff(uint8_t fillChar) { } // A small hex dump function void hexDump(const void *ptr, uint32_t len) { uint32_t i = 0, j = 0; uint8_t c=0; const uint8_t *p = (const uint8_t *)ptr; Serial.printf("BYTE 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n"); Serial.printf("---------------------------------------------------------\n"); for(i = 0; i <= (len-1); i+=16) { Serial.printf("%4.4lx ",i); for(j = 0; j < 16; j++) { c = p[i+j]; Serial.printf("%2.2x ",c); } Serial.printf(" "); for(j = 0; j < 16; j++) { c = p[i+j]; if(c > 31 && c < 127) Serial.printf("%c",c); else Serial.printf("."); } Serial.printf("\n"); } } // A simple read line function. char *readLine(char *s) { char *s1 = s; int c; for(;;) { while(!Serial.available()); switch(c = Serial.read()) { case 0x08: if(s == s1) break; s1--; Serial.printf("%c%c%c",c,0x20,c); break; case '\n': case '\r': Serial.printf("%c",c); *s1 = 0; return s; default: if(c <= 0x7E) Serial.printf("%c",c); *s1++ = c; break; } } } void setup(void) { while(!Serial); Serial.printf("%cSandisk ultra Dual USB drive 3.0 Testing\n",12); // Init USBHost myusb.begin(); myusb.Task(); } void loop(void) { uint8_t rslt = 0; Serial.printf("press enter to test...\n"); readLine(sbuff); Serial.printf("\nWriting: 'this is a test.' to sector: 1000000\n"); rslt = msDrive1.msWriteBlocks((uint32_t)1000000, (uint16_t)1, (uint16_t)512, (const char *)"this is a test."); Serial.printf("rslt = %d\n",rslt); Serial.printf("\nReading sector:10000000 to cbuff\n"); rslt = msDrive1.msReadBlocks((uint32_t)1000000, (uint16_t)1, (uint16_t)512, cbuff); Serial.printf("rslt = %d\n",rslt); hexDump(cbuff,16); Serial.printf("\nClearing buffer\n"); for(uint32_t i = 0; i < 512; i++) cbuff[i] = 0; rslt = msDrive1.msWriteBlocks((uint32_t)1000000, (uint16_t)1, (uint16_t)512, cbuff); rslt = msDrive1.msReadBlocks((uint32_t)1000000, (uint16_t)1, (uint16_t)512, cbuff); hexDump(cbuff,16); }
Output:
Just press enter key to repeat. It does a hex dump of the buffer and then clears the buffer and zeros the sector. I have not gone any further with testing. I think the problems might be initialization.Code:Sandisk ultra Dual USB drive 3.0 Testing press enter to test... Writing: 'this is a test.' to sector: 1000000 rslt = 0 Reading sector:10000000 to cbuff rslt = 0 BYTE 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F --------------------------------------------------------- 0000 74 68 69 73 20 69 73 20 61 20 74 65 73 74 2e 00 this is a test.. Clearing buffer BYTE 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F --------------------------------------------------------- 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ press enter to test...
Please test if you can.