Can I build USBtinyISP onto Atmega32U4?

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Can I build USBtinyISP onto Atmega32U4?

Postby smorehou » Fri Feb 24, 2012 4:32 pm

I have an idea for a custom purpose-built device that will behave as an ISP programmer for an attached target, but also bahave (when its not busy programming) as a i2c node for more general purpose communication between itself and the "target". All of the open source ISP programmers are, for good reason, built upon inexpensive chips that satisfy the requirements of the programmer but not much else.

I'd very much like to use the Atmega32U4 because a) it has built-in USB support w/ bootloader (so I can update the custom device itself without the need for an ISP - it's going to be buried in an enclosure) and b) it has the resources I need for my "general purpose" requirements.

What I'm envisioning from the end-user perspective is the following:
  • When they plug in the USB, it is recognized as a AVRDUDE compatible programmer (ie. USBtinyISP) and used as such.
  • When they plug in the USB and press the HWB/RST to enter bootloader, then it is recognized as an "Atmel AVR device" and they use FLIP (or whatever) to update the device's own firmware
  • When its not plugged in via USB but instead self-powered, it now behaves as a custom programmed MCU communicating with the "target"

I've scoured the web for related tutorials and such and have so far come up empty.

Is what I'm trying to do plausible? Can the USBtinyISP firmware be adapted to work on such a chip?

Any ideas to get me started would be appreciated, thanks.

Steve


ps. I've ordered a Teensy 2.0 as a general purpose dev platform for this project since it comes with a Atmega32U4 onboard.
smorehou
 
Posts: 11
Joined: Fri Feb 24, 2012 4:11 pm

Re: Can I build USBtinyISP onto Atmega32U4?

Postby sdb » Sat Feb 25, 2012 6:04 pm

I think it is very plausible.

Why I2C? Your ISP is going to be using SPI (unless you want to implement one of the more difficult modes...) and will have the SPI pins connected.

You could start with the usbtiny code. Just strip out the USB stuff (most of it) and replace it with the communication you need for the 32u4 (I don't know anything about that).

Personally I found the ArduinoISP sketch easier to understand and modify, so you might want to start with that instead. (That's the one that ships as part of the Arduino IDE, that turns an Arduino into an ISP.) It uses the built-in uart (RxD and TxD pins) to communicate with the PC so it doesn't have all the "pretend to be USB" code to strip out. That means it doesn't need interrupts and all that either, just receive bytes and send bytes. I bet the 32u4 has that same kind of interface (or library) for USB communication also.

However you are going to need to implement something either on the PC or on the 32u4 to make it look like a usbtiny (or avrusb or avrisp) to the PC. I suspect that will be your biggest challenge. But maybe it will just fall out naturally?

The avrisp is expected to be a serial (com) port, or else a virtual com port provided by a driver (such that for the FTDI usb to serial chip). That works really well for ArduinoISP.

I'm not sure how usbtiny or avrusb present themselves. Generic libusb device? Generic HID? And I'm a linux user, where things tend to be a lot easier there than in Windows for an application such as avrdude to talk with a usb device, so I haven't paid too much attention to how they work in Windows. If, however, you use the same VID/PID as a usbtiny, and implement the same endpoint(s), you should be golden. (Same for avrusb.) Not Kosher to use the same VID/PID, but for a hobby device it won't cause a problem. If you go into production you'll need to get your own authorized VID/PID and provide your own INF unique to your product.
sdb
 
Posts: 31
Joined: Thu Jan 12, 2012 3:24 am
Location: USA, ID

Re: Can I build USBtinyISP onto Atmega32U4?

Postby smorehou » Sat Feb 25, 2012 7:05 pm

Thanks for the helpful reply. It doesn't answer a lot of my questions but you've provided me some direction to look at! I never heard of ArduinoISP so that's something for me to check out!

Why I2C? Because I don't know how to make SPI work with more than two nodes. So I figured I'd leave the SPI to the programming side of things and use i2c for the other communication.

I'm new to AVR in general. There's no reason it can't handle both enabled, can it? I was actually hoping to also implement uart for some optional incoming information and process that and re-send it via i2c.
smorehou
 
Posts: 11
Joined: Fri Feb 24, 2012 4:11 pm

Re: Can I build USBtinyISP onto Atmega32U4?

Postby abqlewis » Sat Feb 25, 2012 10:58 pm

Checkout the AVRISP-MKII Clone in LUFA http://fourwalledcubicle.com/LUFA.php. LUFA is open source USB code for the "U" AVRs that have embedded USB (like the 32u4), so this might be easier than changing the USBTinyISP code from tiny2313. I use the programmer on the ATMega32U4 Breakout Board+, and a few 32u2 Breakout Boards, and it works fine (I've had a little problem getting it working on Teesy). I've used AVRISP-MKII Code for ISP, but it is supposed to also work for PDI and TPI. Out of the box (you have to change maybe 2-3 lines in the makefile), it handles your first 2 bullets. You would have to add in your I2C functionality. The 32u4BB+ uses AVR109 instead of DFU (Flip), but you can change it if you want (I wouldn't).
abqlewis
 
Posts: 57
Joined: Fri Dec 11, 2009 1:19 am

Re: Can I build USBtinyISP onto Atmega32U4?

Postby smorehou » Sun Feb 26, 2012 12:05 am

I checked out LUFA briefly a week ago or so and ruled it out for some reason. But honestly I can't remember what that reason was. I'll take another look.

- Steven

Edit: OK, I quickly re-discovered why I moved on... on his AVRISP-MKII Clone he writes:
No schematic for the clone programmer is currently provided - it is up to the user to design their own schematic from the example schematic in the USB AVR's datasheet


"USB AVR" is a bit vague. There's no example schematic on the 32U4's datasheet and I searched and searched and couldn't find a schematic for the AVRISP-MKII or any clone... only a few dozen people also looking for it. My Google skills never seem to be on par with others' though... am I missing something obvious?
smorehou
 
Posts: 11
Joined: Fri Feb 24, 2012 4:11 pm

Re: Can I build USBtinyISP onto Atmega32U4?

Postby abqlewis » Sun Feb 26, 2012 4:12 am

You're right. As I remember it, that had me going for a little bit. But then I found a link for the AVRISP for Micropendeous http://code.google.com/p/micropendous/wiki/AVRISP, and it became clear. Most of the pins are straight forward : 3 pins for SPI - MOSI, MISO, and SCK - 2 for Power and Gnd - that just leaves 1 pin for Reset line. By default it's PB4, but can be easily changed in the makefile (which might be why it's not well documented). I made a 32u4BB+ shield for about a buck (this is what all shields should be like), that connects all of the correct pins to a 6-pin ISP cable. In theory, I should have only 1 32u4BB+, so I can attach the shield and load LUFA just when I need to program, but I liked it enough to get an extra board as a dedicated programmer. I keep planning to add some buffering hardware, like the USBTinyISP, and to support TPI,and PDI programming, but it keeps getting put off.
abqlewis
 
Posts: 57
Joined: Fri Dec 11, 2009 1:19 am

Re: Can I build USBtinyISP onto Atmega32U4?

Postby smorehou » Sun Feb 26, 2012 10:15 am

Awesome! Thanks so much for the help. How'd you find that micropendous page? lol. I swear I searched for DAYS before finally asking for help here and BOOM... you've got it for me in 2 replies.

I wonder if my local college teaches "Google" :) Its funny, 7 to 10 years ago I considered myself a Google search expert. I could find things nobody else could. Over the years, I've complained that google has become less and less useful... but more recently I'm thinking its me, not Google. :lol:
smorehou
 
Posts: 11
Joined: Fri Feb 24, 2012 4:11 pm

Re: Can I build USBtinyISP onto Atmega32U4?

Postby abqlewis » Mon Feb 27, 2012 3:57 pm

I hope it's working for you now. I went through the same problem. I found the page when I was looking for something else. There probably weren't many (any?) links to the page, which ironically moved it lower in the Google results. Now that there is one more link, it will hopefully move up the list!

As far as the USBTinyISP is concerned - I have one, and it's a great programmer (cheers to Ladyada's design and tutorial), but I've put it away. I use my 32u4/LUFA combo for all my programming now. It's smaller, more convenient (who has a full size USB B cable anymore?!), I think it's easier for beginners (soldering wise), and it multitasks. One day it's a ISP programmer, the next it's a USB-to-Serial board, the next day it's a fake keyboard for April Fools Day, etc. Even bought a 32u2 board for real cheap (<$10) that I may make into a permanent programmer. Changed 1 line in the makefile and Bingo, it works.

BTW, if you like LUFA, donate a little something to Dean's site. He's not a starving student anymore, but I still think he deserves it.
abqlewis
 
Posts: 57
Joined: Fri Dec 11, 2009 1:19 am

Re: Can I build USBtinyISP onto Atmega32U4?

Postby smorehou » Mon Feb 27, 2012 4:14 pm

Only if he posts a simple schematic lol. I would have concluded this a week ago if it didn't leave me hanging.

I have to wait for some hardware to arrive before I can do some testing.
smorehou
 
Posts: 11
Joined: Fri Feb 24, 2012 4:11 pm

Re: Can I build USBtinyISP onto Atmega32U4?

Postby smorehou » Wed Mar 21, 2012 7:00 pm

Hello again.

I'm banging my head against the wall. I simply can't get that LUFA project to work on my u4. It compiles fine, Windows recognizes it... but avrdude complains.

I'm using a Teensy2 board, but really that shouldn't affect anything. That's just a different bootloader, right?

- Steven
smorehou
 
Posts: 11
Joined: Fri Feb 24, 2012 4:11 pm

Re: Can I build USBtinyISP onto Atmega32U4?

Postby Sowbug » Thu Mar 22, 2012 3:41 pm

Hey smorehou, stop banging your head! It's most likely an incompatibility between avrdude and the USB implementation on the AVR8 series. Read more here. The summary is that you can build a version of Dean's AVRIVP mkII project that will work with AVR/Atmel Studio, and you can build one that'll work with the unpatched version of avrdude, but you can't build one that'll work with both.
Mike Tsao
www.sowbug.com
Sowbug
 
Posts: 9
Joined: Thu Nov 24, 2011 10:26 pm

Re: Can I build USBtinyISP onto Atmega32U4?

Postby smorehou » Thu Mar 22, 2012 4:08 pm

I don't need it to work with both. For my purposes, I couldn't care less about avrstudio. I'll read that link, thanks.
smorehou
 
Posts: 11
Joined: Fri Feb 24, 2012 4:11 pm

Re: Can I build USBtinyISP onto Atmega32U4?

Postby Sowbug » Thu Mar 22, 2012 4:23 pm

Oh, good. Then add LUFA_OPTS += -D LIBUSB_DRIVER_COMPAT to your Makefile, do a clean build, and you should be set.
Sowbug
 
Posts: 9
Joined: Thu Nov 24, 2011 10:26 pm

Re: Can I build USBtinyISP onto Atmega32U4?

Postby smorehou » Thu Mar 22, 2012 4:32 pm

Thanks, but I already had that set. I did read the manual :) I knew from the beginning I needed that set for use with AVRdude.
smorehou
 
Posts: 11
Joined: Fri Feb 24, 2012 4:11 pm

Re: Can I build USBtinyISP onto Atmega32U4?

Postby abqlewis » Thu Mar 22, 2012 9:18 pm

Sorry, I missed the fact that you ordered a Teensy in your OP. Teensy boards work for me in every other use but this one. I first got the AVRISP working on an Adafruit 32u4 board, and it works fine. Then I tried a Teensy. Not so much working. I would think that if it were a 32u4 problem, my adafruitU4 would have had the problem also. I've also loaded a recompiled version on a couple of cheap 32u2 boards with not problem (not bad for a $15 programmer). I worked on the Teensy problem for a while, and got it down to a problem with the /RESET line not staying low during programming. I gave up when I realized that my original Adafruit board still worked, so just used that.
abqlewis
 
Posts: 57
Joined: Fri Dec 11, 2009 1:19 am

Next

Return to Microcontrollers

Who is online

Users browsing this forum: No registered users and 4 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [114]

Raspberry Pi[82]
 
FLORA[24]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[12]
Arduino[60]
 
NETduino[14]
 
BeagleBone[23]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[39]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[9]


 
Breakout Boards[35]
LCDs & Displays[49]
Components & Parts[70]
Batteries & Power[54]
EL Wire/Tape/Panel[52]
LEDs[112]
 
Wireless[16]
Cables[66]
 
Lasers[6]
Sensors/Parts[147]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[41]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[25]


 
Stickers[41]
 
Skill badges[55]
 
Books[26]
 
Circuit Playground[7]
 
Gift Certificates[4]