**********************************
* *
* AVR Universal Bootloader *
* AVR Universal Bootloader *
* *
**********************************
Last modified at 2008.May
Introduction
Main feature
Version
Develop environment
Project files
Usage
Main parameters
Tested device
Frequently asked questions
Special thanks
License
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. 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 300 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.
v4.1 | 2008.May | Fix MCUSR macro bug |
v4.0 | 2008.May | Add PC1 decrypt algorithm(128/256 bits key) Fix a bug on download a big file |
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. |
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. |
The Develop environment of this project: WinAVR + AVR Studio
WinAVR version: 20071221
AVR Studio version£º 4.14.589
You may use other IDE or software to edit, debug AVR universal bootloader, such as KamAVR¡¢AtmanAVR¡¢PN.
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
test.c Demo program to test uart communication
testcfg.h Configuration file of test.c
test.aps Project file of test
readme.txt this file
readme.htm HTML edition of readme.txt
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.
Now, you may use AVRUBD to configurate parameters automatically:
This is method I recommend. Or you may set parameters manual:
Now you may program the target HEX file to the AVR mcu.
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) |
timeclk |
Basic time interval(ms) |
TimeOutCnt |
Bootloader maximal timeout count(<=255) |
TimeOutCntC |
The maximal timeout count when wait for receiving file(<=255) |
CONNECTCNT |
The length of password that will be used to connect to PC |
ConnectKey |
The password to connect to PC. It can be hex numeral or string |
COMPORTNo |
Uart port number. One uart mcu is set to 0 or blank, to multi uart mcurt0 is 0, uart1 is 1, and so on. |
WDG_En |
Enable watchdog |
RS485 |
Enable RS485/RS422 mode |
RS485PORT |
Control port of RS485/RS422 transmission(A/B/C/D...) |
RS485TXEn |
Control pin of RS485/RS422 transmission(PC0/PC1/PC2...) |
LED_En |
Enable use LED to indication status. |
LEDPORT |
Port which LED used |
LEDPORTNo |
Pin which LED used |
InitDelay |
Additional delay after uart initializtion(some early device need this, such as ATmega8) |
VERBOSE |
Hint mode. Show more prompt information, interactive input will be convenient while using hyper terminal. |
CRCMODE |
Communication check sum method(0=XMODEM CRC 1=simple accumulated summation) |
The start adrress of Boot section(counted by byte) |
|
ChipCheck |
Enable verify data after write data to flash. This parameter will only valid when Bootstart used |
The AVR universal bootloader has benn test in several AVR device, below devcie are tested by myself:
ATmega8
ATmega88
ATmeag64
ATmega128
ATmega162
ATmega168
ATmega169(Bufferfly)
below are tested by other people:
ATmega16
ATmega164p
ATmega32
ATmega1280
ATmega1281
If you have success use this bootloader in device not list above, please send EMAIL to me.
1. |
Q: |
How to protect boot section? |
A: |
In order to prevent boot section avoid overwrite, user must set lock bits of mcu. Commonly we set Bootloader protection mode to 2 or 3 by set BLB11 and BLB12, disable boot section write operation. |
|
2. |
Q: |
Why use watchdog in bootloader? |
A: |
In order to increase system stability, I suggest use watchdog, to avoid bootloader enter dead loop. |
|
3. |
Q: |
Is hyper terminal may use to download target HEX file? |
A: |
Yes, you can use hyper terminal as PC download software. In order to use hyper terminal as download software, macro BUFFERSIZE must equal 128, and KEY will not set to long(1-2 characters), macro TimeOutCnt/TimeOutCntC/timeclk must define large enough to let you have enough time to input. And macro CRCMODE must equal 0, and you need convert target HEX file to BIN format before download. In fact, AVRUBD(AVR universal bootloader download) is a better software than terminal, AVRUBD support HEX/BIN format, after you load target file, all you need is click download button. |
|
4. |
Q: |
How to confirm uart work fine(comport line link correct)? |
A: |
Demo program test.c may use to test uart. If link correct, compute will receive a '>' periodically from AVR mcu. If you send a character to mcu via Hyper terminal, send data will become to what you send. |
|
5. |
Q: |
Why bootloader can't jump to user's application after upgrade? |
A: |
If this happen, there are most likely to below reasons(90%):
|
|
6. | 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. |
|
7. |
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. |
|
8. |
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. |
|
9. |
Q: |
Where can user get last version of AVRUB? |
A: |
In http://avrubd.googlepages.com 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 shaoziyang@gmail.com. |
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 give many help in test PC1 decrypt algorithm. |
seu gab | Found avrubd download buffer length bug and MCUSR macro bug |
And many people who have not left names.
Base on GPL license.
2007.6, by Mr. Shao ziyang, WuHan
e Y8b Y8b YV3.08P888 88e |