********************************** * * * AVR Universal Bootloader * * A V R U n i v e r sa l B o o t l o a d e r * * * ********************************** Last modified at 2012.Jue [Bug fixed] There two serious bugs found in V4.5, because new version has not publish, so I fix these bugs first here. In file bootldr.c, add below in line 475 and 499: bufptr -= BUFFERSIZE; It will cause download fail when CRC error. Thank Ben Wilson found and fix this bug.

Uart Bootloader Avr

After every power on reset, the bootloader wait for about 0.3 seconds for a keyword to enter the bootloader, otherwise the application was started.

In file bootldr.c, replace lines (*((void(*)(void))(BootStart)))(); to (*((void(*)(void))(BootStart/2)))(); • • • • • • • • • • • • • • Introduction This project is a general AVR bootloader, for different type of AVR device, all you need to do is modify macro definition, and you don not need to modify the main program. There are many bootloader program on internet, but most of them are only available for special types.

When we need to use other types device, we must do a lot of modification. And many of them are only realize the basic functions, and have bugs, hidden problem or may be used inconveniently, so we have developed this program. This project based on ATmega128 bootloader program which developed by Mr ChaoMa, and combined experience in bootloader of PIC18 microcontroller I have wrote before, and used the macro definition skill from AVRUSB, and optimize and test the code time after time, finally get this project. This AVR universal bootloader can support most types of AVR microcontrollers(Mega series), which have self-programable capability, boot section and UART. If the device have many serial ports, you can use any one of them.

Uart Bootloader Avr

This bootloader supports RS232, RS485 and RS422. It can also supports USI, SPI, I2C interface if you made some modify. This bootloader will occupy less than 1k words flash maximum, and it may occupy less than 256 words minimum. The space occupied by the bootloader is relative with device type, configuration parameters, funcations you select, and the optimize grade that the compiler use. Main feature • Support many types of AVR microcontrollers. • Support AVR device with multi-uart.

• Support RS232/RS485/RS422 mode. • Support customize communication baudrate and system clock frequcene. • Automatically calculate the baudrate error. • Write with AVR GCC, 100% C code. • High optimized code, occupy small space.

• Cut out the function conveniently, and can meet different requirements. • Support Watchdog. • User may use the LED to show the upgrade status.

• Support to use super terminal as download software on PC. • Support verification while write to FLASH. Download Baby Looney Tunes Episodes In Hindi here.

• Can define the size of user program section. Version v4.5 2008.Octo Add SafeMode v4.2 2008.Jun Add AES crypt routine (128/256 bits key) Fix a clerical error in WDG initialize Fix a bug in LED initialize, may cause RS485 not work Optimize code, reduce code size v4.0 2008.Apr Add PC1 decrypt algorithm routine (128/256 bits key) v3.5 2008.Mar Fix bug of Flash check above 64K error Auto create batch file 'avrub.bat' in AVRUBD's autocode, you don not need to set segment offset in AVR Studio, more easy to use. V3.2 2008.Mar Fix bug of URSEL bit, it may cause UART initiate fail in some device. V3.1 2007.Sep According to Douglas Hammond's suggest, modify ComInit macro. V3.0 2007.Jun Fix bug on ATmega162.

Modify uart port number configuration. Pass test with WinAVR 20070522. V2.0 2007.Apr.10 Add verification function while write Flash, improve the security of Bootloader.

V1.2 2007.Apr.02 Correct a hidden error in baudrate register calculate. (This error is very common. We can find it in many books and codes in network). V1.0 2007.Mar.22 This is the first version. It realized all necessary functions, and extended XModem protocol to fit different application. Develop environment The Develop environment of this project: WinAVR + AVR Studio WinAVR version: 20071221 AVR Studio version: 4.13.571 You may use other IDE or software to edit, debug AVR universal bootloader, such as KamAVR、AtmanAVR、PN.

Project files Whole project include flowing files: bootldr.c Main program bootldr.h The header file of main program bootcfg.h User configuration of main aprogram bootldr.aps AVR Studio's project file of bootloader aes.c aes crypt routine pc1crypt.c PC1 crypt routine test.c Demo program to test uart communication testcfg.h Configuration file of test.c test.aps Project file of test readme.htm This file Because many people have AVR Butterfly demo board, so all project file here use AVR Butterfly hardware as example. If you use other hardware environment, all you need is to modify the congiguation parameter in file bootcfg.h. Usage Now, you may use to configurate parameters automatically: • Creat a new project, and copy all above files to the folder where the new project is. • Run AVRUBD, choice 'AutoCode' function; • Selcect or set clock frequency, baudrate, comport etc. • Press button, save configuration file 'bootcfg.h'. AVRUBD will create batch file 'avrub.bat'.

• Run avrub.bat to compile your bootloader, make target HEX file. This is method I recommend. Or you may set parameters manual: • Creat a new project, and copy all above files to the folder where the new project is. • Add bootldr.c、bootldr.h、bootcfg.h to the project. • Modify the configuration parameter in bootcfg.h.

The meaning of these parameters are introduced in next section. • Set the flash section address of the project as the beginning address of bootloader.

Here the address is counted as word. Besides that, we need to set some parameters, such as the type of device( if you use AVR Studio or KamAVR, can set the parameters in IDE, otherwise you need to manual modify makefile file yourself). • Compile the project, then generate the target HEX file. Now you may program the target HEX file to the AVR mcu. • Set lock bits and fuse bits to configurate Boot section size and enable Boot Reset Vector, and select clock source. • Connect target board to PC via comport, test bootloader.

Main parameters The flowing parameters are very important. Please set these parameters carefully according to user system's hardware. Parameters note BUFFERSIZE The size of communication buffer. When use the hyper terminal, it must be equal to 128.

This parmeter must be multiple or submultiple of SPM_PAGESIZE which is the size of mcu's flash section page. F_CPU Frequency of system clock (in Hz).

BAUDRATE Baudrate of uart communication(bps). LEVELMODE Bootloader triger mode(0=uart 1= pin level) SafeMode Enable SafeMode, it will set a flag in EEPROM, and it will not jump to user application till update successfully timeclk Basic time interval(ms) TimeOutCnt Bootloader maximal timeout count(' periodically from AVR mcu. If you send a character to mcu via Hyper terminal, send data will become to what you send. Q: Why bootloader can't jump to user's application after upgrade?

A: If this happen, there are most likely to below reasons(90%): • Compiler's bug, made jump instruction incorrect. You may see disassemble code to analyse jump codes, or try to update you compiler to new version. • Not set fuse bits and lock bits correctly. • Parameters wrong, such as bootloader segment offset. Q: How to cutdown unused function? A: In file bootcfg.h, there are many macro definition, set macro to 0 will disable corresponding fuction.

For example, not use LED in bootloader, set macro LEDEn to 0. Q: How to reduce bootloader target size, leave more flash space to user? A: Cutdown unnecessary functions, such as verbose hint, LED indication, use add up instead of CRC as check sum. And you can also set optimization of compiler, these will reduce target file size. Due to indeterminacy of optimization, code size optimize will not get the smallest size in some condition.

You may also remove IVT(interrupt vect table) to save more space. In AVR-GCC, compiler will create IVT in application head.

Avrub not use any interrupt, so IVT is not necessary, this will save about 40-160 bytes. Q: If AVRUB support other AVR C compiler? A: AVR universal bootloader use AVR GCC as compiler, other C compiler have not been test. IAR C compiler is very close to AVR GCC, I think there are only few place need to be modify(AVRUSB is compatible with AVR GCC and IAR C compiler). Other C compiler may be use too, because I write code according to ANSI standard. The code may need to modify is head file, some register name may be different.

Q: Where can user get last version of AVRUB? A: In you will get last version or AVRUB. If you have any suggestion, or link above can't be access, please feel free to send email to me. Filme Outlander Guerreiro Vs Predador Dublado Online there. Special thanks There are many people given me help in develop this project. Liu haitao give many help in coding and debuging tda1552 Tested ATmega32 Xu yankang Found bug in HEX format convert Ni enwei give some useful suggestion Cheng xiang help to translate this document to English Luiz Francisco Catalan Found Flash check bug, and help to test PC1 and AES decrypt algorithm.

And many people who have not left names. License OpenSource, base on GPL license.

Series Smiley’s Workshop - AVR C Programming Series C programming and microcontrollers are two big topics, practically continental in size, and like continents, are easy to get lost in. Consider these workshops a combination roadmap, guidebook, and emergency first aid kit for your journey into this fascinating, but sometimes dangerous world. All articles in this series: • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •.