Go Down

Topic: An example of Arduino Due as an USB host mass storage (Read 38710 times) previous topic - next topic


Yes, my project files are for Atmel Studio 6.1 beta (ASF 3.7.2) You will need to use this version to load the project.

However, for you guys with ASF 3.5.x It's is fairly easy to get the existing ASF USB Host example working.

1) File->New->Example Project From ASF..

2) Select USB Host MSC FatFS and HID mouse example - Arduino Due/X

3) In src/ASF/sam/boards/arduino_due_x/arduino_due_x.h
* Un-define USB_ID_GPIO

4) In src/ASF/sam/boards/arduino_due_x/init.c
* remove the line:
gpio_configure_pin(USB_ID_GPIO, USB_ID_FLAGS);

5) In src/ui.c
* Remove ALL the code from ui_usb_sof_event()

That's all there is to it. it'll work!

If your using ASF 3.7.2 then you also need to replace sleep.c with the code from my previous message.



Hello Travis,

I'm sorry if I'm still here but unfortunately my USB Host doltysen't work again.

Maybe you've also changed the main.c?

When I insert my pen drive into the USB port Host, (obviously not in programming port), nothing
happens and the red led of my pen drive remains off ... I tried with three pen drive.

Now I am trying to download Studio 6.1 with many difficulty because my internet is not very good,
then I'll try to open your demo.

Could you send to me your files. Bin so I can try if my Host USB  works?

my email is darighi@tin.it
Thanks again



Hi, Here me again.
At this point I think I have some problem in my Arduino board, because I installed studio 6.1, compiled your software and installed it on arduino, but it does not work!
Now I think what I can do yet.
thank you very much



Open up a terminal window and set it up for 115200,N,8,1
I use termite:

You should get some output from the debug/programming port:
-- USB HOST HID/MSC Example --
-- Arduino Due/X --
-- Compiled: Apr 20 2013 16:29:49 --

[main]  MAX_DRIVE=8
[main]  Device Attached!
[main]  Sof Detected!

I've also added a pre-compiled version to my downloads:

I've tried a couple different FAT32 formatted flash drives and they both work:

  • Scandisk Cruzer 2GB

  • Kingston DT108 8GB



Travis Hello and thank you for your software.
At the moment I had not success to make it work, no messages is writes inside the pen drive, but I have seen where I might be wrong!
I provide an external 12V power supply and then I insert the Pen Drive but I don't connect the USB cable for serial communication because I have not space since my cable has a connector at 90 degrees and so there is not space to connect it.

By doing so, I saw that the TX LED does not light up so I understand that it doesn't transmit data via serial port, and seems to not work.

If you only connect the serial cable, I see the TX LED light up for a brief period necessary enough to send the serial message but I can't insert the pen drive due to the low space.

Now I wonder: peraphs without the serial cable, arduino stops the execution of the software?

Tomorrow I'll take home from my office a usb cable straight, and try to see if it works.

Best regards and thank for your support.



Yes you are right!  It doesn't work when an external power source is connected.

In src/ASF/sam/boards/arduino_due_x/arduino_due_x.h:

  • Un-define USB_VBOF_GPIO

  • You will also have to remove its gpio_configure_pin() call in init.c

This will make it work with an external power source.  This is probably not the "correct" way to do this.  When I have some more time to play with it I'll look at the schematic and reply back.



Hello Travis,
   finally works! Thank you very much :)

I did not tried the latest changes you suggested to me, but I provided power by USB cable and now writes the file in the pen drive!  Yessss! :)

Really thank you very much and if you come in Italy remember to stop at my house that I offer a pizza or whatever you want :)

If I'll do something of interesting with the Host USB I'll post to you.

Best Regards


Looks like some interesting work on USB host - I've had to put my project aside but interested to try this out at some point.

I believe the USB Host powering on external power has some issues - here is my reading of it, see my posts
I was wondering if there was a place to post this as a bug?


Thank you for your post.
For atmel software framework bug I wrote to atmel but for this bug I don't know where you can post it.
Best regards.


Nice Work :)

When i connect pen drive to native port of Due it is showing Vendor ID and Product id

But when i connect ipod to native port it is not showing anything..

Any idea why it is not showing :(


cause an ipod isn't a genuine USB massstorage device, it's an apple whatever-device.


This topic is one of the most important for practical use, although I can't test it, because I don't have Atmel Studio.

Is there an existing solution/example to be used with arduino IDE?



This topic is one of the most important for practical use, although I can't test it, because I don't have Atmel Studio.

Is there an existing solution/example to be used with arduino IDE?

Yes and no.
There is a "enumerate USB devices on DUE " posted ( about year old ) and no discussion on that.
That is based on "USBHost class" and works, It will identify USB  info on  mouse , keyboard , flash drive and webcam  ( tested so far).
The MSC ASF sample code is a challenge to "port" to DUE. The true ASF code is documented and has a nice debug trace macro.  I got as far as CONFIGURE and cannot get pass detecting end points. ( The header files contents is pretty inconsistent - sometime only #defines, sometime mixture of classes ). So I am going to use the enumerating code to get the USB device to RUNNING state and than add the MSC ( heavilly modified  I expect).  I am still not sure how to actually communicate from DUE to "MSC controller". But again ATmel puts out tons of API (USB)  notes, nice.


May 21, 2015, 10:51 am Last Edit: May 21, 2015, 11:01 am by JuanSalazar
I wanted to share an example from Atmel ASF that shows how to implement a USB host mass storage on Arduino Due with USB module.

I have upload the .bin file in github for those interested to test it. If you want to move forward with this application, I'd recommend to install Atmel Studio 6 with ASF and build/compile the Arduino Due based example called "USB Host MSC FatFS example". I could write a sketch for Arduino IDE but you have to be patient.

For this application you will need:
- Arduino board
- Flash memory card (FAT or FAT32)
- A USB to mini-USB cable
- Bossac.exe in you computer
- Download my HOST_EXAMPLE21.bin file from github

Then, follow these steps:
1. Download the file HOST_EXAMPLE21.bin from this link:

[font=Verdana]1.1.  Download the file HOST_EXAMPLE21.bin attached to this post (EDITED: March-05-2014).[/font]
2. Load HOST_EXAMPLE21.bin to Arduino Due using bossac.exe as follows:

Notice that I am using port 23 because that is the port in my laptop where my Due is connected.

3. After loading HOST_EXAMPLE21.bin in your Due, connect Due to a Flash Memory card (FAT/FAT32 are supported) using the USB-mini USB cable.

4. Finally disconnect the memory stick from Due and read it in your computer. The example creates in your memory card (stick) a file "uhi_msc_test.txt" that contains the text: Arduino Due Rocks!

If you want to create your own file and text you'll find the example in Atmel Studio 6 as follows:
File->New->Example Project from ASF->[Under Kit] Arduino Due X->USB Host MSC FatFS example

Hi Palliser, I read the post, and I'm interested at your arduino due "library" if I can call it in this way, but I read that:
1. It can only be used on SdCard; and I want to use it on USB pens,
2. For using it I must program directly the ARM processor, and I don't have much time to learn how-to-use/program it,
What should I do? I want to simply read/write variable text files on usb pens with my Arduino 2 but without buy an USB Host Shield...
Regards and thanks in advance for the help


Hola Juan,

I must say I am half way to finish my porting of the Atmel ASF example for Due. I just need time to finish it (nowadays I am busy at my work). I hope to have the library and raw example (write/read USB memory stick) ready by the end of this Summer, thus, it is about to wait. Regards,


Go Up