APPLICATION NOTE Atmel AT03160: Migrating Bootloader from ATxmega128A1 to other Atmel XMEGA Devices Features Atmel AVR XMEGA bootloader Procedure application C-code sample application for Self Programming Read and Write Both Flash and EEPROM Memories Read and Write Lock Bits Read Fuse Bits Description Atmel AVR XMEGA As many electronic designs evolve rapidly there is a growing need to be able to update products which have already been shipped or sold. The bootloader firmware embedded in microcontrollers can facilitate the application flash update without the need of a programmer. This application note describes how to migrate bootloader from Atmel ATxmega128A1 to other AVR XMEGA devices step by step. Before reading this application note, AVR1605 XMEGA Boot Loader Quick Start Guide should be read since this application note is an extended read for AVR1605. The project of AVR1605 is based on ATxmega128A1 and the entire project package could be downloaded from Atmel website. For more information about self programming please refer to the application note AVR109: Self Programming.
Table of Contents 1. Procedure... 3 1.1 Step 1 - Start IAR... 3 1.2 Step 2 - Open the project... 3 1.3 Step 3 - Change processor and xcl file... 5 1.4 Step 4 - Change flash page size... 8 1.5 Step 5 - Change define information... 9 1.6 Step 6 - Compile the project... 9 1.7 Step 7 - Debug the bootloader... 11 1.8 Step 8 - Change the bat file... 13 2. Recommended reading... 14 3. Revision History... 15 2
1. Procedure Here are the main procedures to migrate bootloader from ATxmega128A1 to other XMEGA devices. Before doing the migration following the procedures, the original project which is based on ATxmega128A1 should be downloaded through the link: http://www.atmel.com/images/avr1605.zip IAR Embedded Workbench version 6.11 or later should be installed first before starting the migration procedure. Optionally Atmel Studio version 6.0 or later is installed if the bootloader is programmed in Atmel Studio. 1.1 Step 1 - Start IAR Click Windows start -> All Programs -> IAR Systems -> IAR Embedded Workbench for Atmel AVR -> IAR Embedded Workbench. Figure 1-1. Start IAR 1.2 Step 2 - Open the project Click File -> Open -> Workspace. Figure 1-2. Open workspace 3
Browse to the project folder, select the project file bootloader.eww, and then click Open button. Figure 1-3. Open bootloader If the used IAR software version is newer, the conversion prompt will occur. Click Yes to continue. Figure 1-4. Conversion prompt 4
1.3 Step 3 - Change processor and xcl file Select bootloader - Debug in the Workspace and then click Project -> Options. Figure 1-5. Open options Select General Options in the Category and then in the Target tab, change ATxmega128A1 to the target device. Figure 1-6. Change processor 5
Find the linker configuration file link_bootloader_atxmega128a1.xcl in \code folder. And copy from it to get the target linker configuration file and rename it with the target device name. In this target device.xcl file, change Segments in program address space (internal Flash memory), Data (SRAM, external ROM or external NV RAM) memory and Internal EEPROM part to the suitable values according to the datasheet of the target device. You can also refer to the linker file for corresponding device from IAR for these details. IAR s linker files are available in \IAR Systems\Embedded Workbench 6.0\avr\src\template folder. Figure 1-7. Change xcl file 6
Select Linker in the Category and then in the Config tab, change link_bootloader_atxmega128a1.xcl to the modified target file. Figure 1-8. Select xcl file 7
1.4 Step 4 - Change flash page size Select sp_driver.h file in Workspace and change the FLASH_PAGE_SIZE, 512, to the correct value corresponding to the target device. The flash page size can be acquired in the datasheet. Figure 1-9. Change flash page size in sp_driver.h Select sp_driver.s90 file in Workspace and change the FLASH_PAGE_SIZE, 512, to the correct value depending on the target device. Figure 1-10. Change flash page size in sp_driver.s90 8
1.5 Step 5 - Change define information Select defines.h file in the Workspace. Change ATxmega128A1 to the target device and then change all the predefined items to match the target device. All the information filled could be found in the datasheet. Figure 1-11. Change pre-defined information 1.6 Step 6 - Compile the project If everything is processed correctly, the project can be compiled successfully. Click Project -> Rebuild All and the new debug file, bootldr.dbg, will be created in \Debug\Exe folder. This debug file will be used to debug the bootloader in Atmel Studio. Figure 1-12. Rebuild the project 9
If the bootloader is debugged with IAR Embedded Workbench, the output format should be changed as shown in Figure 1-13. After the setting, click Project -> Rebuild All and the bootloader.d90 will be produced. This debug file will be used to debug the bootloader with IAR Embedded Workbench. Figure 1-13. Output format 10
1.7 Step 7 - Debug the bootloader The bootloader can be debugged on IAR Embedded Workbench. Select the debugger you are using in the Setup tab as shown in Figure 1-14. Figure 1-14. Select tool 11
Click Project -> Download and Debug, and this will debug the bootloader to the target device shown in Figure 1-15. After downloading, you could start debugging the bootloader. Figure 1-15. Download and debug Alternatively, bootldr.dbg file can make the bootloader to be debugged in Atmel Studio 6. After opening Atmel Studio 6, click File -> Open -> Open Object File For Debugging, and then browse to \Debug\Exe folder to open bootldr.dbg file. Please refer to Atmel Studio help file for more information on how to debug with the object file. Figure 1-16. Open object file 12
1.8 Step 8 - Change the bat file Browse to \AVROSP_Test folder and open the bat file with Notepad. Change ATxmega128A1 to the target device. The.hex file should be changed to the real image file name. The image file (.hex) should be placed in the same folder with the bat file. The other bat files should be changed in the same way if they are used. Figure 1-17. Change bat file 13
2. Recommended reading It is recommended to read the following application notes to get an overall idea about self programming and bootloader: AVR109: Self Programming This application note explains how devices with the SPM instruction can be configured for self programming. Though it is given for Atmel tinyavr and Atmel megaavr devices, it gives general information about self programming. AVR1316: XMEGA Self-programming This application note describes the basic functionality of Atmel AVR XMEGA self programming. AVR1622: TWI Boot Loader for XMEGA This application note describes how to use boot loader of the XMEGA family of devices to update the application section and how XMEGA can be configured for self programming. AVR1605: XMEGA Boot Loader Quick Start Guide This application note describes how to use a boot loader application with one of the XMEGA family devices (i.e. ATxmega128A1) and how an AVR with the Store Program Memory (SPM) instruction can be configured for Self-programming. 14
3. Revision History Doc. Rev. Date Comments 42153A 07/2013 Initial revision 15
Atmel Corporation 1600 Technology Drive San Jose, CA 95110 USA Tel: (+1)(408) 441-0311 Fax: (+1)(408) 487-2600 www.atmel.com Atmel Asia Limited Unit 01-5 & 16, 19F BEA Tower, Millennium City 5 418 Kwun Tong Road Kwun Tong, Kowloon HONG KONG Tel: (+852) 2245-6100 Fax: (+852) 2722-1369 Atmel Munich GmbH Business Campus Parkring 4 D-85748 Garching b. Munich GERMANY Tel: (+49) 89-31970-0 Fax: (+49) 89-3194621 Atmel Japan G.K. 16F Shin-Osaki Kangyo Building 1-6-4 Osaki Shinagawa-ku, Tokyo 141-0032 JAPAN Tel: (+81)(3) 6417-0300 Fax: (+81)(3) 6417-0370 2014 Atmel Corporation. All rights reserved. / Rev.: Atmel, Atmel logo and combinations thereof, Enabling Unlimited Possibilities, AVR, XMEGA and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.