Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1031 | - | 1 | |
2 | ====================================================== |
||
3 | |||
4 | ATMEL AVR UART Bootloader for AVR-GCC/avr-libc |
||
5 | |||
6 | by Martin Thomas, Kaiserslautern, Germany |
||
7 | mthomas@rhrk.uni-kl.de |
||
8 | eversmith@heizung-thomas.de |
||
9 | http://www.siwawi.arubi.uni-kl.de/avr_projects |
||
10 | |||
11 | ** Addtional code and improvements contributed ** |
||
12 | ** by Uwe Bonnes, Bjoern Riemer and Olaf Rempel. ** |
||
13 | |||
14 | Eearly versions of this bootloader-code have been |
||
15 | based on the AVR Butterfly bootloader-source REV02 |
||
16 | which has been available from atmel.com. |
||
17 | |||
18 | ====================================================== |
||
19 | |||
20 | |||
21 | Programming-Software (on the "PC-Side"): |
||
22 | |||
23 | * AVRProg (included in AVRStudio) available at www.atmel.com. |
||
24 | MS-Windows only. AVRProg can be used as stand-alone application. |
||
25 | (avrprog.exe) |
||
26 | |||
27 | * avrdude available at http://savannah.nongnu.org/projects/avrdude/ |
||
28 | "Multiplattform" |
||
29 | |||
30 | * Installation instructions at the end of this file. |
||
31 | |||
32 | |||
33 | 3. Dec. 2008 - Version 0.85 |
||
34 | |||
35 | * disable U2X before jump to app as suggested be Alexander Döller |
||
36 | * moved UBRR-macros to main.c and changed them. Inspired by code from avr-libc setbaud. |
||
37 | (macros which are commented out (//) are from Pavel Fertser) |
||
38 | |||
39 | 6. Nov. 2008 - Version 0.84 |
||
40 | |||
41 | * Added definitions for ATmega64 provided by Pavel Fertser - Thanks. |
||
42 | |||
43 | 12. Apr. 2008 - Version 0.83 |
||
44 | |||
45 | * Added definitions for ATmega644P and ATmega324P |
||
46 | * Tested with ATmega324P, gcc 4.2.2, avr-libc 1.4.6 |
||
47 | * Added testapp to verify "exit bootloader" with |
||
48 | watchdog (n.b.: watchdog-disable called early in testapp) |
||
49 | |||
50 | 27. Jan. 2007 - Version 0.82 |
||
51 | |||
52 | * Added definitions for ATmega644. |
||
53 | * Using avr-lib's eeprom-functions (old "direct-access"-code |
||
54 | has not been compatible with ATmega644). |
||
55 | * Watchdog-disable at startup (configurable): avoids problems with |
||
56 | repeated login to bootloader. Not needed if the bootloader is |
||
57 | never re-entered again between an "exit programming" and |
||
58 | a system-reset/power-toogle. |
||
59 | * Additional watchdog disable-function for ATmega644. |
||
60 | * Made watchdog-enable time at exit-programming a configuration-value |
||
61 | (define). |
||
62 | * Bootloader read-protection: if enabled the bootloader fakes |
||
63 | an empty boot-section (configurable by define) |
||
64 | Since more of the avr-libc functions's are used this version |
||
65 | should be more portable for other AVRs but the size of the |
||
66 | binary increases a little bit. |
||
67 | Make sure to disable the watchdog early in the user-application |
||
68 | esp. when using a "modern" AVR (i.e. ATmega48/88/168/644/324P/644P). |
||
69 | |||
70 | 3. Dec. 2006 - Version 0.81 |
||
71 | |||
72 | * Added definitions for ATmega162. |
||
73 | * Fixed init for double-speed (bitmask). Thanks to Bernhard Roth |
||
74 | |||
75 | 28. May 2006 - Version 0.8beta3 |
||
76 | |||
77 | * Supports discarding of interrupt-vectors which saves some space |
||
78 | if no interrupts are needed in the bootloader. Added option |
||
79 | in makefile to enable this feature, modified LDFLAGS, |
||
80 | additional code in main.c for a pseudo default_interrupt ISR. |
||
81 | The modified linker-scripts have been contributed by |
||
82 | Olaf Rempel (basicly just the .vector-section is not linked). |
||
83 | * Reverted the order of signatur-byte-numbers in part- |
||
84 | configurations to the usual order in the datasheet, |
||
85 | also reverted in main.c for sending the signature. |
||
86 | * Definitions for lock/fuse-readout. |
||
87 | * Updated installation-instruction at the end of this file. |
||
88 | * Added DEVTYPE_ISP/DEVTYPE_BOOT to part-configurations, |
||
89 | added configuration-option for this in main.c. |
||
90 | * A remark about the DEVTYPE: Usualy there are two |
||
91 | Part-Codes/Device-Codes. One is for ISP: AVRProg shows |
||
92 | the type of the AVR. The other code is for bootloading: |
||
93 | AVRprog shows the type plus "BOOT". When a boot-device-code |
||
94 | gets detected by AVRprog it "knows" how do handle the |
||
95 | limited functionality of bootloaders. (When receiving the |
||
96 | ISP-code AVRProg expects an AVR910-type programmer.) |
||
97 | The offset between the codes is usualy 0x01 where the |
||
98 | ISP-code is the smaller value, i.e. ATmega32 ISP-code |
||
99 | is 0x72->"ATmega32" and boot-code is 0x73->"ATmega32 BOOT". |
||
100 | When using avrdude the bootloader's device-code must match |
||
101 | the device-code in the avrdude.conf. Check the avrdude- |
||
102 | code to see if both codes (AVR910 and AVR109) are supported. |
||
103 | -- I have got some e-mails from users which have been |
||
104 | confused by this. Hopefully this explanation is good enough. |
||
105 | * This bootloader lets the watchdog do a reset when the |
||
106 | user selects "Exit programmer" (i.e. in AVRProg) after an |
||
107 | update. Make sure to disable or reset the watchdog early in |
||
108 | your application. |
||
109 | |||
110 | 27. May 2006 - Version 0.8beta2 |
||
111 | |||
112 | * More very well done improvements contributed by Olaf Rempel. |
||
113 | * Olaf Rempel also modified the STARTUP_WAIT method. |
||
114 | |||
115 | 21. May 2006 - Version 0.8beta |
||
116 | |||
117 | * Version contributed by Olaf Rempel. He has done a lot of modifications. |
||
118 | -> "cleaner code", smaller binaries. |
||
119 | |||
120 | 09. Feb. 2006 - Version 0.75 |
||
121 | |||
122 | * additional STARTUP_WAIT support contributed by Bjoern Riemer |
||
123 | |||
124 | 18. Aug. 2005 - Version 0.74 |
||
125 | |||
126 | * AT90CAN128 support contributed by Uwe Bonnes |
||
127 | * Makefile modifications contributed by Uwe Bonnes |
||
128 | |||
129 | 23. Feb. 2005 - Version 0.7 |
||
130 | |||
131 | * (Version 0.6 has never been available on the web-page) |
||
132 | * ATmega128 support |
||
133 | * code cleanup |
||
134 | * This version has been tested with ATmega8, ATmega32 and |
||
135 | ATmega128 |
||
136 | |||
137 | 7. Apr. 2004 - Version 0.5 |
||
138 | |||
139 | * added different startup-methods |
||
140 | * compatible with ATmega8 now |
||
141 | * included makefile adapted to ATmega8 now |
||
142 | (ATmega16 options still available) |
||
143 | * fixed jump to application which did not work |
||
144 | reliably before |
||
145 | * tested with ATmega8 |
||
146 | * minimal options and startup-code result in |
||
147 | bootloader-size < 512 words |
||
148 | |||
149 | 6. Apr. 2004 - Version 0.4 |
||
150 | |||
151 | * Buffered read of chars from UART during programming |
||
152 | since eeprom-write is too slow for unbuffered |
||
153 | operation. So EEPROM-upload does work now. |
||
154 | * Added BOOTICE-mode to flash JTAGICE-compatible |
||
155 | hardware (ATmega16@7,3Mhz) (if you know about BOOTICE, |
||
156 | you may unterstand why this has been added, if not |
||
157 | just keep the option disabled) |
||
158 | * small changes in (my)boot.h (lock-bit-mask) found |
||
159 | out during the development of the STK-500-compatible |
||
160 | bootloader. But setting lock-bits still does not |
||
161 | work with this bootloader. |
||
162 | * read of the low-fuse byte works (high byte still TODO) |
||
163 | * read of the lock-byte works (write still TODO) |
||
164 | |||
165 | 27. Mar 2004 - Version 0.3 |
||
166 | |||
167 | Felt that as much functions from avr-libc's boot.h |
||
168 | as possible should be used without modifications. |
||
169 | Latest CVS-version of boot.h is included. |
||
170 | Only the read-routine is still "self-made" based |
||
171 | on ATMELs assembler-code. |
||
172 | EEPROM write on Mega16 does not work (and did not |
||
173 | work with V0.2 too). May be caused by my old Mega16 |
||
174 | chip. Needs testing. Flash read/write and EEPROM |
||
175 | read works. Still only tested with ATmega16. |
||
176 | This version may not work with the ATmega169 any |
||
177 | more. |
||
178 | |||
179 | 24. Mar 2004 - Version 0.2 |
||
180 | |||
181 | During the development of a data-logger application |
||
182 | with the AVR-Butterfly there was a need to make |
||
183 | some changes in the bootloader. The same problem |
||
184 | again: no IAR compiler. The same way to solve the |
||
185 | problem: a port of the code to avr-gcc/avr-libc. |
||
186 | So this code is based on the ATMEL Butterfly |
||
187 | bootloader source code Rev 0.2 for IAR. |
||
188 | |||
189 | The bootloader-port for the Butterfly which mimics |
||
190 | the complete functionality of the original |
||
191 | BF-bootloader is availabe at: |
||
192 | www.siwawi.arubi.uni-kl.de/avr_projects |
||
193 | |||
194 | Atmel used a separate "lib" written in "pure" |
||
195 | assembly to access the low-level functions |
||
196 | for flash read/write. Well, so far I |
||
197 | don't know how to use "mixed language sources" |
||
198 | with the avr-gcc toolchain, so the low-level |
||
199 | routines have been implemented as inline assembler. |
||
200 | The avr-libc boot.h module written by Eric |
||
201 | Weddington served as a template Three of the four |
||
202 | low-level routines found in lowlevel.c come from |
||
203 | boot.h with minimal changes. The read routine has |
||
204 | been developed based on the ATMEL assembler code. |
||
205 | |||
206 | Ignore the fuse and lock-bit readout. Read and Set is |
||
207 | not enabled (TODO). |
||
208 | |||
209 | |||
210 | --------------- Installation ----------------- |
||
211 | |||
212 | - Change the MCU type in the makefile. |
||
213 | |||
214 | - Change the boot(loader)-size in Makefile. The needed |
||
215 | space depends on the features selected in main.c |
||
216 | |||
217 | - Set baudrate in main.c, a doublespeed configuration-option |
||
218 | is available too. |
||
219 | |||
220 | - Change the F_CPU in main.c to the clock-frequency |
||
221 | of your board. See the datasheet for frequencies |
||
222 | with minimum error at the selected baudrate. |
||
223 | |||
224 | - Select the start-condition in main.c. |
||
225 | |||
226 | - Please use at least avr-gcc 3.3.1/avr-libc 1.0 |
||
227 | or WINAVR Sept. 2003 or later to compile and link |
||
228 | this bootloader. |
||
229 | |||
230 | - Upload the hex-File to the AVR (STK500, STK200, SP12 |
||
231 | evertool, AVR910 etc.) |
||
232 | |||
233 | - Program the "Boot Flash section size" (BOOTSZ fuses) |
||
234 | according to the boot-size selected in the makefile |
||
235 | i.e. BOOTSZ=00 for boot-size 1024 words (2048 bytes) |
||
236 | on ATmega16 |
||
237 | |||
238 | - enable the BOOT Reset Vector fuse (BOOTRST=0) |
||
239 | |||
240 | - Set the lock bits to protect the bootloader from |
||
241 | SPM-writes (Boot Loader Protection Mode 2 in STK500- |
||
242 | plugin) so that it can not overwrite itself. |
||
243 | |||
244 | - Connect the AVR UART Pins via level-shifter/inverter |
||
245 | (i.e. MAX232) to your PCs COM-Port. |
||
246 | |||
247 | - Reset the AVR while fullfilling the bootloader start- |
||
248 | condition. (Default: selected pin connected to GND). |
||
249 | The condition must be "true" until you see the |
||
250 | AVRPROG dialog or avrdude connects. |
||
251 | |||
252 | - Start AVRPROG (AVRStudio/Tools or stand-alone avrprog.exe) |
||
253 | AVRDUDE is supported too, check it's manual |
||
254 | for command-line options. Read the text above for |
||
255 | information about Device-Types and AVRDUDE |
||
256 | |||
257 | - AVRPROG or AVRDUDE should detect the bootloader. |
||
258 | |||
259 | - see AVRStudio's online-help for more information how |
||
260 | to use AVRPROG |
||
261 | |||
262 | - make sure to EXIT from AVRPROG (button) to start |
||
263 | your main-application or toogle power/reset. |
||
264 | |||
265 | |||
266 | Feedback welcome, Good luck. |
||
267 | Martin |