EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Help writing a USB driver

Started by Mercy October 10, 2006
Hi all,

Any advice/pointers or instructions would be most helpful.  I am still
a newbie at embedded design so please humor me.

I have a datalogger module written using an Atmel 8051.  I want to add
a USB port to it so I can simply plug in a USB flash drive and have the
data automatically downloaded as a formatted text file.

I have read www.usb.org... but I still don't know where to start.  If
someone could point me to an online resource or a book... preferrably
something with similiar applications... that'd be great!

Here's a few of my questions.

1.  If I buy a USB controller such as those provided by Micrel or
Cypress... do I still need to write a "Host Controller Driver?"

2.  What parts of the USB protocol do I need to implement, and how much
of it is already implemented by the USB controller and the USB Flash
Drive.

3.  Do I really need to worry about all that protocol timing stuff ...
shouldn't the USB controller take care of that for me?

4.  Assuming that I get the answer to the three questions above, how do
I write a TEXT file to a USB flash drive?  I know how to do it if I was
writing a windows app... but this is different.  Anyone have any idea?

Thanks in advance.
Mercy

Mercy wrote:
> Hi all, > > Any advice/pointers or instructions would be most helpful. I am still > a newbie at embedded design so please humor me. > > I have a datalogger module written using an Atmel 8051. I want to add > a USB port to it so I can simply plug in a USB flash drive and have the > data automatically downloaded as a formatted text file. > > ... > > 1. If I buy a USB controller such as those provided by Micrel or > Cypress... do I still need to write a "Host Controller Driver?"
You can hook it up with a AT90USB128.
> > 2. What parts of the USB protocol do I need to implement, and how much > of it is already implemented by the USB controller and the USB Flash > Drive.
Host controller and file system.
> > 3. Do I really need to worry about all that protocol timing stuff ... > shouldn't the USB controller take care of that for me?
Yes, you need to program the controller.
> > 4. Assuming that I get the answer to the three questions above, how do > I write a TEXT file to a USB flash drive? I know how to do it if I was > writing a windows app... but this is different. Anyone have any idea?
Write it with the controller, of course.
> > Thanks in advance. > Mercy
Mercy wrote:

> Any advice/pointers or instructions would be most helpful. I am still > a newbie at embedded design so please humor me. > > I have a datalogger module written using an Atmel 8051. I want to add > a USB port to it so I can simply plug in a USB flash drive and have the > data automatically downloaded as a formatted text file.
You don't want to do this. Use a removable flash storage medium like SD. Implementing host-side USB is not a trivial exercise and should only be undertaken for the gravest reasons, and where no reasonable alternative exists.
larwe wrote:
> You don't want to do this. Use a removable flash storage medium like > SD. > > Implementing host-side USB is not a trivial exercise and should only be > undertaken for the gravest reasons, and where no reasonable alternative > exists.
Ok, so I don't want to do this with a USB port. So... umm... how would I go about using a removable flash storage medium like an SD card or an CF card? Would I just embedd a card reader into my current module? Where can I go to find more information about this? Thanks :-)
linnix wrote:
> > 1. If I buy a USB controller such as those provided by Micrel or > > Cypress... do I still need to write a "Host Controller Driver?" > > You can hook it up with a AT90USB128. > > >
I would... but I don't think the AT90USB128 has a built in CAN controller. And I need the CAN controller more than I need the USB port :-)
"Mercy" <mercy.chang@gmail.com> wrote in message 
news:1160494713.481397.164650@h48g2000cwc.googlegroups.com...
> > larwe wrote: >> You don't want to do this. Use a removable flash storage medium like >> SD. >> >> Implementing host-side USB is not a trivial exercise and should only >> be >> undertaken for the gravest reasons, and where no reasonable >> alternative >> exists. > > Ok, so I don't want to do this with a USB port. So... umm... how > would > I go about using a removable flash storage medium like an SD card or > an > CF card? Would I just embedd a card reader into my current module? > > Where can I go to find more information about this?
If you have SPI then SD and MMC are fairly simple - you can bit bang it if you have to. Lewin's (larwe) DosFS is perfectly adequate as a file system for the SD card too. I used an MMC card datasheet and a google for how FAT16 worked to write my own drivers from scratch and it wasn't hard - and I don't have much experience in that area.
On 10 Oct 2006 08:15:27 -0700, "Mercy" <mercy.chang@gmail.com> wrote:

>Hi all, > >Any advice/pointers or instructions would be most helpful. I am still >a newbie at embedded design so please humor me. > >I have a datalogger module written using an Atmel 8051. I want to add >a USB port to it so I can simply plug in a USB flash drive and have the >data automatically downloaded as a formatted text file. > >I have read www.usb.org... but I still don't know where to start. If >someone could point me to an online resource or a book... preferrably >something with similiar applications... that'd be great!
Life is too short to do this yourself. Use one of these : http://www.vinculum.com/ Or these : http://www.ghielectronics.com/details.php?id=1
Mercy wrote:
> larwe wrote: > >>You don't want to do this. Use a removable flash storage medium like >>SD. >> >>Implementing host-side USB is not a trivial exercise and should only be >>undertaken for the gravest reasons, and where no reasonable alternative >>exists. > > > Ok, so I don't want to do this with a USB port. So... umm... how would > I go about using a removable flash storage medium like an SD card or an > CF card? Would I just embedd a card reader into my current module? > > Where can I go to find more information about this? >
At least one of the flash card protocols includes the ability to communicate with the card over SPI, so you don't tie up a bunch of processor pins. A recent Circuit Cellar had an article on doing just this -- it would be in the May-July time frame, probably. The bottom line is that a FAT-12 or FAT-16 file system is pretty easy to implement, and talking to the card isn't hard either. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Posting from Google? See http://cfaj.freeshell.org/google/ "Applied Control Theory for Embedded Systems" came out in April. See details at http://www.wescottdesign.com/actfes/actfes.html
Mercy wrote:

> Ok, so I don't want to do this with a USB port. So... umm... how would > I go about using a removable flash storage medium like an SD card or an > CF card? Would I just embedd a card reader into my current module?
You would just embed a socket into your current module and add the software to talk to it. There are zillions of example circuits and software for various micros floating about the web. Note that you must interface between 3.3V and 5V, if your system is 5V. For the filesystem layer, as another respondent suggested, you can use my (free) DOSFS <http://www.zws.com/products/dosfs/>.
Tim Wescott wrote:
> At least one of the flash card protocols includes the ability to > communicate with the card over SPI, so you don't tie up a bunch of > processor pins. A recent Circuit Cellar had an article on doing just > this -- it would be in the May-July time frame, probably. >
When you guys refer to SPI, are you talking about: Serial Peripheral Interface or System Packet Interface? Also ... how can I identify what I have?

The 2024 Embedded Online Conference