Bootloaders for AT90USB1286
While the AT90USB1286 MCU in the Teensylu/Printrboard can be programmed with an ICSP or JTAG programmer, you can also install a bootloader, which will allow you to program it via a USB connection alone. Besides the convenience of not having to attach a hardware programmer, uploading firmware via a USB bootloader is blazingly fast. Also, it allows you to write host software to do end user firmware upgrades without a hardware programmer.
I am currently aware of 3 bootloader options for the AT90USB128x MCU’s:
DFU – USB Device Firmware Upgrade Class
This is the bootloader officially supported by Atmel.
PRO: Works with Atmel FLIP tool.
CON: requires libusb device driver; no command line tool available for Windows. For Linux, an open source host loader app is available; can’t integrate into Arduino IDE
CDC – USB Communication Device Class
PRO: can integrate into Arduino IDE; works with avrude via avr109 protocol.
CON: requires user to know which virtual serial port it’s associated with; in Windows, uses native Windows driver, but requires INF file install, needs upgrade of avrdude to newer version for Arduino < 1.0.
HID – USB Human Interface Device Class
PRO: Trouble free – doesn’t require any device drivers – just plug and play
CON: doesn’t integrate into Arduino IDE
Fuse Settings
Before you can install a bootloader on your MCU, you must set the fuses correctly to allocate space for it. We need 4K bytes (2K words) of space, so using the Engbedded Atmel Fuse Calculator, we see that we need Boot Flash Size BOOTSZ=01, which is in the high fuse. Here are the fuse settings that I use on mine:
avrdude -c usbtiny -p at90usb1286 -U lfuse:w:0xde:m -U hfuse:w:0xdb:m -U efuse:w:0xf0:m
BE CAREFUL IF YOU WANT TO FIDDLE WITH FUSE SETTINGS YOURSELF. It’s not hard to “brick” your AVR with the wrong settings. In fact, when I was first working with my Printrboard, I managed to brick it by messing up the CKSEL bits, thinking I was supposed to set it for an external oscillator. Luckily, all I had to do was connect an external oscillator (I used the signal generator function of my DSO Quad mini scope) to XTAL1 and then use avrdude to fix the offending fuse. If you do something worse, like disabling SPIEN by accident, you might have to resort to HV programming. Here is some info on recovering a bricked AVR: http://www.larsen-b.com/Article/260.html
Note that I have set hfuse = 0xdb, which disables the JTAG interface. This makes more I/O pins available (in particular, some of the pins exposed on the I/O headers of Printrboard). If you want to use a JTAG programmer, you should instead set hfuse = 0x9b.
Once your fuses are set correctly, use avrdude with your programmer to upload the bootloader. After your bootloader is installed, you don’t need to use the programmer anymore – just a USB connection is enough.
Booting into Bootloader
Once a bootloader is installed (see instructions below), the bootloader must be activated when you want to upload firmware. To boot the AVR into the bootloader instead of normal program code, you must tie the HWB pin to ground during a RESET pulse. To to this on Teensylu or Printrboard, simply remove the 2-pin jumper that’s next to the AT90USB1286 chip, then press and release the reset button. You can then replace the HWB jumper.
NOTE: If you have a Printrboard RevD, the jumper has been reversed, and needs to be INSTALLED to get into the bootloader, and REMOVED to run your firmware.
Below, I describe how to install and use each of the bootloaders. For Arduino IDE integration, use BootloaderCDC. I also like BootloaderHID, because it doesn’t need drivers, and doesn’t require selecting a virtual serial port.
DFU Bootloader
- Download and install FLIP. FLIP will also install the device driver.
- Download BootloaderDFU.zip. I built this one for AT90USB1286 from LUFA-120219.
- Install with avrdude: avrdude -c usbtiny -p at90usb1286 -U flash:w:BootloaderDFU.hex:i (note if avrdude complains of a verification error, ignore it)
- To flash hex files to board, after Booting into Bootloader, use FLIP or dfu-programmer.
CDC Bootloader
- Download BootloaderCDC.zip. I built this one for AT90USB1286 from LUFA-120219.
- Install with avrdude: avrdude -c usbtiny -p at90usb1286 -U flash:w:BootloaderCDC.hex:i (note if avrdude complains of a verification error, ignore it)
- To flash hex files, you’ll need a newer version of avrdude than the one included with Arduino < v1.0. The version I use is 5.10. After Booting into Bootloader (the first time, Windows might want a driver … point it to the INF file that I included) , type: avrdude -c avr109 -P port -p at90usb1286 -U flash:w:firmware.hex:i, substituting your Printrboard’s CDC serial port for port, and the name of your hex file for firmware.hex.
- If you want to flash directly from the Arduino IDE, follow my instructions for installing my at90usb1286txt.zip files into Arduino. Then, after restarting Arduino and Booting into Bootloader, select [BootloaderCDC]Teensylu/Printrboard from the Arduino Tools->Board menu. Then select the serial port associated with your board. Hit the Upload button in the Arduino IDE to compile and upload your sketch.
HID Bootloader
- Download BootloaderHID.zip. I built this one for AT90USB1286 from LUFA-120219.
- Install with avrdude: avrdude -c usbtiny -p at90usb1286 -U flash:w:BootloaderHID.hex:i (note if avrdude complains of a verification error, ignore it)
- To flash hex files, after Booting into Bootloader, type: hid_bootloader_cli -mmcu=at90usb1286 -w -v firmware.hex, substituting the name of your hex file for firmware.hex. I’ve included the Windows binary. For Linux or OSX, you can build hid_bootloader_cli yourself from the LUFA sources.
NOTE: When uploading a bootloader to the AT90USB1286 using a USBtinyISP, you will get a verify error from avrdude. You can safely ignore it. The problem is that the USBtinyISP has a bug with reading flash memory above the 64K (10000h) boundary. However, it can write it without problems.
There are 59 Comments to "Bootloaders for AT90USB1286"
Hi,
First of all, thank you for putting all this information out there for us to use!
I wondered if you might be able to help with my issue?
I received my Printrboard with the CDC bootloader and Marlin installed, however a friend of mine didn’t. Mine is Rev.D and his is Rev.B. I bought a USBtinyISP to update his firmware and thought I’d check it on mine first. Everything checked out and I’ve gotten both boards updated, however… I used to be able to update the firmware with the Arduino IDE but now I can’t. It seems as if the boot jumper isn’t making any difference, I’ll explain.
Before updating, when my board was working with the Arduino IDE, upon installing the jumper (Rev.D) and pressing the reset button the serial number changed to a different number from the one displayed without the jumper (from 12341 to 3d11) and I could upload new firmware.
Now, after updating the bootloader and booting into it, the serial stays the same, Arduino gives a “Java.Lang.nullpoint” error upon uploading and I can still connect / print via Pronterface (which I’m assuming I shouldn’t when in bootloader mode).
Do you have any suggestions? I appreciate your help.
Colin
I think they reversed the jumper in Rev.D. In my rev B/C boards, you remove the jumper and press reset to boot the bootloaders.
Open up Windows Device Manager and look under Ports (COM & LPT).
When the board’s in bootloader mode, you should see it as Communications Port (COMx).
When it’s running the firmware, you should see it as Usb Serial (Communications Class, Abstract Control Model) (COMx)
One problem may be that the original bootloader you had was improperly using a different USB VID/PID.
I’m assuming you used my BootloaderCDC.zip. Assuming that bootloader is flashed into your Printrboard,
with the jumpers set for bootload, right click on it in Device Manager, select Update Driver Software from the popup menu,
and then point it to the INF file that I included. Hopefully, that will make it recognize the bootloader properly.
If the bootloader is installed properly, then you should be able to flash the firmware using avrdude, as in my article above.
Let’s get avrdude working properly first, then we can figure out what’s wrong w/ Arduino.
Hi,
After searching the depths of the internet I found a forum post where someone had a similar issue with an adafruit board. This resulted in me adding : “cdcteensylu.bootloader.path=undefined”
to the teensy/boards.txt file and now I can program my Printrboard with the Arduino IDE!!
JOY!!
FYI I’m using OSX 10.7 so things were a little different but with the Marlin firmware loaded I see “USB Serial” in System Information and after I set the fuses, uploaded your CDC Bootloader and booted into the bootloader, System Information then said “AVR CDC Bootloader”. From there I uploaded the Marlin firmware with the Arduino IDE and it all worked.
Again, thanks for you help. Your work has been incredibly valuable and I appreciate you posting about it all in your blog. Keep up the great work!!
Colin
Ah, I wish you’d mentioned you were using a OSX. Anyway, glad you got it working, and thanks for posting your fix… perhaps it will help someone else get it going.
When setting the fuses, I found that I had to add -u (note lowercase) to disable ‘safe mode.’ I verified this by reading the fuses back, using -U lfuse:r:low.txt:h (and similar for high and ext).
I don’t see this -u option mentioned here, or in any other AVRDUDE article on setting fuses… am I the one missing something or is everyone else?
What version of avrdude are you using? While the documentation says that it’s needed for updating fuses, I’ve never had problems with not specifying -u
I got the latest version I could find: Version 5.11-Patch#7610
I just discovered that the -? option says this:
-u Disable safemode, default when running from a script...and I did use (DOS/windows) batch files for everything. ..so perhaps safemode is _not_ active _unless_ running from the a batch file?
I think you nailed it on the head. I just checked some batch files of mine, and they have -u in them.
[...] CDC Bootloader, courtesy of Lincomatic – Link [...]
[...] for this post goes to Lincomatic. I’m posting my methods and what I did to get my board working. I also think having this [...]
Hi im new with printrboard tested before mezli and sanguinololu have two repraps few days ago i have bought printrboard for new project and got one problem which i hope u will help me to solve
i got comunnication problem with my board and system i have try on win7 and xp and cant connect to the board i have installed stuff from printrboardfarm file but this still dose not work could u recommend some procudure to help me link my board with prontarface ?? thanks a lot
Hi,
I followed the instructions on the http://reprap.org/wiki/Printrboard#Installing_A_Bootloader and i used there fuse values and it completed with the errors like you stated it updated to the new bootloader now its bricked.. it will not register at all on any machine windows/linux/OSX. How can i de-brick this board? i checked ur link but i am unsure what any of that means. Any help would be greatly appricated.
Thanks
James
The only way you can actually “brick” the board is to mess up the CKSEL bits.
If you can still burn a bootloader, then you just need to redo it.
Try following the article above.
I can’t see the board on the pc and if i connect my USBtinyISP to it and try to re run the commands it fails not finding the printrboard. and the post you linked about using an external clock i have no idea how to implement. I am at a loss on how to accomplish getting back to a reprogramable state.
Ouch, OK, I didn’t know that you were having trouble w/ the USBtinyISP as well.
The other thing besides CKSEL that can make the USBtinyISP not work is if you disabled that via the SPIEN bit in the high fuse.
But you were able to write a bootloader to the board after setting the fuses, right?
If so, then the fuses are not your problem.
Did you make sure to remove the jumper (Printrboard Rev A-C .. RevD the jumper should be installed) and hit reset before trying to reload the bootloader?
I put the jumper on to get it into Bootloader connected the 6pin pin1 (red) closest to SD slot plugged the usb into the USBtinyISP ran those two commands. I think it errored on the fuses bits and asked me if i wanted to continue or revert.. and i didn’t reverse. But it downloaded the new bootloader failed on verification like it should have but now its just done plug it in and the light comes on but nothing won’t load on the OS regardless of jumper. would this be easier on an AIM or IRC thing I hate to fill up your comments section with nub stuff
I’m no expert on this stuff. If the fuses got messed up, you have to follow the instructions in the linked article for unbricking. In my case, I knew exactly which bits I messed up, so clocking it with an external oscillator woke it up to a state where the USBtinyISP was working again. If the USBtinyISP can still see your board then just follow my instructions above.
i got the bootloader to go without hassle but the board will not boot. was a driver issue before but no matter what bootloader i put on it.. windows will not find the board and i cannot load firmware to the board using your modified teensy files. Can you tell me exactly what version of IDE you use and what else you’ve changed as of right now i have a controller i cannot use but is programable via USBtinyISP and with the CDC bootloader windows can find it but not upload any firmware. and with the DFU bootloader or HID bootloader windows cannot see the board. I am at a loss
After you install my CDC bootloader, you need to use my INF file in order for Windows to see it. If you manage to install firmware on it via the bootloader, then you will need to use Teensy’s INF file to see it as a serial device.
Another way is use my [usbtinyisp]AT90USB1286 board setting, and just load the firmware directly instead of installing a bootloader.
I am using the Arduino 0022 setup thats linked from reprap-usa.com’s Printrboard product page. I sent them my Arduino files because they were having trouble configuring it properly
after much tinkering and swearing and drinking i managed to get HID bootloader working and got sprinter firmware on my board and pronter see’s the board and the printer moves.. YAY
I am attempting to debug the sprinter code with Arduino 1.0.1(I’ve tried -0022 and -0023!). Our customer wants us to use the CDCBootloader in the Rev.D. I got the fuses and bootloader installed by erasing the entire AT90USB1286 via Atmel Studio 6\Device Programmer(I know now, I can insert either -u or -e to override to erase the lockbits). I have followed lincomatic’s instructions to a “T”, except attempting to use Arduino 1.0.1(Customer preference!)
Can you explain how you got sprinter to cooperate with Arduino?
Also, I am a noob to the software programming field. I am a Electronics Tech, and a recent Arduino UNO hobbyist.
Any help you can give is greatly appreciated.
I haven’t tried to compile anything for AT90USB1286 with Arduino 1.0+.
For Sprinter, I had to make a bunch of changes to get the pin assignments correct,
but Kliment accepted my changes a long time ago.
Maybe you can try compiling my branch first https://github.com/lincomatic/Sprinter
Did you figure out what you were doing wrong?
What was the trick to get it working?
I just replied to the James you conversed with the last few days.
First off, thank you muchly for your hard work in keeping this blog up and all your leg work you have done to make the PrintrBoard function.
I am new to the C\C++\Arduino programming. I am attempting assist our customer with the set up of the Sprinter\Arduino programming. My limited experience is showing.
My problem is that Arduino(1.0.1,-0022, or -0023 in WIN XP Pro SP3) and Sprinter(kliment-Sprinter-de2feb0) fail to link. Here is what I am seeing:
“In file included from arc_fuc.cpp:26:/ Sprinter.h:6:23: warning: Arduino.h: no such file or directory”. There are several other errors, two more state “no Arduino file or directory”. I am an electronics technician by trade, an Arduino fan by hobby.
Any assistance would be greatly appreciated!!!
Arduino.h is part of Arduino 1.0+. For older versions of Arduino, it should include WProgram.h instead.
It’s possible that the particular snapshot of Sprinter you downloaded has compile issues.
Can you try downloading a different version? Also, you can
try using my Arduino setup and see if that works better. http://www.reprap-usa.com/download/arduino0022.zip
Thanks for answering.
I downloaded the Arduino-0022 from RepRap this morning, just found it.
I will get another version of Sprinter when I’m done answering this blog.
I also downloaded your Marlin RC2 firmware and am attempting to just get a good download at this time.
I took your advice to use all your modified software and an older version of Sprinter, succeeded in programming the first production unit.
What had me stopped for a while was initialization errors with avrdude5.5. I pulled a stupid tech trick and placed the usbtinyusb 6 pin cable backwards on the header!
We are currently doing setup for the functional test.
I wish to thank you again for your assistance of this blog site and your reply.
Do you mind my asking what company you are from?
I work for AMIEMS,Inc, a contract electronics manufacturing and services provider.
This product is for a 3D printer company( cannot disclose name). I am the lead electronics tech for the Test Dept.
I forgot, we out of Winthrop,Maine.
Cool. I might have a need for your services at some point in the future.
Let me know when you may need us and I can set you up with our Sales staff.
I don’t know if this matters for USBtiny but I was having a heck of a time trying to program the bootloader onto my Printrboard (rev D) it was taking 3 hours to run and still not working and all I had to do was add -u (turns off safe mode) to the avrdude commands (for setting fuses and programming the bootloader) and everything worked perfectly in 30 seconds.
Hope this helps
Just to clarify the first sentence, I was programming with the the Pololu AVR programmer so I don’t know if the -u is also needed for the USBtiny or not
That’s strange. -u turns off checking that fuse bits didn’t get corrupted.
Are you sure your fuse bits didn’t get changed?
I don’t have to use that w/ USBtinyISP.
When I would run it without the -u command, I would (only sometimes which is strange) get a response saying that the fuse bits had been changed to 2 and if I wanted to change them back to 0x9B or whatever and I would say ‘y’ and then it would just timeout for a long time and nothing would happen.
Sorry for some reason I wrote a new post instead of replying.
Andrew, it might help you to use -e instead of -u. E.g., if you want to rewrite all the flash and EEPROM. I had to erase and then load fuse bits, then used CDCBootloader.hex. It looked like this:
avrdude -c usbtiny -p at90usb1286 -e -U lfuse:w:0xde:m -U hfuse:w:0xdb:m -U efuse:w:0xf8:m
It really helps to clear those lock bits first. remember, the AT90USB1286 comes preloaded with HID bootloader and lock bits set so to not allowed accidental erase or rewrite
Okay I’ll keep that in mind if I have to mess with this again.
alright soooo heres my issue and no can seem to figure it out.. lastely me.. i need marlin firmware but i also what to be able to directly upload from Arduino IDE.. so i wen’t and got a stock copy of 022 then got teensydunio for that version of IDE. downloaded my firmware from your github.. complied it without errors.. but it for the life of me will not uploadfirmware to the board. I have the jump set to boot into the bootloader and it gives this error
“avrdude: ser_open(): can’t set dtr for “\\.\COM2″
which is the com port my board is on. so i don’t know whats up.. here my pastebin of flashing your BootloaderCDC.
http://pastebin.com/P6Wz9AHR
any help would be appricated
1) are you sure the boot jumper is in the correct position? if in doubt, try both. on my Windows machine, the com port number changes between the two settings
2) have you followed the instructions in the RepRap wiki?
3) please try using my pre-hacked arduino-0022.. there’s a link from RepRap USA in the comments section of this article
http://blog.lincomatic.com/?p=537
So I went and grabbed that copy of the arduino from RepRap USA.. and i did a file compare to mine from yours and it turns out your version has the avrdude.exe in it that is newer than the one in mine.. so i tried your copy.. uploads fine.. so i copied the avrdude and other avr files from the RepRap USA copy to my copy of arduino-0022 now my copy uploads fine.. think just an older version of avrdude caused my issues.
Cool. Glad you got it working.
Hi
Newbee to this, so my question might be very simpel.
I have a printerbot working just fine. Some modifications, but over all super enjoy and introduction to the field 3D printing.
I like the board printerboard rev D, onboard stepper controllers etc, so I ordered one for other other application and developement.
I thourght it was very easy to do the first simpel test.
Compile “blink” with Arduino, and use flip to program the board.
It seems to work fine, there is just one wrong thing….
I’m using pin 46 im my file, but seems like the output goes to pin 61
What am I missing ?
Tryied selecting different board types in Arduino software.
Can see hex file changes, but all give output to pin 61 and not 47 as expected.
Is the board in some way locked
Allan Pedersen
Denmark
I think maybe you are assuming the logical pin numbers used in Arduino code match the physical pin numbers on the AT90USB1286?
They are actually arbitrarily assigned by Teensyduino.
You can find the pin mappings in core_pins.h:
////////////////////////////////////
// Teensy++ 1.0 & 2.0
////////////////////////////////////
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
#define CORE_NUM_TOTAL_PINS 46
#define CORE_NUM_DIGITAL 38
#define CORE_NUM_ANALOG 8
#define CORE_NUM_PWM 9
#define CORE_NUM_INTERRUPT 8
#define PIN_D0 0
#define PIN_D1 1
#define PIN_D2 2
#define PIN_D3 3
so digital 0 = PIN_D0, which is physical pin 25.
The pins actually end at 45:
#define PIN_F6 44
#define PIN_F7 45
So you can’t use any number higher than 45 for calls to digitalRead()/digitalWrite().
But if you are using my fastio.h from Marlin, then you can use fastio for
46 = PE2 = physical pin 43
47 = PE3 = physical pin 9
Which pin is pin 61 on Printrboard? I don’t understand the results you are getting.
Thanks for reply
I have found your post on the pin issue.
Yes was assuming that the logical pin numbers match the physical pin numbers
I made an error in my post… I’m using pin 39 to the blink test… according to diagram printerboard rev B ( not able to find printerboard rev D diagram ) it should be HotBed ( PC4_A12_0C3C)… but output appears on pin 60 according to diagram E-Therm (PF0-ADC0) . I have changed frequency etc to make sure I’m not getting cheated af something else. I’m using your 0022 Arduino version.
So I guess it should be okay to use Teensylu\printrboard as selected board in Arduino 0022 to compile, even it is saying CDC Bootloader ? It works fine execpt for the pin issue, witch i’ll have to correct looking to core_pins.h
After compile, I’m using Flip to program.
Allan Pedersen
Denmark
Yes, you can use Teesylu/Printrboard CDC to generate the code. The hex file doesn’t care which bootloader you’re using, so you can just use FLIP to upload
Hi again,
Been looking around but not much info other than here
So what I have to do is #include to my sketch ?
If I can’t use digitalRead()/digitalWrite() pinmode(), what to use then?
Allan Pedersen
Denmark
You can either use the macros fastio.h from my fork of Marlin: https://github.com/lincomatic/Marlin/blob/Marlin_v1/Marlin/fastio.h
46 = PE2, 47 = PE3
Or, you can just add the definitions to core_pins.h, and use digitalRead/Write()
Hi
I am having a bit of trouble uploading firmware to the printrboard i believe i have the DFU bootloader it even connects to flip. I try an upload with flip and if i have the verify step ticked it comes back with an error if i untick that step i looks like it uploads fine.
From what i am seeing it looks like the flash is not being erased of written too.
i have also tried this from a linux box with dfuprogrammer but it look like i am getting the same resolute.
I have just bought a USBtinyISP to see if i can write it that way.
does any one hava a suggestion i can try while i am waiting for the USBtinyISP to arrive.
I have a rev B board and have tried uploading a hex file i created and the default firmware that came with the board.
also the board only talks to me when i am in the bootloader and won’t talk to me when booting the firmware.
Thank for the info this has been one of the most help places to understanding the printrboard.
Lincoln
Some vendors ship w/ the CDC boot loader. Perhaps you should try to upload w/ CDC
I got the printrboard from printrbot and from what i have been reading that is what is loaded on all of theres.
Do you know a way i can find out the bootloader version?
Thanks
Lincoln
Lincoln,
You may be able to verify the firmware bootloader version by verifying it against the one you think it is (DFU,CDC,HID) with Arduino software. If you use an Atmel programmer, you can read the file and verify with Atmel Studio. I can’t remember if you can how to verify using WinAVR.
Actually, it’s avrdude that can help. To check for CDC:
avrdude -c avr109 -p at90usb1286 -P\\.\comX
replace X with your comm port number
It’s very unlikely that the HID bootloader is installed, but if you want to test, try my instructions for hid_bootloader_cli above.
Sorry about that about the avrdude. I went back and saw the mistake. I had the flu last week and some things got messed up. Did Lincoln get his problem solved?
I’m not sure, he never replied.
Hi guys
After a bit more digging in found out that I some how had locked parts of the flash.
I was using the right tools to talk to the printrboard but it just wouldn’t wipe or write.
I only got this fixed after getting my USBtinyISP and flashing the bootloader from this Page is am now using the dfu bootloader and have flashed the repetier firmware by the bootloader.
Does anyone have an idea on the commands for flashing a firmware by the USBtinyISP?
Thanks for putting up this information this the only place I have found with any information that has been any help.
Thanks again
Lincoln
Hi,
I have a V2 Linear Prusa wired up with printrboard (CDC), Got all the programs running and compiled sprinter succesfully. (Arduino 0023) installed all programs and files stated here. As I read above, I’m having the same problem, arduino returns:
” avrdude: ser_open(): can’t set dtr for “\\.\COM5″ ”
after upload. (the compile works fine though)
Normal printrboard state will connect with com4 on my pc and when booting it changes to com5 like it sould.
For James updating the avrdude.exe, and the files fixed the problem,
becuase I use arduino 0023 I can’t use these (I tryed, gave me version errors)
Could I try something else to fix this specific error?
Thanks in advantage.
Regards,
Ward
The only way is to update the avrdude.exe. What kind of errors are you getting?