Go Down

Topic: SD card storage using the HSMCI interface (Read 3888 times) previous topic - next topic


Has anyone ever had success testing the HSMCI (High Speed Memory Card) interface with the Arduino Due board?

I'm currently implementing a custom board based on the SAM3X8E processor used in the Due and I'm planning to use the HSMCI interface for SD card storage.  Right now I'm trying to do some software testing using an Arduino Due with an SD card connected to the HSCMI interface pins.  All the necessary signals except for MCDA0 are available on the headers.  MCDA0 is available by soldering to the TXLED.

So far I have attempted to get this working by using the Atmel Software Framework examples in Atmel Studio 6, and then using bossac.exe to flash the board.

The closest to success that I have achieved so far is to start with the "SD/MMC/SDIO Card FatFs Example - SAM3X-EK" project.  That project is intended for Atmel's SAM3X-EK demo board, so it uses the SAM3X8H processor instead of the SAM3X8E processor as used in the Due.  I was able to change the device to the SAM3X8E in the project settings, then modify the board definition file so that the Card Detect pin uses a pin available on the Due, and get the project to compile and load.

With this project compiled and loaded, I can see the MCCK (clock) pin creating a square wave, and I can see some brief pulses on the MCCDA (command) pin, but the initialization process still fails, unable to communicate with the SD card.

My alternate approach was to start with an example project created for the Due specifically, and then use the ASF wizard to add the necessary files to match the SD example project.  Although I can get that version to compile, load, and run, the clock pin never toggles nor does the command pin.  It seems like for some reason the PIO is not correctly configuring those pins for HSMCI usage in that case.

Anyway, that's enough background to understand what I have tried so far.  Has anyone else ever attempted to use the HSCMI interface with a Due board and had success?

Thanks so much in advance for any help or suggestions!


PS - Before working with Atmel Studio and the ASF, I tried quite a lot to copy the relevant code into Arduino sketch files and compile within the IDE version 1.5.2, but I had absolutely no success getting it to compile as it could never seem to find the definitions and functions used in the ASF, even though I believe that most of those definition files should be part of the Arduino Due core library...

PPS - I am aware that there is a SPI interface SD library available for the Arduino Due.  That was my plan A, but unfortunately I'm also using some SPI ADC chips that require precise timing for a fast control loop and therefore I can't tolerate the delays from the block writes over a shared SPI bus.  If there are other alternatives (like software SPI to separate the SD vs. ADC busses, etc), I'm all ears!


Writing the post above made me think through the problem a bit more, so I decided to do a little bit more hardware debugging.

When I probed the command signal along with the clock signal, I could see the command sent by the processor as well as the response from the card.  However, after the card response, the command signal slowly drifted from 3.3V down towards ground, so I realized that I was missing a required pullup resistor on the MCCDA signal.  After adding a 10k pullup to 3.3V, the test writes to the SD card finally worked!!

However, I'm not out of the woods yet.  I have a fairly large sketch already running on the Due, and I need to integrate this HSMCI code with the sketch.  So, I'm still very interested in any suggestions about the best way to integrate Atmel ASF based code with the Arduino IDE code.  As I mentioned in my earlier post, when I started with an ASF example project specifically intended for the Due, the clock and command output pins were never active, even when the HSMCI->HSMCI_CMDR register write occurred.  It seems that something is wrong with the PIO settings when I try to integrate the SD card example project with the Arduino Due board configuration.

Thanks again!



This is by no means a proper Arduino library with examples, etc, but user Palliser requested a follow up with the code I used to get the HSMCI interface to an SD card working.

I have attached a zip file with the SdFatHsmci "library" that I used and a simple test program HSMCI_test.  This was created based on the HSMCI example projects from the Atmel Studio Atmel Software Framework and modifying as necessary to get the code to compile and run correctly in the Arduino IDE.  It was awhile ago when I did this work, but I believe that the primary code modifications had to do with eliminating some of the calls related to RTC (real time clock) functions that were not supported in my hardware setup.

I hope this is helpful to someone.




Hello Dominic and thank you for the files. I will be testing your sample and keep posting how it goes.




I am new to memory card interfacing and would like to know some basics regarding MMC cards. FIrst of all I will be using the SPI interface to communicate with an eMMC card. I have found out through some research over the internet that only one data line DAT0 can be used to receive data from the eMMC by connecting it to SPI MISO and CMD can be used to send data to eMMC by connecting it to SPI MOSI. Is this information correct? If so, can someone please guide me to further details related to this matter.
Thanks in advance.


P.S. I am using SAM4S16C which also has HSMCI but according to my requirement I need to use SPI.


Hello folks,

I was wondering if there has been any progress in this topic. I am also trying to work with SD card in SD mode on a SAM4S, So far I have successfully initialized bot the HSMCI and SD cards in SD mode now what I need is to test the read and write operation of the card in order to make sure everything is working properly. I am working on Atmel Studio and I tend not to use any of the ASF stuff so I am trying to make a completely custom project from scratch and then including the necessary files like HSMCI.c & HSMCI.h as well as sd_mmc_protocol.h file as a starting point. Please let me know if anyone has successfully done this before or is doing it now. Any help and suggestion would be appreciated.



Hey there, wondering if anyone has been able to get this "HSMCI_test.zip" code to compile with 1.6.8?

I get this error using: Arduino: 1.6.8 (Windows 7), Board: "Arduino Due (Native USB Port)"

too few arguments to function 'FRESULT f_open(FIL*, const TCHAR*, BYTE, int, int, int, int, int, int)'


Hello rocketjosh,

DominicG's sample sketch/library (HSMCI_test) runs OK but only in the IDE 1.5.6-r2 (at least for me).
Remember that this is an old code but it permits read/write an SD card very fast. I have run it with good results on a 32GB Kingston class 4 SDHC.

Do you really need hs reading your SD card? I wouldn't recommend you messing with this library. It is very raw. Why don't use an SDCard on SPI? There is already a lot of support available for this solution in the Arduino library and this forum. Regards.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131