USB Hub Used For In System Programming

Did you order that 4-port USB hub because it was almost free but now it’s just sitting in your junk box? Why not turn it into an In System Programmer for AVR chips? [Paul] came up with HUB ISP as an answer to the chicken-or-egg problem we’ve seen with other diy programmers. It uses the data wires from four different USB cables to program AVR chips, enlisting the help of a 74HC00 NAND gate along the way. You do not need to have a programmed microcontroller as all the magic happens on the software end of things. The one caveat is that [Paul’s] method currently only works on Linux machines.

37 thoughts on “USB Hub Used For In System Programming

  1. Linux, ftw. Dual-boot every machine you own, people. Unless you want to unplug from windows altogether. It’s up to you. Also, keep in mind that you can boot Linux from a USB thumb drive; I have several distros in my pocket right now: DSL-not, Fedora 10, Ubuntu 10.04 Gnome, Ubuntu 10.04 Netbook remix, Slax. Damn small is pretty sweet, as it can run from as little as 50MB fixed. Hmmm, I believe I already have a quad NAND chip. He’s harvesting +Vcc from two of the ports and GND from the other two; neat idea, as you get up to 200mA with that.

  2. @PocketBrain or in the time since i read your comment, and right now port it to windows

    1>—— Rebuild All started: Project: hub_isp, Configuration: Debug Win32 ——
    1>Build started 6/7/2010 10:22:41 AM.
    1>_PrepareForClean:
    1> Deleting file “Debug\hub_isp.lastbuildstate”.
    1>InitializeBuildStatus:
    1> Creating “Debug\hub_isp.unsuccessfulbuild” because “AlwaysCreate” was specified.
    1>ClCompile:
    1> usb.c
    1>c:\code\hub_isp\usb.c(373): warning C4098: ‘usb_set_debug’ : ‘void’ function returning a value
    1> usb_hub.c
    1>c:\code\hub_isp\hub_isp\usb_hub.c(35): warning C4101: ‘name’ : unreferenced local variable
    1> misc.c
    1> ihex.c
    1> hub_isp.c
    1> avr_isp.c
    1> Generating Code…
    1>Manifest:
    1> Deleting file “Debug\hub_isp.exe.embed.manifest”.
    1>LinkEmbedManifest:
    1> hub_isp.vcxproj -> c:\code\hub_isp\Debug\hub_isp.exe
    1>FinalizeBuildStatus:
    1> Deleting file “Debug\hub_isp.unsuccessfulbuild”.
    1> Touching “Debug\hub_isp.lastbuildstate”.
    1>
    1>Build succeeded.
    1>
    1>Time Elapsed 00:00:01.40
    ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

  3. Quoting @PocketBrain “OMFGBBQSAUCE-I HAVE A BONER FOR LINUX, YOU SHOULD TOO!”

    Considering you can make a pony prog with 4 resistors and the proper connectors (db25, and idc6 or idc10…), this seems like a waste of perfectly good usb cables, and a NAND gate — not to mention the usb hub. GOOD hubs are hard to come by.

  4. FYI the changes i made to it for windows were pretty simple

    ifdef’d around a unistd.h

    added a usleep
    http://sourceforge.net/apps/trac/scummvm/browser/vendor/freesci/glutton/src/win32/usleep.c?rev=38187
    needs
    #pragma comment(lib,”winmm.lib”)

    added a ssize_t (this might be in a windows header already, but i just chucked it in)

    changed the 0b’s to 0x’s in avr_isp.c

    used libusb_dyn
    http://svn.gnumonks.org/trunk/librfid/src/libusb_dyn.c

    #ifdef’d around the kernel detach usb_get_driver_np in usb_hub.c

    added a #define for ENOFILE 2

    that was about it.

  5. @Ryan Leach: If you write a USB filter driver for Windows it’ll enable you to send anything you wish to your USB controller to process. All the Linux magic (well, almost) is possible with Windows too… it’s just that those who need that magic are using Linux already. ;P

  6. This is one of those projects that are made just for “Look how cool I am and what I can do on Linux, ofcourse”.
    For the next one I have an idea: use the leds on the keyboard for output (coupled with some photorezistors and tranzistors) and the click from the mouse for input. That would be awesome! And useless…
    Go get 4 rezistors, a serial/parallel connector and you have a working programmer. And you aren’t stuck on linux.

  7. I just don’t see it as much of a challenge to windows, its the same hardware, you can run ring 0, filter drivers etc. libusb is ported and functional, used it a bunch of times before. Not sure why people think its so hard to do this stuff on windows?

    I only ported it because of what PocketBrain said, i looked at Pauls site, i see the don’t bother me with windows stuff do it yourself, so everything you need is posted above.

    I’ll throw the project on my wordpress site when i get a few minutes.

  8. “If you are just getting started with AVR microcontrollers, ISP programming is not a good place to begin, even if you buy a ready made programmer, and certainly not by trying to build your own!”

    What the hell kind of crap statement is that? ISP programming is just programming the chip while it’s in the ‘system’ instead of programming the chip then inserting it into the system. Building an ISP programmer isn’t that hard either, it’s very straight forward and there have been plenty of guides for the beginners. It felt like the guy was saying “ISP programming is too complicated for you to understand, so go get an arduino or teensy.”

    As hackers we constantly strive to learn how things work, and to share that information freely with each other. The best way to learn is to do: Pick up a soldering iron, build a simple programmer and learn how to work with a microcontroller. Hell, not all of our projects work the first time around, it’s all a learning experience.

  9. Hi, Paul here…. the guy who made this.

    @charliex, does your windows version actually work?

    The main problem on Windows or Mac is libusb’s lack of usb_detach_kernel_driver_np(). Everything else you did sounds reasonable, but #ifdef’ing out that bit probably kills any hope it would work.

    On Linux, that asks the kernel to unload its driver, and then you can claim the interface and send control transfers to it. Windows just doesn’t support this from userland, as far as I’m aware.

    There certainly is some way to do this on Windows… I just don’t know how. But the USB-IF compliance test program does something like this, where it takes over a hub and uses it to subject your USB device to all sorts of scenarios to check if it’s USB compliant. Older versions required you to have a PS2 keyboard and mouse, because it apparently switches the entire USB protocol stack for its own. I’ve run it several times, but never seen the source, but you can get the binary for free at http://www.usb.org.

    The main problem, even if you’re able to send control transfer to the hub, is if Windows is still using it, the host controller driver will see new device arrivals and try to do lots of stuff. You have to keep the ports disabled to do this kind of I/O.

    I really never intended this to be Linux vs Windows thing… I simply use Linux and even when I had this crazy idea, I figured Linux wouldn’t let me detach its driver for the hub and let me have exclusive access, at least not so easily from user space, but it did!

    Also, it looks like everyone’s missed the ideas (near end of the page) about improving the timing and somehow using the root hub. If anyone could figure that stuff out, it might be possible to do AVR ISP programming using only 3 USB cables and 3 resistors… no hub and no NAND gates!

  10. @Fili
    How is this one of those projects? It states right there in the article what this is good for, if you didn’t read it: its good for getting an AVR programmed to make a proper USB ISP programmer… like the USBasp that was covered the other day.

    I agree with the others though, 4 USB cables will probably set you back more than the hub did to start with. Solder direct to the board!

  11. Also, yes, if anyone verifies the charliex’s windows program works, I’ll be happy to host it or link to his site! I might even install windows on a machine and give it a try myself…..

  12. why the hell are people shitting on someone doing something with an object that was never intended?

    I could have sworn that doing that was considered a hack. and I am also sure that people are getting out of touch when they say “go order a proper one instead of wasting time making one” Why waste a learning experience by circumventing the opportunity purchasing something already made?

    this is a great hack that I would have never thought of myself, I am glad to see people coming up with new ideas, but people that belittle someones ideas have really gotten out of touch with what hacking is all about.

    just my 2 cents.

  13. this is good for a couple reasons, ponyprog does not support every chip out there, serial and parallel ports are disappearing from computers.

    dumb crap 4 port usb hubs are nothing, usb cables are nothing (plus you can still use the other end or the wire) if your totally flat broke and some office worker drops a box of corporate usb dongles on you as you loiter in the lobby, yes you sir can burn an avr

    good work

  14. Osgeld, thanks for making the point I was about to. I’m sick of trying to use an ‘old’ Atom 1.6ghz board with a serial port on it for this sort of stuff, and usb->serial adapters don’t always work properly, especially under 64bit Windows. This would certainly come in handy, as I already have a busted-open 4 port hub here, casing just shattered after falling from my table. I triple-boot all three major OSes, so I could care less if it’s Win32, Carbon/Cocoa/ObjC, or native Linux C code, and I’ll probably play with charliex’s modification to see if/how it works.

  15. this is ingenious and a great hack in the truest sense of the word

    all you whiners coming in here complaining that this isn’t as elegant as making/buying a programmer need to get out and stay out

  16. For everyone who’s reacted so negatively, generally that HUB ISP is not as good as regular “chicken or egg” programmers, and maybe not even as cheap depending on how you obtain a hub and 4 cables, I added these words to the “Not For Beginners, or Anyone Who Values Their Time” section: (which was originally meant to explain HUB ISP’s limitations, but apparently not as successfully as I’d imagined)

    HUB ISP is certainly not a viable replacement for regular “chicken or egg” AVR ISP programmers, which are much faster and more reliable, and maybe even cheaper… eg, Teensy running the ArduinoISP code (yup, another shameless plug).

    I am really glad so many of you appreciate this little idea I spent the weekend turning into working code and a nice web page… it’s a hack and I believe the first time anyone’s ever used reset pulses and pullup detection on disabled USB ports to do simple I/O.

  17. omg.. always these stupid people on hackaday. he just made a good hack and people try to make it look bad because it requires linux?! take a look at the source and make it work for windows. and also people complain about the use of “expensive” cables.. solder some wires to an old hub. again its a hack. if you dont want to use it just shut up and respect his work. i think he has done a good job.

  18. Very impressive. Very nice use of a USB HUB.
    This could probably be extended on for general serial / parallel stuff.

    Can’t believe people are complaining. I really hope they are trolling.
    This is hackaday, not go-out-and-buy-something-made-for-that-purpose-aday.

  19. @Paul
    Nice! I might even see about making it work someplace. However I see one typo there, you mispelled “serial” there.

    However for making it work for me, I’d rather track down the breakout boards for USB connectors such as the ones worn by that FTDI device board from Sparkfun.

    Other then that it makes perfectly good sense.
    @charliex:
    Interesting idea. I am interested in making it work. But it does it work on Windows Seven?

  20. very cool… lets see avr dragon 49.00+shiping=$$$
    4port hub in junk box free (and taking up space)+4usb cables in junk box(more like 2dozen or so from cheap digi-cams and dead mp3 players)free=priceless… as it was stated this is not go-out-and-buy-something-made-for-that-purpose-a-day.com(by the way that site name is available…for all the wankers) it’s hack-a-day and this is most certainly a hack.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.