Arduino Forum

Products => MKR Boards => MKRZero => Topic started by: bertmad3400 on Aug 11, 2018, 02:20 pm

Title: Emulate usb storage device using MKRZero
Post by: bertmad3400 on Aug 11, 2018, 02:20 pm
I'm using an Arduino MKRZero and an sd card using the built-in sd card reader in the MKRZero. My question is if it's possible to use the MKRZero with an sd card to emulate an usb storage device? The point of this is to be able to copy a file directly from the MKRZero without having to pull out the sd card and plug it into my computer.

Is there any way to do this?
I'm already looking into usb client drivers and other types of device driver so i would prefer to solve this problem in another way but if you have a specific way of doing it using drivers please let me know
Title: Re: Emulate usb storage device using MKRZero
Post by: evi7538 on Sep 08, 2018, 10:02 pm
Hi, I'm also interested in this but for another purpose: I need a fast data transfer rate from MKRZero to PC, at least 1mbit/s. I'm currently using Serial communication but Serial max datarate seems to be limited to 256kbit/s (because of the serial port throughput limitation of Win Api on the PC side). USB HID is also not fast enough for this. So I need to switch MKRZero to USB CDC or MSC communication mode. There is a way to program MKRZero for a USB class communication through Atmel Studio using their ASF library:

http://ww1.microchip.com/downloads/en/AppNotes/Atmel-42343-USB-Device-Interface-UDI-for-Mass-Storage-Class-MSC_ApplicationNote_AT09338.pdf

http://ww1.microchip.com/downloads/en/AppNotes/Atmel-42343-USB-Device-Interface-UDI-for-Mass-Storage-Class-MSC_ApplicationNote_AT09338.pdf

But I haven't found a way to do that in Arduino IDE.  That means I have to switch to Atmel Studio platform and translate my sketch accordingly. Sadly, because I'm so spoiled by the easiness of Arduino IDE :(

For your application, if you want your device to appear as an external drive on the PC side (like a usb stick), you need to configure it as USB MSC, and face the same issue: do the FW development in Atmel Studio, not Arduino IDE.
Title: Re: Emulate usb storage device using MKRZero
Post by: evi7538 on Sep 08, 2018, 11:30 pm
update: I found a good add-on to Atmel Studio that allows to keep the code in Arduino style so no translation is needed:
https://www.visualmicro.com/page/Arduino-for-Atmel-Studio-7.aspx
Title: Re: Emulate usb storage device using MKRZero
Post by: Juraj on Sep 09, 2018, 07:35 am
this could be an Arduino library for SAMD as Mass Storage https://github.com/markmal/MSD
Title: Re: Emulate usb storage device using MKRZero
Post by: evi7538 on Sep 09, 2018, 03:43 pm
this could be an Arduino library for SAMD as Mass Storage https://github.com/markmal/MSD
Yes, I saw that library, the problem is:
"It is quite slow because SAMD21 supports only Full Speed USB 2.0. So, when you plug this into your Windows computer it may take couple of minutes until it will be accepted by Windows as removable device."
I don't know why he is saying that. In the Atmel appnote AT06475 it says "SAM D21 USB peripheral supports both embedded host and device modes of operation, supporting full speed (12Mbits/s) and low speed (1.5Mbits/s) communication."

And there are bugs and patches...

I tried Atmel Studio with Visual Micro (costs only $30), it is great! I can now use the same Arduino code but the IDE has a lot of handy formatting/editing and debugging tools. It's based on the Visual Studio IDE (which I use and like a lot). And there are libraries and examples in ASF library for USB CDC and MSC that can be integrated into Arduino code. I'm going to try that.