Changelog:
November 17th, 2013:
0) Bug fix - the bootloader replied to an erase command with the wrong response.
November 16th, 2013:
0) I removed sizebefore and sizeafter from the makefile 'all' target. The line is still there, but it's commented so the size* targets aren't built by default. This should allow the project to build on both platforms without any issues.
1) AS6 solution files are now in the repository so the project can be built using GNU tools at the command line or in AS6 with an external makefile. You still have to modify the makefile to set the MCU variable in either case. If you choose to use AS6, you also need to set the MCU in the project settings.
2) I added support for all of the Xmegas currently in Atmel Toolchain 3.4.2.
====================================================
I thought I'd make a formal post about this since it's been a while. A few years ago, I worked on an AVR911 bootloader from Atmel with another member here. We made it much easier to use with the hope that more people would be able to benefit from a bootloader. Our experience at that point (and still today...) is that most bootloaders are overly complicated and abstract. This one hopefully isn't. If you have any questions, comments, or feedback, please let me know.
To acquire the source code, go to Github and download it using your browser (zip file) or with git. Here is the link to the repository. To clone the repository from the command line, please do this:
git clone git://github.com/bandtank/Xmega_Bootloader.git
To use the bootloader, open the makefile and edit this section:
############################################################################### # User modification section ############################################################################### # Choose one of the following MCUs: # If you have a different MCU, you will have to define these values: # Name in makefile Name in ioxxxx.h # --------------------------- ----------------------------- # BOOT_SECTION_START_IN_BYTES BOOT_SECTION_START # BOOT_PAGE_SIZE BOOT_SECTION_PAGE_SIZE # APP_PAGE_SIZE APP_SECTION_PAGE_SIZE # # You can find these files in the include path for your compiler. Examples: # 1) Winavr: C:\WinAVR-20100110\avr\include\avr\ioxxxx.h # 2) Atmel 3.4.2: C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\ # Native\3.4.2.1002\avr8-gnu-toolchain\avr\include\avr\ioxxxx.h # MCU = atxmega128a1 # MCU = atxmega64a3 MCU = atxmega64a3u # MCU = atxmega32a4 # MCU = atxmega16a4 # MCU = atxmega16d4 # Choose a baud rate for the UART. # If you need a baud rate that is not listed in this makefile, you must add # new configuration statements in config.macros.h. Remember, Xmegas start-up # with a 2MHz clock. # BAUD_RATE = 9600 # BAUD_RATE = 38400 # BAUD_RATE = 57600 BAUD_RATE = 115200 # Specify a pin to check for entry into the bootloader. The notation is # PORT,PIN. For example, if you wanted to use PIN 3 on PORTC, you would set # the option as C,3. Then specifiy the logic value required to enable the # bootloader code (1 = enable the bootloader if the pin is VCC, 0 = enable # the bootloader if the pin is GND). BOOTLOADER_PIN = B,2 BOOTLOADER_PIN_ON = 0 # Specify a pin to control an LED. The notation is PORT,PIN. For example, if # you wanted to use PIN 6 on PORTA, you would set the option as A,6. Then # specifiy the logic value required to enable the LED (1 = output VCC to turn # on the LED, 0 = output GND to turn on the LED). LED_PIN = D,2 LED_ON = 0 # Specify which UART to use with PORT,NUM notation. For example, UART1 on # PORTD would be D,1. UART = C,0
If the Xmega you plan to use is in the user modification section, then you're done. If it's not, then it should be easy to add by following the examples in the file. To find the required information, you'll need to search through the header files that came with your compiler.
If you're using the Atmel toolchain in Windows, you can probably find the files here (change the path as necessary depending on version numbers):
C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.1002\avr8-gnu-toolchain\avr\include\avr
If you're using Winavr in Windows, you can probably find the files here:
C:\WinAVR-20100110\avr\include\avr
Open the header file for your part and look for these lines:
#define BOOT_SECTION_START (0x10000) ... #define APP_SECTION_PAGE_SIZE (256) ... #define BOOT_SECTION_PAGE_SIZE(256)
Add those values to the makefile as follows:
ifeq ($(MCU), atxmega64a3u) BOOT_SECTION_START_IN_BYTES = 0x10000 BOOT_PAGE_SIZE = 256 APP_PAGE_SIZE = 256 endif
Make sure you set the fuses such that the bootloader section, not the app section, will be used after reset.
If you're going to use AVRDUDE to communicate with the bootloader, here's an example command line you can use once the bootloader is programmed onto your hardware:
avrdude -p x16d4 -P com6 -b 115200 -c avr911 -U flash:w:../xmegatest/xmegatest/Debug/xmegatest.hex
Add the -v flag (or -vv, -vvv, -vvvv) to see more detail in case you have issues. The output from the command shown above will look something like this:
Connecting to programmer: . Found programmer: Id = "XmegaBl"; type = S Software Version = 1.1; No Hardware Version given. Programmer supports auto addr increment. Programmer supports buffered memory access with buffersize=256 bytes. Programmer supports the following devices: Device code: 0xfa avrdude.exe: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.02s avrdude.exe: Device signature = 0x1e9442 avrdude.exe: NOTE: FLASH memory has been specified, an erase cycle will be performed To disable this feature, specify the -D option. avrdude.exe: erasing chip avrdude.exe: reading input file "../xmegatest/xmegatest/Debug/xmegatest.hex" avrdude.exe: input file ../xmegatest/xmegatest/Debug/xmegatest.hex auto detected as Intel Hex avrdude.exe: writing flash (404 bytes): Writing | ################################################## | 100% 0.08s avrdude.exe: 404 bytes of flash written avrdude.exe: verifying flash memory against ../xmegatest/xmegatest/Debug/xmegatest.hex: avrdude.exe: load data flash data from input file ../xmegatest/xmegatest/Debug/xmegatest.hex: avrdude.exe: input file ../xmegatest/xmegatest/Debug/xmegatest.hex auto detected as Intel Hex avrdude.exe: input file ../xmegatest/xmegatest/Debug/xmegatest.hex contains 404 bytes avrdude.exe: reading on-chip flash data: Reading | ################################################## | 100% 0.08s avrdude.exe: verifying ... avrdude.exe: 404 bytes of flash verified avrdude.exe done. Thank you.
If AVRDUDE doesn't support your xmega, you can add support by editing avrdude.conf. My advice is to search the file for an xmega similar to the one you want to use. Copy the whole section, paste it in the file, and then change the necessary parameters. For example, the xmega16d4 isn't supported by AVRDUDE 5.10, but I added it by copying the configuration for the xmega16a4 and then changing the first few lines:
#------------------------------------------------------------ # ATXMEGA16D4 #------------------------------------------------------------ part id = "x16d4"; desc = "ATXMEGA16D4"; signature = 0x1e 0x94 0x42; has_jtag = yes; has_pdi = yes; nvm_base = 0x01c0;
I edited the id, desc, and signature. You can find the signature bytes in the datasheet.
Finally, here's a test program you can use to see if the bootloader works. It's the same program as the one I used to generate the output shown above. Clone it with this command:
git clone git://github.com/bandtank/xmegatest.git
The code is very simple:
#includeint main(void) { PORTD.OUTCLR = PIN3_bm; PORTD.DIRSET = PIN3_bm; while(1); }
Change it to do anything you want, but my recommendation is to keep it simple at first if you want to test the bootloader.