1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Electronics Help to build a USB gadget

Discussion in 'Modding' started by nick01, 19 Jan 2006.

  1. nick01

    nick01 What's a Dremel?

    Joined:
    6 Nov 2004
    Posts:
    598
    Likes Received:
    0
    Does anyone know where to find documentation on making a USB hard drive?

    I plan to make a battery powered data collection gadget that is connected every few days to a computer to read out collected data and reset it. In the old days one would have used RS-232 and HyperTerminal to connect to the gadget on any Windows PC, but RS-232 is dying out, so now it has to be USB.

    I have neither the software nor the experience to program device specific drivers in Windows XP. The idea is therefore to let the gadget look like a USB flash drive to Windows XP and use the native driver to connect to it. The fake drive would contain exactly two files. One file would contain the collected data for copying to the PC. The other file would contain setup information. The gadget would read the setup information whenever the file is written to.

    I have played with Microchip PICs before and can write code for them, but from their documentation on USB-PICs I couldn't figure out how to make one look like a USB flash disk, and what additional components it takes to make the USB connection.

    Thanks for any help
     
  2. phuzz

    phuzz This is a title

    Joined:
    28 May 2004
    Posts:
    1,712
    Likes Received:
    27
    USB drive enclousers are pretty cheap nowadays, might be worth picking one up and having a play with the IDE to USB converter...
    (also try moving this thread to the electronics sub-forum, they're clever bods over there :))
     
  3. MonkeyTurnip

    MonkeyTurnip What's a Dremel?

    Joined:
    23 Aug 2005
    Posts:
    697
    Likes Received:
    5
    i bought a 2.5" ide - USB external hdd case for £3.50 plus £3 delivery off of amazon a month a go
     
  4. nick01

    nick01 What's a Dremel?

    Joined:
    6 Nov 2004
    Posts:
    598
    Likes Received:
    0
    The USB to IDE adapters that I looked into always just have a processor inside, and a little support electronics. The adapters translate USB straight to IDE and usually the code on the processor is protected, so I can't even read it out in machine code.
     
  5. Atomic

    Atomic Gerwaff

    Joined:
    6 May 2002
    Posts:
    9,646
    Likes Received:
    94
    We have had the same problem at work with serial ports dying out... annoying as so many scientific instruments connect via it still.

    In your position I think i would use a usb hdd and take out the guts, then just use a switch to move the IDE interface between the 'gadget' and the IDE/USB when you need to read the data.

    Either that or use a normal removable HDD caddy and just move the HDD between the gadget and the computer.
     
  6. Rod10k

    Rod10k What's a Dremel?

    Joined:
    2 Jun 2001
    Posts:
    193
    Likes Received:
    0
    Microchip has example code to make a PIC look like a removeable hard disc

    See this thread on their forums for details here

    To connect a PIC to USB you only need a USB connector. The PIC has all the other required bits and pieces inside.

    Have a look at the PICDEM USB FS for a sample schematic.

    The other thing to consider is that USB is a protected name. If this is a product then you need to investigate the licencing issues. check usb.org for details

    Let us know what you decide
     
  7. Splynncryth

    Splynncryth 0x665E3FF6,0x46CC,...

    Joined:
    31 Dec 2002
    Posts:
    1,510
    Likes Received:
    18
    There is a default mass storage class that you need to set up on the USB side. You'll then need to turn those USB bulk transfers into ATA formatted transfers for some sort of ATA controller. The only USB platform I caould offer any help with is the Cypress FX2 platform, but at $500 for the dev kit, I don't think that is much of an option (though there is a wonderful ATA USB hard drive bridge example for the kit). The links some of the others have put up seem to be a pretty good start for using the PIC.
    If you are just using the plain old mass storage class, the drive will be treated as a standard HD. I'm not sure I understand what you want to do with the software, but you might find writing a specific USB driver to be a better final solution for your design.
     
  8. AJB2K3

    AJB2K3 What's a Dremel?

    Joined:
    12 Dec 2005
    Posts:
    1,605
    Likes Received:
    4
  9. mclean007

    mclean007 Officious Bystander

    Joined:
    22 May 2003
    Posts:
    2,035
    Likes Received:
    15
    how about using an el cheapo flash card reader to interface with the PC and making your gadget write to an SD/CF card?
     
  10. ch424

    ch424 Design Warrior

    Joined:
    26 May 2004
    Posts:
    3,112
    Likes Received:
    41
    You could just attach the PIC to an SD card through SPI, use someone else's SD+FAT library, and get it to write to files on that... Then unplug the card and put in a card reader to transfer it to the computer.

    This would make it much easier, as PIC USB is quite tricky.

    ch424
     
  11. nleahcim

    nleahcim What's a Dremel?

    Joined:
    22 Apr 2003
    Posts:
    550
    Likes Received:
    1
    This is what I would suggest. Everything else is just too complicated for most people. FTDI makes some very nice usb to uart converters.

    If you really must have it acting as a usb hard drive - On AT-91.com they have some open source code that will make one some of their ARM chips act as a generic mass storage device. Keep in mind that an ARM is many many times more complicated to use than a PIC.
     
  12. star882

    star882 What's a Dremel?

    Joined:
    19 Mar 2003
    Posts:
    925
    Likes Received:
    1
    I actually have a nifty little adapter (given to me by a friend) that uses a 24MHz Ashlee Simpson MCU to connect USB to 1-wire.
    As for homemade projects that do not involve writing Ashlee Simpson assembly code, a USB to RS232 adapter plus some logic chips makes for a very simple (though slow) interface that is enough for many measurement applications. For an embedded USB device, you could even take apart the adapter and use the circuit board inside. That will also allow you to power your device from USB, although make sure that the total draw (including the adapter) does not exceed 500mA. I'm actually making a data acquisition unit that uses USB to connect to the PC.
     
  13. Rod10k

    Rod10k What's a Dremel?

    Joined:
    2 Jun 2001
    Posts:
    193
    Likes Received:
    0
    The specs for powering things from the USB port are a little more complicated. A device may take 100ma during enumeration, after that if it has enumerated as a high power device it can ask for 500ma. The host is within its rights to deny this request iirc.
    The host may also request a USB device to suspend in which case it has about 10ms to reduce its consumption to 5ma or something small like that.

    Rod
     
  14. nick01

    nick01 What's a Dremel?

    Joined:
    6 Nov 2004
    Posts:
    598
    Likes Received:
    0
    Looks like I'll stick with RS-232 and dangling adapters for now. :sigh: That USB stuff would have been nice, but the software is too complicated. Still looking into the smart card idea tough.
     
  15. Splynncryth

    Splynncryth 0x665E3FF6,0x46CC,...

    Joined:
    31 Dec 2002
    Posts:
    1,510
    Likes Received:
    18
    Let me say that USB development is nowhere near as hard as everyone says it is. Having a good codebase to start with helps, but by the time I was done with my early USB stuff, I could have rewritten all the libraries because I have deen through them so much looking at specific functionality. The problem is that it is not necessarally cheap. I've worked primarially with the FX2 from Cypress. The development kit itself retails for $500, and if you want the full version of the compiler, you'll need to spend about $2000 more. (they ship the kit with an evaluation version of the compiler that builds it's code only to load into external memory) Most of the other kits I was looking at when I bought the FX2 were in the same proce range and had the same compiler issues. The one exception to all this are the PICs that have USB support, but I have not yet gotten into PICs so I have no idea what sort of quirks they have with USB.

    Still, if you were really determined, there are some othhr routes to take. Many microcontrollers out there do not integrate flash on board for firmware, they use an external EEPROM. IF it's a I2C or other serial type flash part, you should be able to fins schematics for parallel port interface plans. I've seen them for a couple interfaces like I2C and LPC buses.
    Assembly code really isn't that bad. Oh, there are things I do miss about high level languages when programming in ASM like conditional branching instructions, but ASM has a simplicity to it, the instructions are limited in scope, and your control over the systemis much tighter. Still, you may still be able to find tools like C compilers from either the company or in terms of a freeware compiler. Once I've seen, but haven't used yet is SDCC.

    USB is NOT hard, it is just not the same as the bit pushing you are use to with the serial or parallel port. USB was designed for programmers, so it is more about data structres, USB feels more like an API than an interface.

    On top of all this, if you conform to one of the standard class types, like USB mass storage, you don't need to worry about any OS specific software, you just need to develop firmware.

    Initallygetting everything set up may be hard, but once you get going, the actual USB development is pretty easy.
     
  16. kracso

    kracso What's a Dremel?

    Joined:
    23 Feb 2003
    Posts:
    37
    Likes Received:
    0
    Check out FTDI .
    They have some pretty neat USB IC's.
     
  17. nick01

    nick01 What's a Dremel?

    Joined:
    6 Nov 2004
    Posts:
    598
    Likes Received:
    0
    I hadn't thought about that. Putting the USB-serial adapter as chip into my circuit should work. That way nobody can abduct it. - Thanks
     

Share This Page