I've made lots of progress.
On OSX, the drive can now "come online," I can view and edit a sample text file I created from the device-side. I can unmount the drive.
You might be wondering, what did I do to fix it?? Although your idea is sound on data toggling, that wasn't it. The problem for me is with the unique aspects of my USB controller ASIC what-have-you,the PDIUSBD12. As you know, when studying a datasheet, it takes time to fully comprehend the complete connection between everything -- well sometimes the datasheet says things that misleads your mind into thinking "OK I don't need to address XYZ," when you really do... That's what happened to me, and right now my solution is sub-optimal. Let me expound :
PDIUSBD12Endpoint 2This endpoint is different from the other endpoints. The other ones which have 16-byte single buffers. EP2 has 64-byte buffer, and is double buffered.. It's advertised as transparent in the datasheet. So I just operated on it the same way I would with my experience from dealing with EP 0 and enumerating the device.. WRONG -- the more I looked thru the datasheet I started realizing the potential importance of this double buffering behaviour.. Especially when I noticed a max-read of 130 bytes (2 extra to account for certain pecularities of the device as listed in datasheet). I felt like the packets were in the controller I just didn't know how to access them.. Then I noticed a command that would tell you if one of the 2 buffers was full.. Transparent my ass.. Just kidding
... The firmware example uses DMA with EP2, which I cannot do, and I can only wonder until I look at it whether it will shine light on how to properly handle -- but for now what I did in a hunch instinct was I moved all of my logic over to the smaller endpoint 1.. Changing some code to adapt for the smaller EP size, and wah-lah!! I proved my hunch! It started working!! And that's how I fixed so far
I hope to in the future attempt a return to EP2's bigger buffer. I can probably figure out how to use it, given instincts and possible firmware documentation [as long as DMA doesn't auto-handle what I will need to handle manually].
And I learned a couple things at this point:
Point 1I need a more dynamic response to TEST UNIT READY instead of just passing good CSW's if I want my "drive" to come back online after a dismount.. or during the OSX format process, which still doesn't complete due to this and possibly other future road blocks.
Point 2If I remount the drive after unmount, the drive will not display the new files I may have added, and the one pre-existing text file is listed as having 0 bytes although the data and the other files raw data can be found in the partition if dumped by raw memory..But I didn't inspect the FAT itself to see if it became messed up. I suspect this is connected to my observation that when OSX mounts my drive, it writes some data to the partition.. off the top of my head I loosely recall it writing "MAC OSX" somewhere after the 1st or 2nd sector and a serial number too.
Summary on these pointsI'm not too concerned with these observations or fixing them directly since I already know I'm not properly implementing the whole required-SCSI command set.. So here's what I've done to admonish that:
Learning from a Real Flash DriveI immediately ran into a problem -- I am implementing a Full Speed product, but most flash drives are high-speed. Purchasing a full-speed product seemed pretty lame as they are rare and shipping is expensive, plus the crappy USB advertising makes it hard to guarantee the proper operation I'm after.. Luckily, I have some USB sticks here, and I prayed one of them may support Full Speed and that I could modify the bus speed from the OS-side..
Reducing 2.0 Bus Speed to Full SpeedI dabbled with virtualization but to no avail (VirtualBox and Windows XP)... although it is said you might be able to disable the 2.0 UHCI [may have the wrong term there] and get it working.. Not for me.... even with vbox extensions installed and USB 2.0 virtual UHCI enabled in V-OS settings... Luckily, I found a solution..
I booted into my Ubuntu 12.04 partition thru Refind [love it] and found some instructions on how to [maybe] be able to change the bus and port speed -- I was warned that my tech has to be old enough to do this. Anyway the instructions are here, and it worked : ) --
http://lists.en.qi-hardware.com/pipermail/discussion/2011-August/008508.html -- I'd love to make a mental note that using dmesg to find the usb bus and port was more intuitive than the output of lsusb, which has a device number which I originally mistakenly used for the port number.. With those instructions I had it working..
I got the TotalPhase USB driver working thru the UDEV instructions found here:
http://www.totalphase.com/support/articles/200472426/#s4.3.1 -- the USB drivers themselves are easily found on totalphase's website..
Analyzing USB Stick at Full SpeedI proceeded to take a number of "snapshots" of different events.. Right now, I have the following:
1_enumerate_and_preload_drive.tdc 1.1M
2_launch_gparted.tdc 765K
3_select_and_unmount_drive.tdc 11M
4_erase_partition_to_unallocated.tdc 3.0M
5_create_msdos_partition_table.tdc 3.6M
6_create_fat16_partition.tdc 6.8M
7_exit_gparted.tdc 908K
8_mount_open_drive_create_file_write_file_unmount.tdc 281K
9_connect_open_drive_open_file_close_file.tdc 1.4M
and to print that output, I just learned / found my own way to do this:
ls -lh | awk '{print $9," ",$5}' | column -t