Help writing a USB driver

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

formatting link
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?"

  1. 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.

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

  1. 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

Reply to
Mercy
Loading thread data ...

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

formatting link
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?"

  1. 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.

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

  1. 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

Reply to
Mercy

You can hook it up with a AT90USB128.

Host controller and file system.

Yes, you need to program the controller.

Write it with the controller, of course.

Reply to
linnix

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.

Reply to
larwe

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 :-)

Reply to
Mercy

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 :-)

Reply to
Mercy

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.

Reply to
Tom Lucas

Life is too short to do this yourself.

Use one of these :

formatting link

Or these :

formatting link

Reply to
Mike Harrison

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
Reply to
Tim Wescott

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 .

Reply to
larwe

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?

Reply to
Mercy

Serial Peripheral Interface, AKA 'the easy way'.

I don't know what you mean by identifying what you have -- I thought you had some design requirements to which you wanted to fit hardware.

--

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
Reply to
Tim Wescott

Actually, with the FTDI Vinculum (VNC1L) it seems almost trivial. Rocky

Reply to
Rocky

Good point. Those are perfect solutions for my problem . But a little too pricey... I don't think my manager would be very impressed... hehe ....

Reply to
Mercy

Outsourced complexity is still complexity. A 32-bit peripheral to an

8-bit micro, purely for mass storage? Insane.
Reply to
larwe

Just a suggestion: use AT43USB380 USB Host from Atmel. It has USB library to handle all USB host transactions and MSD (FAT32) library to handle USB Disk.

-kunil

Mercy wrote:

Reply to
kunil

More impressed than when you find out how long he has to pay you do to it from scratch. The Viniculum device is an absolute bargain, and unless your volume is well into

5-6 figures you'd be crazy to roll your own.
Reply to
Mike Harrison

But it's complexity that's already been developed and, more importantly, tested. I have no doubt that there are subtle quirks with different USB memory devices - if you buy the solution from someone selling it to lots of people, there is a good chance that they will already have found most of the bugs.

Why exactly..? Who cares what's inside the chip as long as it does the job. Actually it's an 8 bit core with some hardware to help accelerate 32 bit operations.

Reply to
Mike Harrison

tested.

- if you buy

My point is that if the question is "How do I remove data from point A and collect it at point B?" there are much simpler options - and if it comes to that, better-tested ones (through having been fielded longer).

Reply to
larwe

Has anyone actually gotten one of these things to work?? I'm trying t read a USB flash drive using the VDIP( Vinculum w/ VDAP firmware) throug a UART port on an MSP430F1611.

The code below is supposed to generate an interupt to when CTS#(reference from the uP) is asserted. The interupt asserts RTS#, and waits for th character to come into the RX Buffer. The character is then stored int memory. The code is also supposed to transmit a to the VDIP, thi would generate a response saying that a USB devices is or in no connected.

The there are two problems I have noticed so far. For transmitting character to the VDIP, I assert the RTS# and wait for CTS# to be asserted Before sending a character to the VDIP over the UART. However CTS# neve goes high. The second problem is that nothing is ever recieved from th VDIP because CTS# never goes high. And so nothingis ever transmited o received.

The code that I'm to use to communicate with the VDIP is shown below.

;---------------------------------------------------------------------------- ; Initialization Sequence #include ORG 01100h RESET mov.w #0A00h,SP Initialize stackpointer StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Sto WDT bis.b #001h, &P1DIR ; Use P1. as output bic.b #001h, &P1OUT bis.b #030h, &P3SEL ; Use P3.4,5 for UART0 bis.b #050h, &P3DIR ; Use P3.4,6 as output bis.b #040h, &P5DIR ; Use P5.6 for DREQ bis.b #040h, &P5OUT ; mov.b #004h, &BCSCTL1 ; Setup Clocks mov.b #088h, &BCSCTL2 ; mov.b #002h, &IFG1 ; SetOsc0 bic.b #OFIFG, &IFG1 ; Test Oscilator mov.w #0FFh, R15 ; SetOsc1 dec.w R15 ; jnz SetOsc1 ; bit.b #OFIFG, &IFG1 ; jnz SetOsc0 ; mov.b #021h, &U0TCTL ; Setup U0TCTL mov.b #008h, &U0RCTL ; Setup U0RCTL mov.b #baudDiv0, U0BR0 ; Setup Baud Rate Clock mov.b #baudDiv1, U0BR1 ; mov.b #baudMod, U0MCTL ; bis.b #0C0h, &ME1 ; Enable UART Transmitters mov.b #010h, &U0CTL ; UART0 Released mov.b #000h, &P1IES ; Port 1: Low=>High Transitio Cause Interupts bic.b #0FFh, &P1IFG ; Clea any existing Port 1 Interupt Flags mov.b #002h, &P1IE ; Allo P1.1 to Cause Interupts bis.b #GIE, R2 ; Enable global interupts ;---------------------------------------------------------------------------- ; Super_Loop mov.w &fromUSB, R5 ; R5 is pointer to a table where data is received from the UART

Super_Loop mov.w &toUSB, R4 ; R4 is pointe to data being sent to UART call #UART0_TX ; transmi character subroutine

jmp Super_Loop ; Do nothing

;---------------------------------------------------------------------------- ; UART0 TX Subroutine UART0_TX bic.b #002h,&P1IE ; Disable Interupts Caused by P1.1

bis.b #rts, &P1OUT ; Set P1.1 (RTS# on uP, #CTS on USB Host)

poll_CTS_TX bit.b #cts, &P1IN ; Wait for CTS#(uP) to set

jz poll_CTS_TX poll_TX bit.b #TXEPT, &U0TCTL ; Wait until U0 TX Buffer is Empty

jz poll_TX mov.b @R4,U0TXBUF ; Transmit Selected Character

bic.b #rts, &P1OUT ; Reset P1.1 (RTS# on uP, #CTS on USB Host)

bis.b #002, &P1OUT ; Enable Interupts Caused by P1.1

ret ; return from subroutine

;-------------------------------------------------------------------------- ; P1.1 Interupt Handler (for UART RX, activated on rising edge of #CTS

P1_ISR bit.b #cts, &P1IFG ; test P1_ISR Trigger jz end_ISR ; bis.b #rts,&P1OUT ; Set P1.1 (RTS# on uP, CTS# on Host)

poll_RX bit.b #040h, &IFG1 ; Poll UART RX Flag until 1

jz poll_RX mov.b &U0RXBUF, 0(R5) ; Move RXed Char to Address pointed to by R5, post inc.

inc.b R5 end_ISR mov.b #000h, &P1IFG ; Reset All P1 Interupt Flags

bic.b #rts,&P1OUT ; Reset P1.1 (RTS# on uP, CTS# on Host)

reti ; return from interupt ;--------------------------------------------------------------------------- ; Memory toUSB DW testDataTx ; pointer to table where data is transmitted

fromUSB DW testDataRx ; pointer to table where data is received

testDataTx DW 00Dh ; Data to be transmitted to USB testDataRx DW 0, 0, 0, 0, 0, 0, 0, 0 ; Data received from USB Host

DW 0, 0, 0, 0, 0, 0, 0, 0 ;--------------------------------------------------------------------------- ;Interupt Vectors ORG 0FFFEh DW RESET ORG 0FFE8h DW P1_ISR

;-------------------------------------------------------------------------- ;EQUATES baudDiv0 EQU 041h baudDiv1 EQU 003h baudMod EQU 000h rts EQU 001h cts EQU 002h end

Any help is much appreciated.

Reply to
jhelm

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.