[TUT][SOFT] Xmega bootloader available

Go To Last Post
37 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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:

#include 

int 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.

Last Edited: Mon. Nov 18, 2013 - 02:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This seems too good not to keep somewhere special so I'll edit the title and move it to the Tutorial Forum.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for this!

But.. How do you build this? I have AVR Studio 6.1.2730 svc pack 2. Sorry I've only ever started projects from scratch in AVR Studio so I do not know how to import this for building and programming.

I have retrieved it, and modified it for my flavor of XMEGA.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all!
As Deathcow, I'm lost regarding the building of your bootloader. And if I try to compile it from a cmd window, it does not work (saying -f was unexpexcted...).
I will look at your makefile and try to make a new Studio 6 project for this bootloader.

Thanks for your work, bandtank !

Have a nice day,
Kraal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi again,

Deathcow, I have created a new project under Studio 6.1, with the name "Xmega_Bootloader" for my device, ATXmega128A1U. Then I've overwrite the newly created Xmega_Bootloader.c with the one from the git repo, and copied all the other files inside the solution directory, except the .git, the README and the makefile.
Then I opened said makefile in Studio to see its internals. What you have to do is to look at the lines 107, 111 and 117.
Line 107 will give you the symbols to define in the project properties->AVR/GNU C Compiler->Symbols (10 including MCU and F_CPU).
Line 111 tells you to add those same flags to the ASM flags (project properties->AVR/GNU Assembler->General).
Line 117 tells you to relocate the .text section to the start of the boot section of your xmega (project properties->AVR/GNU Linker->Misc). And that should do the trick. I will add the DFLL to have a better precision on the USART.

Bandtank there is a BOOTUP_DELAY symbol which is not used nor defined. Did I missed something here ?

Now it compiles, but I have to test it with AVR OSP.

Have a nice day,
Kraal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AS6 has "Create project from Makefile" on the Tools menu. I just attempted to use this after having git clone'd the files (and test built them using the old WinAVR tools). The As6 process was not entirely successful in that it ended with the Solution Explorer constant showinf "(loading)" but never completing. I looked at the .atsln and .cproj files it had created and it turns out that the .atsln still referred to a .cproj file in my %TEMP% directory which was no longer there. However it HAD created the .cproj file in the project directory so I just edited the XML of the .atsln file to fix up the file reference to "./proj.cproj" and then the solution loaded and built OK.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Cliff,

I didn't know about this feature of Studio, it is much quicker than my method...
However, my compiled version does not work with AVROSP, I will have to check with a terminal and send a few command, and/or use avrdude.

Have a nice day,
Kraal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> has "Create project from Makefile" on the Tools menu.

I tried this but got the same instant make failures with
"(saying -f was unexpexcted...)" as Kraal said.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kraal wrote:
Thanks Cliff,

I didn't know about this feature of Studio, it is much quicker than my method...
However, my compiled version does not work with AVROSP, I will have to check with a terminal and send a few command, and/or use avrdude.

Did you make sure to change the programming address to the boot section byte address? I've never tried my file in AS6, so I'm not sure how to do it. I'll try now, though...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I got it to work with basically no issues in about two minutes. I'm not sure if I just got lucky, but here's what I did:

1) Cloned the bootloader
2) Opened AS6 - Install "Create Project from Makefile" from the Extension Manager (it wasn't listed in the tools menu for me)
3) Imported the makefile using the "Create Project from Makefile" tool
4) Built the project (no errors or warnings for me)
5) Programmed using JTAGICE3
6) Communicated with the bootloader using AVRDUDE

A few pictures to possibly help along the way...

Import the project:

Select a part:

Build the project:

Program the bootloader using JTAGICE3:

Communicate with the bootloader using AVRDUDE:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I should also add that I built the project using Winavr's avr-gcc in the same directory after creating an AS6 project. It's clear that AS6 used the Atmel Toolchain to build because the build size was 2626 bytes when it's usually 2652 bytes with Winavr's avr-gcc on my system.

Last Edited: Sat. Nov 16, 2013 - 01:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry for all of the spam, but I thought these posts should remain discrete so people can find all of the relevant information.

I created a branch of the repo that has a working AS6 solution file. You'll need to change the MCU define in the makefile as well as the project settings, but, otherwise, this should work assuming your environment is setup correctly.

git clone git@github.com:bandtank/Xmega_Bootloader.git -b AS6_Ext_Makefile
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow, whats going on for me? This is definitely my weak area.

Even with the latest branch, I get -

------ Rebuild All started: Project: Xmega_Bootloader, Configuration: Debug AVR ------
Build started.
Project "Xmega_Bootloader.cproj" (ReBuild target(s)):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreRebuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Vs\Compiler.targets" from project "F:\Xmega_Bootloader\Xmega_Bootloader.cproj" (target "ReBuild" depends on it):
	Using "RunCompilerTask" task from assembly "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Extensions\Application\AvrGCC.dll".
	Task "RunCompilerTask"
		C:\Program Files (x86)\Atmel\Atmel Studio 6.1\shellUtils\make.exe -C "F:\Xmega_Bootloader" -f "makefile" clean all 
		make: Entering directory `F:/Xmega_Bootloader'
		rm -rf eeprom_driver.o Xmega_Bootloader.o serial.o sp_driver.o CCP_Write.o Xmega_Bootloader.elf Xmega_Bootloader.hex Xmega_Bootloader.eep Xmega_Bootloader.lss Xmega_Bootloader.map Xmega_Bootloader.d
		-f was unexpected at this time.
		make: *** [sizebefore] Error 255
		make: Leaving directory `F:/Xmega_Bootloader'
	Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreRebuild" in project "Xmega_Bootloader.cproj" -- FAILED.
Done building project "Xmega_Bootloader.cproj" -- FAILED.

Build FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It doesn't seem to like the sizebefore routine. Someone else had that problem as well because they were using make in cmd.exe instead of sh.exe, which is the default. Try altering line 132 in the makefile from this:

all: sizebefore $(TARGET) $(PROJECT).hex $(PROJECT).eep sizeafter  $(PROJECT).lss

to this

all: $(TARGET) $(PROJECT).hex $(PROJECT).eep $(PROJECT).lss
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was able to reproduce your error on a computer that doesn't have Winavr installed . I don't actually know if that's what causes sizebefore/after to work correctly, but the makefile definitely failed then passed with sizebefore/after in the makefile and then commented, respectively. Let me know if you get the same results please.

With sizebefore/after:

------ Build started: Project: Xmega_Bootloader, Configuration: Debug AVR ------
Build started.
Project "Xmega_Bootloader.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Vs\Compiler.targets" from project "C:\src\Xmega_Bootloader-AS6_Ext_Makefile\Xmega_Bootloader.cproj" (target "Build" depends on it):
	Task "RunCompilerTask"
		C:\Program Files (x86)\Atmel\Atmel Studio 6.1\shellUtils\make.exe -C "C:\src\Xmega_Bootloader-AS6_Ext_Makefile" -f "makefile" all 
		make: Entering directory `C:/src/Xmega_Bootloader-AS6_Ext_Makefile'
		-f was unexpected at this time.
		make: *** [sizebefore] Error 255
		make: Leaving directory `C:/src/Xmega_Bootloader-AS6_Ext_Makefile'
	Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "Xmega_Bootloader.cproj" -- FAILED.
Done building project "Xmega_Bootloader.cproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

Without sizebefore/after:

------ Build started: Project: Xmega_Bootloader, Configuration: Debug AVR ------
Build started.
Project "Xmega_Bootloader.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Vs\Compiler.targets" from project "C:\src\Xmega_Bootloader-AS6_Ext_Makefile\Xmega_Bootloader.cproj" (target "Build" depends on it):
	Task "RunCompilerTask"
		C:\Program Files (x86)\Atmel\Atmel Studio 6.1\shellUtils\make.exe -C "C:\src\Xmega_Bootloader-AS6_Ext_Makefile" -f "makefile" all 
		make: Entering directory `C:/src/Xmega_Bootloader-AS6_Ext_Makefile'
		avr-gcc  -mmcu=atxmega16d4 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=2000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -DBOOT_PAGE_SIZE=256 -DAPP_PAGE_SIZE=256 -DMCU=atxmega16d4 -DBAUD_RATE=115200 -DMY_UART=C,0 -DENTER_BOOTLOADER_PIN=B,2 -DLED_PIN=D,2 -DLED_ON=0 -DBOOTLOADER_PIN_EN=0 -DBOOTUP_DELAY= -MD -MP -MT eeprom_driver.o -c  eeprom_driver.c
		avr-gcc  -mmcu=atxmega16d4 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=2000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -DBOOT_PAGE_SIZE=256 -DAPP_PAGE_SIZE=256 -DMCU=atxmega16d4 -DBAUD_RATE=115200 -DMY_UART=C,0 -DENTER_BOOTLOADER_PIN=B,2 -DLED_PIN=D,2 -DLED_ON=0 -DBOOTLOADER_PIN_EN=0 -DBOOTUP_DELAY= -MD -MP -MT Xmega_Bootloader.o -c  Xmega_Bootloader.c
		avr-gcc  -mmcu=atxmega16d4 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=2000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -DBOOT_PAGE_SIZE=256 -DAPP_PAGE_SIZE=256 -DMCU=atxmega16d4 -DBAUD_RATE=115200 -DMY_UART=C,0 -DENTER_BOOTLOADER_PIN=B,2 -DLED_PIN=D,2 -DLED_ON=0 -DBOOTLOADER_PIN_EN=0 -DBOOTUP_DELAY= -MD -MP -MT serial.o -c  serial.c
		avr-gcc  -mmcu=atxmega16d4 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=2000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -DBOOT_PAGE_SIZE=256 -DAPP_PAGE_SIZE=256 -DMCU=atxmega16d4 -DBAUD_RATE=115200 -DMY_UART=C,0 -DENTER_BOOTLOADER_PIN=B,2 -DLED_PIN=D,2 -DLED_ON=0 -DBOOTLOADER_PIN_EN=0 -DBOOTUP_DELAY= -MD -MP -MT sp_driver.o -x assembler-with-cpp -Wa,-gdwarf2 -c  sp_driver.s
		avr-gcc  -mmcu=atxmega16d4 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=2000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -DBOOT_PAGE_SIZE=256 -DAPP_PAGE_SIZE=256 -DMCU=atxmega16d4 -DBAUD_RATE=115200 -DMY_UART=C,0 -DENTER_BOOTLOADER_PIN=B,2 -DLED_PIN=D,2 -DLED_ON=0 -DBOOTLOADER_PIN_EN=0 -DBOOTUP_DELAY= -MD -MP -MT CCP_Write.o -x assembler-with-cpp -Wa,-gdwarf2 -c  CCP_Write.s
		avr-gcc  -mmcu=atxmega16d4 -Wl,-Map=Xmega_Bootloader.map -Wl,-section-start=.text=0x4000 eeprom_driver.o Xmega_Bootloader.o serial.o sp_driver.o CCP_Write.o    -o Xmega_Bootloader.elf
		avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature  Xmega_Bootloader.elf Xmega_Bootloader.hex
		avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex Xmega_Bootloader.elf Xmega_Bootloader.eep || exit 0
		avr-objdump -h -S Xmega_Bootloader.elf > Xmega_Bootloader.lss
		make: Leaving directory `C:/src/Xmega_Bootloader-AS6_Ext_Makefile'
	Done executing task "RunCompilerTask".
	Task "RunOutputFileVerifyTask"
		
		Display Output File Size Skipped due to : Output File not found
	Done executing task "RunOutputFileVerifyTask".
Done building target "CoreBuild" in project "Xmega_Bootloader.cproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "Build" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Vs\Avr.common.targets" from project "C:\src\Xmega_Bootloader-AS6_Ext_Makefile\Xmega_Bootloader.cproj" (entry point):
Done building target "Build" in project "Xmega_Bootloader.cproj".
Done building project "Xmega_Bootloader.cproj".

Build succeeded.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bandtank wrote:
It doesn't seem to like the sizebefore routine. Someone else had that problem as well because they were using make in cmd.exe instead of sh.exe, which is the default. Try altering line 132 in the makefile from this:
all: sizebefore $(TARGET) $(PROJECT).hex $(PROJECT).eep sizeafter  $(PROJECT).lss

to this

all: $(TARGET) $(PROJECT).hex $(PROJECT).eep $(PROJECT).lss

This change allowed it to build. Thanks for that. I can't wait to try it out. I am using a 256A3B. This is new territory for me. I assume I can load only the bootloader into the XMEGA via AVR Studio 6 - then I am forced to load my app via the new bootloader. You cant load the bootloader and your revision 1 app both onto the chip from AVR Studio?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The error above is because the clean: rule uses the Unix command "rm -fr". If you have WinAVR installed (and in the PATH) it has gnuwin32 tools in ./utils/bin and that includes rm.exe which is a Windows build of the Unix command. So edit the Makefile and use "del" instead if you don't have gnuwin32 tools.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

deathcow wrote:
bandtank wrote:
It doesn't seem to like the sizebefore routine. Someone else had that problem as well because they were using make in cmd.exe instead of sh.exe, which is the default. Try altering line 132 in the makefile from this:
all: sizebefore $(TARGET) $(PROJECT).hex $(PROJECT).eep sizeafter  $(PROJECT).lss

to this

all: $(TARGET) $(PROJECT).hex $(PROJECT).eep $(PROJECT).lss

This change allowed it to build. Thanks for that. I can't wait to try it out. I am using a 256A3B. This is new territory for me. I assume I can load only the bootloader into the XMEGA via AVR Studio 6 - then I am forced to load my app via the new bootloader. You cant load the bootloader and your revision 1 app both onto the chip from AVR Studio?

I'm guessing you can, but I don't know how. You'd have to specify the placement of the bootloader code to be in the bootloader section and the application code in the application section.

I do that in the makefile for the bootloader on line 117:

LDFLAGS += -Wl,-section-start=.text=$(BOOT_SECTION_START_IN_BYTES)

That's why you have to modify the settings for each MCU so the code will end up in the right place. To load both at once, you can probably play some games with the linker flags on a per file/project basis.

In the end, though, I don't know if you gain much by spending the time to do that. Once the bootloader is on the MCU, it's very simple to program the application. Loading both at once would only save you time the first time you want to program the application code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
The error above is because the clean: rule uses the Unix command "rm -fr". If you have WinAVR installed (and in the PATH) it has gnuwin32 tools in ./utils/bin and that includes rm.exe which is a Windows build of the Unix command. So edit the Makefile and use "del" instead if you don't have gnuwin32 tools.

I'm not sure if my system is different somehow, but I don't have the Winavr/bin directory in my path and I still have access to rm. Maybe I need to edit the makefile to detect the OS so different tools can be used...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Three updates:

0) I removed sizebefore and sizeafter from the makefile. 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) I merged the branches because there's no reason the AS6 files can't live in the same branch as the non-AS6 version.

2) I added support for all of the Xmegas currently in the Atmel toolchain.

#  MCU = atxmega8e5
#  MCU = atxmega16a4
#  MCU = atxmega16a4u
#  MCU = atxmega16c4
#  MCU = atxmega16d4
#  MCU = atxmega16e5
#  MCU = atxmega32a4
#  MCU = atxmega32a4u
#  MCU = atxmega32c3
#  MCU = atxmega32c4
#  MCU = atxmega32d3
#  MCU = atxmega32d4
#  MCU = atxmega32e5
#  MCU = atxmega64a1
#  MCU = atxmega64a1u
#  MCU = atxmega64a3
#  MCU = atxmega64a3u
#  MCU = atxmega64a4u
#  MCU = atxmega64b1
#  MCU = atxmega64b3
#  MCU = atxmega64c3
#  MCU = atxmega64d3
#  MCU = atxmega64d4
#  MCU = atxmega128a1
#  MCU = atxmega128a1u
#  MCU = atxmega128a3
#  MCU = atxmega128a3u
#  MCU = atxmega128a4u
#  MCU = atxmega128b1
#  MCU = atxmega128b3
#  MCU = atxmega128c3
#  MCU = atxmega128d3
#  MCU = atxmega128d4
#  MCU = atxmega192a3
#  MCU = atxmega192a3u
#  MCU = atxmega192c3
#  MCU = atxmega192d3
#  MCU = atxmega256a3
#  MCU = atxmega256a3b
#  MCU = atxmega256a3bu
#  MCU = atxmega256a3u
#  MCU = atxmega256c3
#  MCU = atxmega256d3
#  MCU = atxmega384c3
#  MCU = atxmega384d3

The accompanying defines are listed in the file as well, but I won't paste those in here because it's a lot of text.

In case anyone gets some use out of this, here's the script I wrote to mine the information from the files:

#!/bin/bash

headers="/cygdrive/c/Program Files (x86)/Atmel/Atmel Toolchain/AVR8 GCC/Native/3.4.2.1002/avr8-gnu-toolchain/avr/include/avr"

for x in `ls -1 "$headers" | grep iox | sort -u`; do
	mcu=`echo $x | sed 's/iox\(.*\)\.h/atxmega\1/'`;
	bootstart=`grep BOOT_SECTION_START "$headers"/$x | grep -v END | sed 's/^.* (\(.*\))/\1/'`;
	bootpage=`grep BOOT_SECTION_PAGE_SIZE "$headers"/$x | grep -v END | sed 's/^.* (\(.*\))/\1/'`;
	apppage=`grep APP_SECTION_PAGE_SIZE "$headers"/$x | grep -v END | sed 's/^.* (\(.*\))/\1/'`;
	echo "ifeq (\$(MCU), $mcu)";
	echo "    BOOT_SECTION_START_IN_BYTES = $bootstart";
	echo "    BOOT_PAGE_SIZE = $bootpage";
	echo "    APP_PAGE_SIZE = $apppage";
	echo "endif";
done

I dumped it to a file and then sorted the lines because sort didn't quite do it right.

xmega_headers.sh > output
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do not have winavr installed. However, once I removed the sizebefore and sizeafter references as specified, everything built. I guess I need to install winavr to get this "avrdude" though.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As noted in other threads be warned that the avrdude in WinAVR is 4 years old. 6.0.1 was recently released and I think that included a Win32 build of the code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

omg zoinkers etc. I just had my first successful bootload on the XMEGA256A3B using your bootloader. Thank you so much!!

I downloaded AVRDUDE only (I do not have WinAVR) from:
http://savannah.nongnu.org/forum...

Then it did not run because of libusb, so I installed it with these instructions:
http://www.pinguino.cc/download/...

Then it ran.

However, it did not successfully program. I got this:

F:\avrdude>avrdude -v -p x256a3b -P com3 -b 9600 -c avr911 -U flash:w:/avrdude/GccApplication1.hex

avrdude: Version 6.0.1, compiled on Sep 18 2013 at 08:20:41
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "F:\avrdude\avrdude.conf"

         Using Port                    : com3
         Using Programmer              : avr911
         Overriding Baud Rate          : 9600
         AVR Part                      : ATxmega256A3B
         Chip Erase delay              : 0 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 0
         StabDelay                     : 0
         CmdexeDelay                   : 0
         SyncLoops                     : 0
         ByteDelay                     : 0
         PollIndex                     : 0
         PollValue                     : 0x00
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           prodsig        0     0     0    0 no         50   50      0     0     0 0x00 0x00
           fuse1          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse2          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse4          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse5          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0     0     0 0x00 0x00
           data           0     0     0    0 no          0    0      0     0     0 0x00 0x00
           eeprom         0     0     0    0 no       4096   32      0     0     0 0x00 0x00
           application    0     0     0    0 no     262144  512      0     0     0 0x00 0x00
           apptable       0     0     0    0 no       8192  512      0     0     0 0x00 0x00
           boot           0     0     0    0 no       8192  512      0     0     0 0x00 0x00
           flash          0     0     0    0 no     270336  512      0     0     0 0x00 0x00
           usersig        0     0     0    0 no        512  512      0     0     0 0x00 0x00
           fuse0          0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : butterfly
         Description     : Atmel AppNote AVR911 AVROSP

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=512 bytes.

Programmer supports the following devices:
    Device code: 0xfa

avrdude: devcode selected: 0xfffffffa
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9843
avrdude: NOTE: Programmer supports page erase for Xmega devices.
         Each page will be erased before programming it, but no chip erase is performed.
         To disable page erases, specify the -D option; for a chip-erase, use the -e option.
avrdude: reading input file "/avrdude/GccApplication1.hex"
avrdude: input file /avrdude/GccApplication1.hex auto detected as Intel Hex
avrdude: writing flash (15730 bytes):

Writing | ##                                                 | 3% 0.01s ***failed;
 ***failed;
 ***failed;
 ***failed;
(ETC ETC * a million)

So I added the -D option as it says above to disable page erase, and it programmed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't understand why you had that problem. I also don't understand how it worked if you disabled page erasing. I've been using AVRDUDE 5.10, so I don't know if something is different in 6.X.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Disabling page erase was a lucky guess as far as getting it to program. Why would page erase be required to make it work though, providing every byte of the app was programmed in sequence as normal?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You found a bug. Oops.

FYI - I caught this using the -vvvv option to AVRDUDE. It showed me that the programmer was responding, but the response wasn't correct. I introduced this bug a few commits earlier when I changed all of the responses to be preprocessor defines for readability. I accidentally switched the return value to be 'Y' instead of '\r'.

You can see the response was 0x59 ('Y'). The reason it worked when you specified -D is because the chip already erased even though AVRDUDE failed because of the bad response. The next time you programmed the chip, it was in an erased state so it could be programmed correctly.

The fix has been pushed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey bandtank, same results here from a fresh build of a latest git.

I did this:
git clone git://github.com/bandtank/Xmega_Bootloader.git

Do I need to do something different to get your fix?

thanks!
Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you please run with the -vvvv option to AVRDUDE and then copy the results into your next post? You don't need to copy the whole thing. The following should be fine:

Reading | avrdude.exe: Send: s [73]
avrdude.exe: Recv: B [42] . [94] . [1e]
################################################## | 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: Send: A [41] . [03] . [fc]
avrdude.exe: Recv: . [0d]
avrdude.exe: Send: g [67] . [00] . [01] E [45]
avrdude.exe: Recv: . [ff]
avrdude.exe: Send: A [41] . [03] . [fd]
avrdude.exe: Recv: . [0d]
avrdude.exe: Send: g [67] . [00] . [01] E [45]
avrdude.exe: Recv: . [ff]
avrdude.exe: Send: A [41] . [03] . [fe]
avrdude.exe: Recv: . [0d]
avrdude.exe: Send: g [67] . [00] . [01] E [45]
avrdude.exe: Recv: . [ff]
avrdude.exe: Send: A [41] . [03] . [ff]
avrdude.exe: Recv: . [0d]
avrdude.exe: Send: g [67] . [00] . [01] E [45]
avrdude.exe: Recv: . [ff]
avrdude.exe: erasing chip
avrdude.exe: Send: e [65]
avrdude.exe: Recv: . [0d]
avrdude.exe: reading input file "../xmegatest/xmegatest/Debug/xmegatest.hex"
avrdude.exe: input file ../xmegatest/xmegatest/Debug/xmegatest.hex auto detected as Intel Hex

Check to be sure line 93 in Xmega_Bootloader.c is:

sendchar(RESPONSE_OKAY);

Are you sure you flashed the new bootloader to your chip?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I am sure.

Line 93 is correct in my codeset. To make sure, I cleaned the build and tried to validate -- and saw that it couldn't find the hex file to validate. I then rebuilt the solution and validated, and it validated correctly against my device.

Relevant section:

Connecting to programmer: .avrdude: Send: . [1b]
avrdude: Send: S [53]
avrdude: Recv: X [58]

avrdude: Recv: m [6d] e [65] g [67] a [61] B [42] l [6c]
avrdude: Send: V [56]
avrdude: Recv: 1 [31] 1 [31]
avrdude: Send: v [76]
avrdude: Recv: ? [3f]
avrdude: Send: p [70]
avrdude: Recv: S [53]
Found programmer: Id = "XmegaBl"; type = S
    Software Version = 1.1; No Hardware Version given.
avrdude: Send: a [61]
avrdude: Recv: Y [59]
Programmer supports auto addr increment.
avrdude: Send: b [62]
avrdude: Recv: Y [59]
avrdude: Recv: . [02]
avrdude: Recv: . [00]
Programmer supports buffered memory access with buffersize=512 bytes.
avrdude: Send: t [74]

Programmer supports the following devices:
avrdude: Recv: . [fa]
    Device code: 0xfa
avrdude: Recv: . [00]

avrdude: Send: T [54] . [fa]
avrdude: Recv: . [0d]
avrdude: devcode selected: 0xfffffffa
avrdude: Send: P [50]
avrdude: Recv: . [0d]
avrdude: AVR device initialized and ready to accept instructions

Reading |                                                    | 0% 0.00savrdude: Send: s [73]
avrdude: Recv: C [43] . [98] . [1e]
Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9843
avrdude: NOTE: Programmer supports page erase for Xmega devices.
         Each page will be erased before programming it, but no chip erase is performed.
         To disable page erases, specify the -D option; for a chip-erase, use the -e option.
avrdude: reading input file "/avrdude/GccApplication1.hex"
avrdude: input file /avrdude/GccApplication1.hex auto detected as Intel Hex
avrdude: writing flash (15730 bytes):

Writing | ##                                                 | 3% 0.01s ***failed;
 ***failed;
 ***failed;
 ***failed;
 ***failed;
 ***failed;
 ***failed;
 ***failed;
 ***failed;
 ***failed;
 ***failed;
 ***failed;
 ***failed;
 ***failed;
 ***failed;
 ***failed;

command used:

F:\avrdude>avrdude -vvvv -p x256a3b -P com3 -b 9600 -c avr911 -U flash:w:/avrdude/GccApplication1.hex
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was able to reproduce the failure with AVRDUDE 6.0.1. The bootloader works fine with AVRDUDE 5.10.

If you specify -D it works and if you specify -e it works. -e forces a full chip erase, and that's the behavior I would expect AVRDUDE to have by default. I don't know what it's doing if you don't use either option.

I'm looking at the source code to see if I can figure out what's wrong.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow you are right, -e works. I ..swear.. I tried -e and it immediately failed. I must have had something else wrong. So, with -e, I have a fully functional solution. I had thought -e was erasing the bootloader too.

Thanks for all your help, this is a really great thing for me.

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

deathcow wrote:
Wow you are right, -e works. I ..swear.. I tried -e and it immediately failed. I must have had something else wrong. So, with -e, I have a fully functional solution. I had thought -e was erasing the bootloader too.

Thanks for all your help, this is a really great thing for me.

Mike

We've swapped emotions. Now I'm annoyed that I can't figure out what's wrong with it. =P

I'll probably post to the mailing list because the behavior obviously changed between 5.10 and 6.0.1. The real issue is the unknown. I don't know if there's more wrong than what we've seen so far. For example, the EEPROM might unintentionally get nuked if the erase routine isn't working correctly. I'd like to avoid issues of that nature.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to use your code with AVR Studio 6.1. I installed WinAVR and using AVRispmk2 as programmer. I changed the makefile to use with xmega128a3u and was able to compile it. However, when program the "xmega_bootloader.hex" file with AVR Studio I got this message: "Verifying Flash...Failed! address=0x20c00 expected=0xca actual=0xff"

(I also changed the fuse bit to Bootldr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

use your code with AVR Studio 6.1. I installed WinAVR 

Why on earth would you install WinAVR (avr-gcc 4.3.3) when Studio 6 (latest is 6.2 not 6.1 by the way) comes with avr-gcc 4.8.1 and if you wait a bit there will be Studio 7.0 and that comes with 4.9.2

 

No point using a 5..6 year old compiler when you can have a very recent one with tons of new features and bug fixes.

 

None of this has anything to do with your actual programming error but the fact you are using an out of date Studio (6.1) with presumably out of date USB drivers probably DOES have a lot to do with it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

WinAVR is already on my computer (lab computer). I recently install Studio and use Studio to program the chip. Thank you for your reply and sorry for my bad English.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys. how i can add dfu to this bootloader? Thank you