| QUOTE |
| I have made a new bootloader for ATMega32 which I am using for teaching a course in microprocessor technology. It is based on the code published by Peter Dannegger in 2003 with various modifications. It sends the hex file and possibly eep file from a Windows PC to an AVR prototype board through an RS232 cable or USB cable. I am posting it here including source code in case somebody wants to use it. I am using the Olimex prototype board (http://www.olimex.com/dev/avr-p40-usb-8535.html) but you may use any other prototype board. Modifications may be needed if the clock frequency is not 10 MHz. |
| CODE |
;************************************************************************* ;* * ;* ATMEGA Bootloader * ;* * ;************************************************************************* ; This is a bootloader for Atmel Atmega32 microcontroller kit. ; Can be used with AVR-P40-USB-8535 prototype board from www.olimex.com. ; Originally programmed by Peter Dannegger, Nov. 2003. ; Modified by Agner Fog, Sep. 2005. ; Build instructions: ; ===================== ; Build with AVR Studio 4. ; Upload to AVR by JTAG. ; Set the following fuses: ; On-Chip Debug Enabled ; JTAG Interface Enabled ; Serial Program downloading enabled ; Boot Flash section size = 512 words ; Boot Reset vector Enabled ; Brown-out detection level at VCC=4.0V or 2.7V ; Ext. Crystal/Resonator High Freq.; Start-up time: 16K + 64 ms ; Use instructions: ; ===================== ; Use the accompanying program AVRupload.exe to upload from PC using ; RS232 serial interface or USB cable with USB to serial converter on ; the prototype board. ; Baud rate = 19200 Baud, 8 data bits, no parity, 1 stop bit. .nolist .include"m32defr.inc" .include"bootload.inc" .list ; .equ signature = 0x1E9502;Mega32 ;.equ signature = 0x1E9501;Mega323 ;.equ signature = 0x1E9403;Mega16 ;.equ signature = 0x1E9404;Mega162 ;.equ signature = 0x1E9307;Mega8 ; .equ base = SECONDBOOTSTART .org base rjmp init .org base + OVF1addr rjmp OVF1int .org base + URXCaddr rjmp URXCint .org base + NOINTaddr;end of interrupt vector table init: .include"init.inc" ; ;------------------------------------------------------------------------ ; sbi LED_DDR, LED0;test LED ; rcall set_baud;set baud rate rcall uart_init;set baud rate 19200 ldi a0, 1 out DDRB, a0 cbi PORTB, 0 ; turn on LED ; Timeout. Not implemented ; ldi timeout, $ff main: ; command loop ; dec timeout ; breq timeout_exit sbis PINB,4 ; check pushbutton rjmp button_pressed ; go to user program if button pressed cbr flags, 1<<f_error;clear error rcall rx_command ;Command received ? brcc main rcall exec_command;Command execute ldi a0, key_failed;execution failed sbrs flags, f_error;test ldi a0, key_done;execution successful sbrc flags, f_enable rcall putchar ;send command execution status rjmp main button_pressed: ; Wait till button is up again to avoid short circuit in case.. ; user progam has PORTB.4 as output sbis PINB,4 rjmp button_pressed ; debounce: ldi a1, $ff debounce_loop: sbis PINB,4 rjmp button_pressed ldi a0, $ff inner_delay_loop: dec a0 breq inner_delay_loop dec a1 breq debounce_loop ; Debounce finished. Jump to user program jmp userprog ;------------------------------------------------------------------------- ;.include"uart.inc" .include"uart19200.inc" .include"commexec.inc" .include"asc2hex.inc" .include"commands.inc" .include"read.inc" .include"program.inc" .include"userprog.inc" .include"abaud.inc" ;------------------------------------------------------------------------- |