rrivirr / rriv

GNU General Public License v3.0
1 stars 9 forks source link

Implement USB Mass Storage for SDCard #105

Open ZavenArra opened 1 year ago

ZavenArra commented 1 year ago

We want to plug the WaterBear into a computer over USB, and see the SDCard mount as a filesystem drive.

To achieve this in USB, it is necessary to implement the USB Mass Storage protocol. Our MCU, the STM32F103RB, has an on-chip USB controller, and the core we are using (https://github.com/rogerclarkmelbourne/Arduino_STM32/) includes a USB library, called USBComposite which has a device defined for implementing USB Mass Storage (https://github.com/rogerclarkmelbourne/Arduino_STM32/tree/master/STM32F1/libraries/USBComposite - see the README on this page for details)

The is an example code: https://github.com/rogerclarkmelbourne/Arduino_STM32/tree/master/STM32F1/libraries/USBComposite/examples/mass Which has been experimented with: https://github.com/ZavenArra/rriv/tree/usb_attempt

However, it is not fully functional.

First, the USB Mass Storage device does not completely mount. Probing with CLI commands like lsusb, usb-devices, lsblk, and dmesg | grep -i USB shows that the USB Mass Storage device is present, but the driver is not found in linux. It is unclear if this is a device side error (incomplete identification to the computer), or if there is a driver missing on the computer. Testing on different computers may help address this issue, or further profiling of the issue may be necessary.

https://forum.manjaro.org/t/external-usb-drives-not-an-mtp-device/74781 https://superuser.com/questions/1206664/disable-mtp-udev-rules-for-specific-device-so-it-can-be-mount-as-a-usb-mass-stor

Second, the mass storage device example is just implemented for access to in memory data. The bindings to the SDFat library need to be implemented in order to expose the SDCard as a block device when mounted over USB as a USB Mass Storage device.