Managed to get at least file read to work (very crude implementation without error checking) but it is very slow compared to the original one. Need to figure out if this is caused by the USB handling or the SD card reading.
Since high speed USB with bulk endpoints works with 512 bytes and the SD card sector size is also that I made my implementation such that it only reads one sector per USB IN transaction, and I think that the original code reads all the requested sectors in one swoop to a big buffer. So I have to try that and see if it makes a difference.
Monitored the transfer for both with wireshark and the difference is significant. >2.3S versus <0.1S
This is a capture from the original scope. Second column is the time indication.
1423 18.279385 host 1.18.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x0000c660, Len: 240)
1424 18.279399 1.18.1 host USB 64 URB_BULK out
1425 18.279435 host 1.18.1 USB 64 URB_BULK in
1426 18.290936 1.18.1 host USBMS 122944 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1427 18.290982 host 1.18.1 USB 64 URB_BULK in
1428 18.291015 1.18.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1429 18.291098 host 1.18.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x0000c750, Len: 16)
1430 18.291145 1.18.1 host USB 64 URB_BULK out
1431 18.291180 host 1.18.1 USB 64 URB_BULK in
1432 18.292487 1.18.1 host USBMS 8256 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1433 18.292525 host 1.18.1 USB 64 URB_BULK in
1434 18.292562 1.18.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1435 18.292895 host 1.18.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x0000c760, Len: 240)
1436 18.292906 1.18.1 host USB 64 URB_BULK out
1437 18.292946 host 1.18.1 USB 64 URB_BULK in
1440 18.304417 1.18.1 host USBMS 122944 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1441 18.304462 host 1.18.1 USB 64 URB_BULK in
1442 18.304477 1.18.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1443 18.304554 host 1.18.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x0000c850, Len: 16)
1444 18.304563 1.18.1 host USB 64 URB_BULK out
1445 18.304569 host 1.18.1 USB 64 URB_BULK in
1446 18.305946 1.18.1 host USBMS 8256 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1447 18.305979 host 1.18.1 USB 64 URB_BULK in
1448 18.306014 1.18.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1449 18.306096 host 1.18.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x0000c860, Len: 240)
1450 18.306106 1.18.1 host USB 64 URB_BULK out
1451 18.306145 host 1.18.1 USB 64 URB_BULK in
1452 18.317644 1.18.1 host USBMS 122944 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1453 18.317676 host 1.18.1 USB 64 URB_BULK in
1454 18.317685 1.18.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1455 18.317752 host 1.18.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x0000c950, Len: 16)
1456 18.317800 1.18.1 host USB 64 URB_BULK out
1457 18.317844 host 1.18.1 USB 64 URB_BULK in
1458 18.319139 1.18.1 host USBMS 8256 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1459 18.319173 host 1.18.1 USB 64 URB_BULK in
1460 18.319211 1.18.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1461 18.319297 host 1.18.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x0000c960, Len: 240)
1462 18.319307 1.18.1 host USB 64 URB_BULK out
1463 18.319345 host 1.18.1 USB 64 URB_BULK in
1464 18.330856 1.18.1 host USBMS 122944 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1465 18.330911 host 1.18.1 USB 64 URB_BULK in
1466 18.330948 1.18.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1467 18.331002 host 1.18.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x0000ca50, Len: 16)
1468 18.331022 1.18.1 host USB 64 URB_BULK out
1469 18.331026 host 1.18.1 USB 64 URB_BULK in
1470 18.332387 1.18.1 host USBMS 8256 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1471 18.332393 host 1.18.1 USB 64 URB_BULK in
1472 18.332460 1.18.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1473 18.332477 host 1.18.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x0000ca60, Len: 240)
1474 18.332528 1.18.1 host USB 64 URB_BULK out
1475 18.332533 host 1.18.1 USB 64 URB_BULK in
1476 18.344028 1.18.1 host USBMS 122944 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1477 18.344086 host 1.18.1 USB 64 URB_BULK in
1478 18.344133 1.18.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1479 18.344189 host 1.18.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x0000cb50, Len: 16)
1480 18.344214 1.18.1 host USB 64 URB_BULK out
1481 18.344248 host 1.18.1 USB 64 URB_BULK in
1482 18.345597 1.18.1 host USBMS 8256 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1483 18.345604 host 1.18.1 USB 64 URB_BULK in
1484 18.345659 1.18.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1485 18.345727 host 1.18.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x0000cb60, Len: 240)
1486 18.345738 1.18.1 host USB 64 URB_BULK out
1487 18.345792 host 1.18.1 USB 64 URB_BULK in
1488 18.357253 1.18.1 host USBMS 122944 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1489 18.357300 host 1.18.1 USB 64 URB_BULK in
1490 18.357307 1.18.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1491 18.357363 host 1.18.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x0000cc50, Len: 43)
1492 18.357373 1.18.1 host USB 64 URB_BULK out
1493 18.357427 host 1.18.1 USB 64 URB_BULK in
1494 18.359918 1.18.1 host USBMS 22080 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1495 18.359929 host 1.18.1 USB 64 URB_BULK in
1496 18.359955 1.18.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
This is a capture from my code
1473 37.161925 host 1.17.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x000110c0, Len: 240)
1474 37.161974 1.17.1 host USB 64 URB_BULK out
1475 37.162023 host 1.17.1 USB 64 URB_BULK in
1478 37.518151 1.17.1 host USBMS 122944 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1479 37.518224 host 1.17.1 USB 64 URB_BULK in
1480 37.518299 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1481 37.518440 host 1.17.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x000111b0, Len: 16)
1482 37.518488 1.17.1 host USB 64 URB_BULK out
1483 37.518542 host 1.17.1 USB 64 URB_BULK in
1484 37.546236 1.17.1 host USBMS 8256 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1485 37.546310 host 1.17.1 USB 64 URB_BULK in
1486 37.546372 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1487 37.547731 host 1.17.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x000111c0, Len: 240)
1488 37.547798 1.17.1 host USB 64 URB_BULK out
1489 37.547857 host 1.17.1 USB 64 URB_BULK in
1490 37.904446 1.17.1 host USBMS 122944 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1491 37.904558 host 1.17.1 USB 64 URB_BULK in
1492 37.904623 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1493 37.904795 host 1.17.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x000112b0, Len: 16)
1494 37.904831 1.17.1 host USB 64 URB_BULK out
1495 37.904851 host 1.17.1 USB 64 URB_BULK in
1496 37.932611 1.17.1 host USBMS 8256 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1497 37.932640 host 1.17.1 USB 64 URB_BULK in
1498 37.932652 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1499 37.932763 host 1.17.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x000112c0, Len: 240)
1500 37.932820 1.17.1 host USB 64 URB_BULK out
1501 37.932877 host 1.17.1 USB 64 URB_BULK in
1520 38.289367 1.17.1 host USBMS 122944 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1521 38.289441 host 1.17.1 USB 64 URB_BULK in
1522 38.289468 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1523 38.289631 host 1.17.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x000113b0, Len: 16)
1524 38.289645 1.17.1 host USB 64 URB_BULK out
1525 38.289657 host 1.17.1 USB 64 URB_BULK in
1532 38.317430 1.17.1 host USBMS 8256 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1533 38.317488 host 1.17.1 USB 64 URB_BULK in
1534 38.317502 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1535 38.317612 host 1.17.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x000113c0, Len: 240)
1536 38.317626 1.17.1 host USB 64 URB_BULK out
1537 38.317638 host 1.17.1 USB 64 URB_BULK in
1628 38.674216 1.17.1 host USBMS 122944 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1629 38.674310 host 1.17.1 USB 64 URB_BULK in
1630 38.674337 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1631 38.674464 host 1.17.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x000114b0, Len: 16)
1632 38.674479 1.17.1 host USB 64 URB_BULK out
1633 38.674502 host 1.17.1 USB 64 URB_BULK in
1640 38.702252 1.17.1 host USBMS 8256 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1641 38.702326 host 1.17.1 USB 64 URB_BULK in
1642 38.702341 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1643 38.702457 host 1.17.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x000114c0, Len: 240)
1644 38.702472 1.17.1 host USB 64 URB_BULK out
1645 38.702484 host 1.17.1 USB 64 URB_BULK in
1722 39.059089 1.17.1 host USBMS 122944 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1723 39.059195 host 1.17.1 USB 64 URB_BULK in
1724 39.059258 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1725 39.059427 host 1.17.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x000115b0, Len: 16)
1726 39.059463 1.17.1 host USB 64 URB_BULK out
1727 39.059474 host 1.17.1 USB 64 URB_BULK in
1730 39.087230 1.17.1 host USBMS 8256 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1731 39.087261 host 1.17.1 USB 64 URB_BULK in
1732 39.087272 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1733 39.087376 host 1.17.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x000115c0, Len: 240)
1734 39.087398 1.17.1 host USB 64 URB_BULK out
1735 39.087412 host 1.17.1 USB 64 URB_BULK in
1736 39.443931 1.17.1 host USBMS 122944 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1737 39.444045 host 1.17.1 USB 64 URB_BULK in
1738 39.444121 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
1739 39.444293 host 1.17.1 USBMS 95 SCSI: Test Unit Ready LUN: 0x00
1740 39.444317 1.17.1 host USB 64 URB_BULK out
1741 39.444327 host 1.17.1 USB 64 URB_BULK in
1742 39.444362 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Test Unit Ready) (Good)
1743 39.444519 host 1.17.1 USBMS 95 SCSI: Read(10) LUN: 0x00 (LBA: 0x000116b0, Len: 10)
1744 39.444543 1.17.1 host USB 64 URB_BULK out
1745 39.444553 host 1.17.1 USB 64 URB_BULK in
1746 39.461909 1.17.1 host USBMS 5184 SCSI: Data In LUN: 0x00 (Read(10) Response Data)
1747 39.461939 host 1.17.1 USB 64 URB_BULK in
1748 39.461950 1.17.1 host USBMS 77 SCSI: Response LUN: 0x00 (Read(10)) (Good)
So they got one thing right
![Smiley :)](https://www.eevblog.com/forum/Smileys/default/xsmiley.gif.pagespeed.ic.R8GFI-pF6f.png)
but when I open an image from this mass storage device the scope hangs, so on the other hand they messed something up
![Laughing :-DD](https://www.eevblog.com/forum/Smileys/default/smiley_laughing.gif.pagespeed.ce._hfWAz_QHO.gif)
My version still needs the write command implemented to be able to un-mount the drive when it needs a write back. At least there is progress again.
Edit: Modified the code to read from the SD card into a bigger buffer and it is the solution for the speed. It shows the same speed as the original. So quite a lot of overhead in reading a single sector from the SD card. With the USB mass storage only active when enabled by the user and blocking the rest of the scope code, allows for using the 400000 byte buffer the code has for loading the thumbnail files when viewing pictures or wave files on the scope itself.
![Smiley :)](https://www.eevblog.com/forum/Smileys/default/xsmiley.gif.pagespeed.ic.R8GFI-pF6f.png)
My version does not hang, at least with the code I have working now.