[Solved] USB connection for accessing the SD card from a PC

  • Hi there,

    Is it possible to connect the USB cable of the LeopardBoard to a PC in a way that it detects the SD card as an external drive for accessing the files on it?

    It can really be useful for changing the software or downloading the files on it without removing the SD.

    Any idea?



  • Morteza,

    Thanks for starting a new thread when you change the topic.  Makes it so me more useful for those searching for answers.

    Oddly, host PC accessing files on the SD card via USB is what I working on yesterday.  See,_device_and_OTG_support

  • Hi Todd,

    It seems that you think of what I have in mind even ahead of me!!

    Thanks for the good job.

    Can you shed some light on how this can apply to a LeopardBoard too (Not an EVM)?



  • Thanks Todd,

    I managed to apply your instructions to my Leopard board.

    Here are the steps to mount the SD card on the LeopardBoard as a USB Mass Storage Device.

    1- Run make config

    2- Goto: Kernel configuration>Power management options>  and select  Power Management support [*]

    3- Goto: Kernel configuration>Device Drivers>  [*] USB support>  and put USB Gadget Support to [M] (meaning module selection).

    4- Goto: Kernel configuration>Device Drivers>  [*] USB support>  USB Gadget Support > and select the gadget drivers you need under USB Gadget Drivers as follows:

    • [ ] Audio Gadget for USB Audio Class device
    • [ ] Ethernet Gadget for USB ethernet device
    • [M] File-backed Storage Gadget for mounting SD card as a Storage device on Windows or Linux. (This is the one I am interested in)
    • [ ] Serial Gadget for USB-Serial device
    • ...

    5- Goto: Kernel configuration>Device Drivers> [*] USB support>Inventra Highspeed Dual Role Controller>Driver Mode and set it to USB Peripheral

    6- For some unknown reasons, when you set the USB mode to Peripheral or OTG, USB controller changes and you have to set it back. So goto:  Kernel configuration>Device Drivers>  [*] USB support>  USB Gadget Support > and make sure it is set USB Peripheral Controller to Inventra HDRC USB Peripheral 

    7- Change the jumpers on Leopardboard to Device mode: J1 = open / J4 = 1-2 (This is the default mode from the factory)

    8- make and make install to update the new gadget drivers in your board.

    9- Boot up your Leopardboard and type these:

    modprobe g_file_storage file=/dev/mmcblk0

    It assumes that your SD card is called mmcblk0 (If you do not know it, remove the SD card and Insert it again and your Board will echo back the name)

    10- Connect the USB cable to a PC and Voila! you have your SD card as a storage device.

    If you want to see the list of available Gadget drivers on your LeopardBoard, type:

    cat /lib/modules/2.6.32-17-ridgerun/modules.dep

    All the modules starting with a g_* are gadget drivers.


  • Morteza,

    I have added a link to your instructions.  

    Thanks for contributing back to the community.


  • Todd,

    Do you have any information about USB On the Go (OTG) on LeopardBoard?

    I need to know the way to enable it using jumpers or even by some hardware changes on the board.



  • Hi Morteza,

    Please download the TI DM365 EVM schematics.  That board supports OTG.  Compare the design, from the DM36x out to the USB connector, between the leo36x board and the EVM.  That should answer your questions.

  • Hi

    There is a problem (or bug) in kernel/linux- that prevents it from compiling correctly and it gives you an error about phy_on .

    I have a workaround for this:

    You can manually open kernel/linux- and comment out the following lines:

    /* if (cpu_is_davinci_dm646x()) {


    phy_ctrl |= is_peripheral_enabled() ? USBPHY_PERI_USBID :


    phy_ctrl &= ~USBPHY_VBDTCTEN;

    } */


    The same workaround is possible using the patch below:

    download it and add it to $DEVDIR/kernel/patches/arch

    then add its name to series in the same folder to automate the process.

    Here are the last few lines of my series file under $DEVDIR/kernel/patches/arch:





  • Hi Todd and Morteza,

    Thanks for the help.

    Does this work making NAND flash visible to host PC as an external drive? My board doesnt have an SD card and just works on a NAND flash memory.

    Can you please give some info about changes needed in the above instructions to have NAND flash made visible to host PC as an external drive?



  • Jithin,

    You can't export the NAND flash as external drive via USB (well, you can, but no PC will be able to read the files because the file system will be JFFS2 or UBIFS, not VFAT).

    You can configure USB as a network interface, then protocols like scp and ftp will allow the PC to grab the files.