XBoot – Quick Start Guide (for a sweet XMega bootloader!)

So in my recent XMega wanderings, I needed a good bootloader. After muddling through various app notes and forum postings, I came across the culmination of what I couldn’t do on my own – XBoot!

In my defense, I’ve worked on bootloaders before. But the errata sheet on the XMegas is longer than the list of men Princess Leia has broken the hearts of. And I’ve become one of the many casualties of that list. (Erm, the errata list… awkward…)

Big thanks to Alex Forencich! XBoot, a fantastic reincarnation of the AVR1605 app note, is open source and highly configurable bootloader, which at the time of writing is capable of UART or I2C bootloading XMega processors. I believe his intentions are to expand both processor compatibility and protocol options, so visit the XBoot Google Code project for more info.

I’ll be going through and explaining the options that I used, so this isn’t an exhaustive tutorial. This guide assumes you have a working XMega development environment, AVRDude installed, and SVN (if you want to download the code this way). WinAVR should work just fine with a few minor alterations, but I’ve only tested this on Kubuntu with the development environment described in this previous blog post. Also, as a side note, I’ve been using XBoot with XBee Series 1 wireless modules and it works fantabulous (that’s so good, I had to come up with a new word for it).

Download the Code

So let’s get started. Download the code from the XBoot download page and uncompress it, or (my preference) use SVN to download the code:

svn checkout http://avr-xboot.googlecode.com/svn/trunk/ avr-xboot

Configure XBoot

Once the code is downloaded, find the file named “xboot.h”. Most configuration changes, if not all, will be made here. We’ll take it one section at a time. Line item references are from Rev12 out of the repository, but you should be able to match them up to any version. The idea is that all available options are enabled, so comment out what you won’t be using.

Uncomment this line if you’ll be using an XMega256a3. This fixes certain problems (remember Princess Leia the errata list?). I’ve heard this has hit some people but not others, even on the same silicon revision. It may be useful for certain other chips and families – YMMV. Check with Google if concerned.

Here I picked the “USE_ENTER_DELAY” and “USE_ENTER_UART”, hence I commented the other two out. Note that the “USE_ENTER_DELAY” just puts a delay at the start of the program, and isn’t mutually exclusive with the other options. Here’s what the options mean:

USE_ENTER_DELAY: Delays entry by a timeout. Timeout is set by “ENTER_BLINK_COUNT” and “ENTER_BLINK_WAIT”, but I found the default settings worked well.

USE_ENTER_PIN: Select this option if you want to enter the bootloader when a pin is in a certain state at power on. Ex: You press a switch when you power cycle to enter the bootloader. You’ll have to configure which port/pin at line 95, at the section titled “ENTER_PIN”.

USE_ENTER_UART: Select this option if you want to enter the bootloader if a character is received on the UART. This requires using “USE_ENTER_DELAY” by necessity. You’ll need to configure the UART options at line 111.

USE_ENTER_I2C: Select this option if you want to enter the bootloader if a byte is received through I2C. I haven’t used this option, hence I won’t try to elaborate.

Should be pretty self-explanatory. You should only need to change UART_BAUD_RATE, UART_PORT, UART_DEVICE_PORT, and UART_TX_PIN. If you use an exotic baud rate (non-standard and/or fast), you might want to change the settings at line 51 and select the 32MHz clock option.

That’s pretty much it for this section!

Compile & Program

This should work if you’re using AVR-GCC in Linux. I can’t vouch for WinAVR, but it shouldn’t take much to change it. That said, the only thing that really needs to change in the Makefile is the programmer name and the chip you’re compiling it for:

And I’m using an AVRISP mkII programmer, which is pretty cheap for an authentic Atmel programmer. It only does PDI programming (no debugging), and needs to be updated to the latest firmware using AVR Studio (sorry, penguins – you’ll have to boot into Windows), but it does the XMega trick right nicely.

To compile and subsequently program:

$ make
$ make program

This should compile and program XBoot into the programmer. Shazaam! If you get any errors, feel free to leave me a comment and I’ll try to help you out.

Programming an Application Via XBoot

So now that you’ve got XBoot loaded, you can use AVRDude again to program your application to your XMega:

Hello, i have some issues with reentering bootloader. I’m able to program it only once. After reset it waits 3 sec but i cannot upload new firmware. Any help is appreciated. Here is my config code:
// Configuration

Quite a few things could be in play, but more info is needed to diagnose the problem. What chip are you using? When you say you can only load it once, do you mean load a main program using the bootloader, or the bootloader only responds once and then the main program doesn’t run?

A couple general suggestions: Do you have a solid UART connection? Using a regularly flashed program, can you see bidirectional UART data?

It could also be that you’re not loading it into the right Flash address. This shouldn’t be a problem if you’re using the included Makefile.

MBear

18 January 2011 at 3:30 AM

Oh i forgot to mention, MCU is Xmega128A1. It is connected via ftdi (usb-uart) so i don’t think that problem is in connection.
Yes, i can load main program using bootloader, and it start its execution without any problem. I’m loading xboot from AVRstudio..Because with make all i only get compiled code…Avr dude isnt started at all. I have Windows XP OS.
Thanks

As I’m not a windows guy, I don’t know how it works in AVRStudio. I’ve heard mixed results. But it’s awfully hard to troubleshoot a toolset I’m not familiar with ;)

Sounds like it could be one of a few things:
1) The program isn’t loaded correctly. Give the “make program” with AVRDude another try.
2) Are the fuse bits set correctly? Again, the Makefile does this for me. Refer to the makefile for the correct settings.
3) The bootloader entry settings are incorrect. Try the default wait timeout settings, I’ve had trouble modifying this. Disable the watchdog and other features until you get it to work, then add them back in one at a time.

Oh i forgot to mention, MCU is Xmega128A1. It is connected via ftdi (usb-uart) so i don’t think that problem is in connection.
Yes, i can load main program using bootloader, and it start its execution without any problem. I’m loading xboot from AVRstudio..Because with make all i only get compiled code…Avr dude isnt started at all. I have Windows XP OS.
Thanks

I’ve same problem too
I think avrdude can’t erase the chip before programming at second time

I’m not sure what your problem is. If you’re asking for help, I need more details.

Without more info, all I can say is check to make sure that you’ve picked the correct processor in both the makefile as well as xboot.h. Make sure that baud rates match. I would highly, highly recommend using “make program” to load the bootloader. Bootloaders are not trivial – if you don’t know what you’re doing and things aren’t working, follow someone else’s lead (not mine by the way – Alex Forencich was the one who saved my bacon ;).

AVRDude does not have a problem – it’s worked dozens of times over for dozens of people. Make sure the makefile is set up properly.

Hello! Thanks for the great Bootloader, but i have a small problem. Writing flash with avrdude is working, but EEPROM i always get a Error.
Comand is:
avrdude -p atxmega128a1 -P com5 -c avr109 -b 115200 -e -Uflash:w:greenController.hex -U eeprom:w:greenController.eep -v

I haven’t ever needed to write eeprom data using this bootloader, so I’m not sure. You might try the AVR1009 workaround, as it uses interrupts to write eeprom. You might try checking the AVRFreaks.net forum postings on this bootloader.

Prasanna

5 December 2011 at 1:40 PM

Hey… I had the same problem…. was using XBee(@115200)…. I got to know that Xbee doesnt support high data rates…. I lowered the data rates(@38400)…. Problem resolved….!!

Thanks for the heads up – WordPress must’ve changed something. I just added a carriage return and saved again – problem gone.

For the code sections (which don’t have scroll bars and are inordinately short widths), I just copy and paste them when I need to see them. Sorry, WordPress sucks and/or I’m too much of an idiot to figure it out.

Felipe,
I just ran into the same thing. Programming x32a4u. AVR dude for some reason is sending a request for a block read of EEPROM, and the bootloader does not respond. See if you get the below after adding a couple more “-v” to your AVRdude command.

I have use the bootloader in the past, but now it does not function properly.

I have a atxmega32a4u, only think i have to change is usart from C to E. My serial is connect to USARTE0. USART works properly, can send data and recive data. And i can programma chip via pdi, works al fine.

Any Idea why this would work only once for me?
I have BOOTRST set appropriately but it’s acting like it’s not.
In other words, I burn the bootloader, then I can download my application via USB serial. After that the Bootloader never runs. I’m using USE_ENTER_DELAY and USE_ENTER_UART, so I would expect it to wait 3 seconds or so, but instead, my application does a printf right away and it spits it out on the serial port immediately after reset.

I manually set the bootloader lockbits to write protect, and reading out the contents of flash shows that the bootloader is still there.

Hi there,
XBOOT works fine for me, the challenge I am facing is programming XBOOT into the controller.
It does work with ATMEL Studio6 when I confirm the error message that pops up. However when I want to use AVRDUDE or atprogram from the studio as command line tool both report that the memory area I want to write to is beyond the 64K range of my Xmega64a3u.
So currently I can only get XBOOT into the device with the studio6 GUI.
Is there any trick to burn it in including fuses in one go via command line?
Any help is appreciated, thanks and regards
Thomas

Which version of AVRDUDE are you using? Possibly try a different version. Also, there may be a switch somewhere that tells AVRDUDE to be flashing into the boot space, rather than the program space. Wish I could be more help, it’s been a year or two since I’ve used an XMega so I’m not up to speed with this bootloader anymore.