Discussion:
[Libusb-devel] Using libusb with a USB SD Card reader.
Eric Sepich
2011-10-23 22:17:22 UTC
Permalink
I have familiarised myself with the usbls.c example and have spent a bit
of time reading the USB 2.0 specification. I would like to develop a
very simple program to read and write data (files) to and from a USB
based SD Card reader. For the time being I want to do this with the most
simple code possible so I think asynchronous methods would be the best.
Does anyone have any advice on how to use libusb to create such a
program? I am still getting familiar with all the functions the library
has to offer. Is there some specific functions I should be concentrating
on using?

Thank You! :)


P.S.

For my OS which is Ubuntu 11.1 I installed using:
sudo apt-get install libusb-1.0-1-dev
and have compiled using the command line string:
g++ lsusb.c -o lsusb -L/usr/lib/x86_64-linux-gnu/ -lusb-1.0
I also had to change the #include <libusb/libusb.h> to
#include<libusb-1.0/libusb.h> on my particular OS. Since it took me some
time to figure it all out I thought it would be worth sharing. I am
still working on getting the Eclipse environment to locate the library
files but I should be there very soon with it.
Peter Stuge
2011-10-23 22:20:55 UTC
Permalink
I would like to develop a very simple program to read and write
data (files) to and from a USB based SD Card reader.
Why? Is this a school project? It is a waste of time.

Please see:

http://libusb.org/wiki/FAQ#CanIuselibusbtoopenafileonaUSBstoragedevice


//Peter
Tim Roberts
2011-10-24 18:45:21 UTC
Permalink
Post by Eric Sepich
I would like to develop a
very simple program to read and write data (files) to and from a USB
based SD Card reader. For the time being I want to do this with the most
simple code possible...
Here is approximately the simplest code possible for that task.

#!/bin/sh
echo Hello. > /media/sdcard/file1
cat /media/sdcard/file1

You REALLY do not want to undertake the task of accessing a USB mass
storage device at a raw level. Think about it this way. Would you
consider writing a "simple" program to read and write files on your
primary hard disk, without using any drivers of any kind? How many
things would you have to learn? You'd have to learn ATA controller
register programming, interrupts, DMA, ATA commands, sector mapping,
partition table layouts, and complete file system specifications. It is
not a "very simple program". Accessing a USB mass storage device is
exactly the same.
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
Tim Roberts
2011-10-24 19:11:11 UTC
Permalink
Actually what I have been using is a program called F3 by Michelle
Machado.
I don't know what that is, and Google was not helpful.
The program works very well but I am having a very specific issue with
thousands of SD cards that my client bought. Essentially I can not get
any SD card readers to read the cards at all. I know it is a long shot
but I was going to try to write some code at the hardware level to try
to "wake the cards up" so to speak and make an attempt at formatting them.
Are you aware there are several different kinds of SD cards? An SD card
reader cannot access SDHC or SDXC cards, and no amount of software or
driver effort can every make it happen. The hardware is simply not
compatible.

It would be much more productive for you to get some electrical
engineering help to figure out where the problem lies. Right now, what
you are proposing is nothing more than a shot in the dark. There is
nothing you can achieve at a low level that the existing drivers are not
already doing.
I don't think any of you really understand that with tens of thousands
of dollars on the line that it is indeed worth it to make an effort.
Of course we do. We all live in the business world in our real lives.
However, time costs money, too. Starting from scratch, you are a couple
of months away from achieving your goal. How much is your time worth?
Who is paying for that? Is it your client? It's quite possible that
the most economic solution is to sell those SD cards on eBay and go buy
another bunch that are known to work.
Your warnings about how much there is to learn I do heed however being
a self educated systems administrator as well as a self educated
programmer in too many languages to list I felt up to the task.
Mastering systems is something of a lifelong quest for me. In any
event I am the first to admit that I do have much to learn. Thanks for
the help out but perhaps I should get a book on programming the USB
port and start cracking away at that.
USB is the easy part. The USB Mass Storage Class specification uses the
SCSI command set to communicate with the drive on a low level, so you'll
have to understand SCSI. The MSC specification can be downloaded from
the USB web site at www.usb.org. Then, you'll have to understand
partitions and file systems.
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
Douglas E. Engert
2011-10-24 21:48:34 UTC
Permalink
Post by Tim Roberts
Actually what I have been using is a program called F3 by Michelle
Machado.
I don't know what that is, and Google was not helpful.
The program works very well but I am having a very specific issue with
thousands of SD cards that my client bought. Essentially I can not get
any SD card readers to read the cards at all. I know it is a long shot
but I was going to try to write some code at the hardware level to try
to "wake the cards up" so to speak and make an attempt at formatting them.
Are you aware there are several different kinds of SD cards? An SD card
reader cannot access SDHC or SDXC cards, and no amount of software or
driver effort can every make it happen. The hardware is simply not
compatible.
It would be much more productive for you to get some electrical
engineering help to figure out where the problem lies. Right now, what
you are proposing is nothing more than a shot in the dark. There is
nothing you can achieve at a low level that the existing drivers are not
already doing.
I don't think any of you really understand that with tens of thousands
of dollars on the line that it is indeed worth it to make an effort.
Of course we do. We all live in the business world in our real lives.
However, time costs money, too. Starting from scratch, you are a couple
of months away from achieving your goal. How much is your time worth?
Who is paying for that? Is it your client? It's quite possible that
the most economic solution is to sell those SD cards on eBay and go buy
another bunch that are known to work.
Your warnings about how much there is to learn I do heed however being
a self educated systems administrator as well as a self educated
programmer in too many languages to list I felt up to the task.
Mastering systems is something of a lifelong quest for me. In any
event I am the first to admit that I do have much to learn. Thanks for
the help out but perhaps I should get a book on programming the USB
port and start cracking away at that.
USB is the easy part. The USB Mass Storage Class specification uses the
SCSI command set to communicate with the drive on a low level, so you'll
have to understand SCSI. The MSC specification can be downloaded from
the USB web site at www.usb.org. Then, you'll have to understand
partitions and file systems.
There are hobbyist out there trying to use SD cards. Check this out:
http://forums.parallax.com/showthread.php?95774-Poor-Man-s-SD-Card-Socket&p=661502#post661502

This might also help you identify what you have:
https://www.sdcard.org/home/

And to format a card:
https://www.sdcard.org/downloads/formatter_3/

(I have not tried any of these of these.)
--
Douglas E. Engert <***@anl.gov>
Argonne National Laboratory
9700 South Cass Avenue
Argonne, Illinois 60439
(630) 252-5444
Xiaofan Chen
2011-10-31 02:53:27 UTC
Permalink
Post by Tim Roberts
Actually what I have been using is a program called F3 by Michelle
Machado.
I don't know what that is, and Google was not helpful.
I am a Google Power User and I always find Google to be very
helpful in most of the IT related stuff.

It found this. The name is actually "Michel Machado".
http://fixfakeflash.wordpress.com/2010/08/20/linux-h2testw-alternative-program-called-f3-by-michel%C2%A0machado/#more-253

Then you can find what F3 is.
http://oss.digirati.com.br/f3/
Post by Tim Roberts
The program works very well but I am having a very specific issue with
thousands of SD cards that my client bought. Essentially I can not get
any SD card readers to read the cards at all. I know it is a long shot
but I was going to try to write some code at the hardware level to try
to "wake the cards up" so to speak and make an attempt at formatting them.
Are you aware there are several different kinds of SD cards?  An SD card
reader cannot access SDHC or SDXC cards, and no amount of software or
driver effort can every make it happen.  The hardware is simply not
compatible.
It would be much more productive for you to get some electrical
engineering help to figure out where the problem lies.  Right now, what
you are proposing is nothing more than a shot in the dark.  There is
nothing you can achieve at a low level that the existing drivers are not
already doing.
As a hardware engineer, I fully agree. :-) HW engineers need to be
involved to make sure that hardware works fine first. Then you
can talk about firmware and then software.
--
Xiaofan
Xiaofan Chen
2011-10-31 02:57:26 UTC
Permalink
Post by Xiaofan Chen
Post by Tim Roberts
Actually what I have been using is a program called F3 by Michelle
Machado.
I don't know what that is, and Google was not helpful.
I am a Google Power User and I always find Google to be very
helpful in most of the IT related stuff.
Forget the :-) sign.
I am a Google Power User. :-)
I consider myself a Windows power user (by helping others and
by using Google to find solutions) and Linux power user to a
lesser extent (thanks to Google as well). :-)
Post by Xiaofan Chen
It found this. The name is actually "Michel Machado".
http://fixfakeflash.wordpress.com/2010/08/20/linux-h2testw-alternative-program-called-f3-by-michel%C2%A0machado/#more-253
Then you can find what F3 is.
http://oss.digirati.com.br/f3/
Post by Tim Roberts
The program works very well but I am having a very specific issue with
thousands of SD cards that my client bought. Essentially I can not get
any SD card readers to read the cards at all. I know it is a long shot
but I was going to try to write some code at the hardware level to try
to "wake the cards up" so to speak and make an attempt at formatting them.
Are you aware there are several different kinds of SD cards?  An SD card
reader cannot access SDHC or SDXC cards, and no amount of software or
driver effort can every make it happen.  The hardware is simply not
compatible.
It would be much more productive for you to get some electrical
engineering help to figure out where the problem lies.  Right now, what
you are proposing is nothing more than a shot in the dark.  There is
nothing you can achieve at a low level that the existing drivers are not
already doing.
As a hardware engineer, I fully agree. :-) HW engineers need to be
involved to make sure that hardware works fine first. Then you
can talk about firmware and then software.
--
Xiaofan
Loading...