Added libraries from Arduino 1.0.3 for sanguino build

This commit is contained in:
Yuri Valentini
2013-01-07 17:26:50 +01:00
parent dad7691df9
commit 7d20ec706e
63 changed files with 12042 additions and 7 deletions

View File

@ -0,0 +1,717 @@
/**********************************************************/
/* Serial Bootloader for Atmel megaAVR Controllers */
/* */
/* tested with ATmega644 and ATmega644P */
/* should work with other mega's, see code for details */
/* */
/* ATmegaBOOT.c */
/* */
/* 20090131: Added 324P support from Alex Leone */
/* Marius Kintel */
/* 20080915: applied ADABoot mods for Sanguino 644P */
/* Brian Riley */
/* 20080711: hacked for Sanguino by Zach Smith */
/* and Justin Day */
/* 20070626: hacked for Arduino Diecimila (which auto- */
/* resets when a USB connection is made to it) */
/* by D. Mellis */
/* 20060802: hacked for Arduino by D. Cuartielles */
/* based on a previous hack by D. Mellis */
/* and D. Cuartielles */
/* */
/* Monitor and debug functions were added to the original */
/* code by Dr. Erik Lins, chip45.com. (See below) */
/* */
/* Thanks to Karl Pitrich for fixing a bootloader pin */
/* problem and more informative LED blinking! */
/* */
/* For the latest version see: */
/* http://www.chip45.com/ */
/* */
/* ------------------------------------------------------ */
/* */
/* based on stk500boot.c */
/* Copyright (c) 2003, Jason P. Kyle */
/* All rights reserved. */
/* see avr1.org for original file and information */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or FITNESS FOR A */
/* PARTICULAR PURPOSE. See the GNU General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, write */
/* to the Free Software Foundation, Inc., */
/* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* */
/* Licence can be viewed at */
/* http://www.fsf.org/licenses/gpl.txt */
/* */
/* Target = Atmel AVR m128,m64,m32,m16,m8,m162,m163,m169, */
/* m8515,m8535. ATmega161 has a very small boot block so */
/* isn't supported. */
/* */
/* Tested with m168 */
/**********************************************************/
/* $Id$ */
/* some includes */
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <avr/boot.h>
#ifdef ADABOOT
#define NUM_LED_FLASHES 3
#define ADABOOT_VER 1
#endif
/* 20070707: hacked by David A. Mellis - after this many errors give up and launch application */
#define MAX_ERROR_COUNT 5
/* set the UART baud rate */
/* 20080711: hack by Zach Hoeken */
#define BAUD_RATE 38400
/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */
/* never allow AVR Studio to do an update !!!! */
#define HW_VER 0x02
#define SW_MAJOR 0x01
#define SW_MINOR 0x10
/* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */
/* if monitor functions are included, LED goes on after monitor was entered */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED PINB0
/* define various device id's */
/* manufacturer byte is always the same */
#define SIG1 0x1E // Yep, Atmel is the only manufacturer of AVR micros. Single source :(
#if defined(__AVR_ATmega1284P__)
#define SIG2 0x97
#define SIG3 0x05
#elif defined(__AVR_ATmega644P__)
#define SIG2 0x96
#define SIG3 0x0A
#elif defined(__AVR_ATmega644__)
#define SIG2 0x96
#define SIG3 0x09
#elif defined(__AVR_ATmega324P__)
#define SIG2 0x95
#define SIG3 0x08
#endif
#define PAGE_SIZE 0x080U //128 words
#define PAGE_SIZE_BYTES 0x100U //256 bytes
/* function prototypes */
void putch(char);
char getch(void);
void getNch(uint8_t);
void byte_response(uint8_t);
void nothing_response(void);
char gethex(void);
void puthex(char);
void flash_led(uint8_t);
/* some variables */
union address_union
{
uint16_t word;
uint8_t byte[2];
} address;
union length_union
{
uint16_t word;
uint8_t byte[2];
} length;
struct flags_struct
{
unsigned eeprom : 1;
unsigned rampz : 1;
} flags;
uint8_t buff[256];
uint8_t error_count = 0;
uint8_t sreg;
void (*app_start)(void) = 0x0000;
/* main program starts here */
int main(void)
{
uint8_t ch,ch2;
uint16_t w;
uint16_t i;
asm volatile("nop\n\t");
#ifdef ADABOOT // BBR/LF 10/8/2007 & 9/13/2008
ch = MCUSR;
MCUSR = 0;
WDTCSR |= _BV(WDCE) | _BV(WDE);
WDTCSR = 0;
// Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
if (! (ch & _BV(EXTRF))) // if its a not an external reset...
app_start(); // skip bootloader
#endif
//initialize our serial port.
UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSR0B = (1<<RXEN0) | (1<<TXEN0);
UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
/* Enable internal pull-up resistor on pin D0 (RX), in order
to supress line noise that prevents the bootloader from
timing out (DAM: 20070509) */
DDRD &= ~_BV(PIND0);
PORTD |= _BV(PIND0);
/* set LED pin as output */
LED_DDR |= _BV(LED);
/* flash onboard LED to signal entering of bootloader */
/* ADABOOT will do two series of flashes. first 4 - signifying ADABOOT */
/* then a pause and another flash series signifying ADABOOT sub-version */
flash_led(NUM_LED_FLASHES);
#ifdef ADABOOT
flash_led(ADABOOT_VER); // BBR 9/13/2008
#endif
/* forever loop */
for (;;)
{
/* get character from UART */
ch = getch();
/* A bunch of if...else if... gives smaller code than switch...case ! */
/* Hello is anyone home ? */
if(ch=='0')
nothing_response();
/* Request programmer ID */
/* Not using PROGMEM string due to boot block in m128 being beyond 64kB boundry */
/* Would need to selectively manipulate RAMPZ, and it's only 9 characters anyway so who cares. */
else if(ch=='1')
{
if (getch() == ' ')
{
putch(0x14);
putch('A');
putch('V');
putch('R');
putch(' ');
putch('I');
putch('S');
putch('P');
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
/* AVR ISP/STK500 board commands DON'T CARE so default nothing_response */
else if(ch=='@')
{
ch2 = getch();
if (ch2 > 0x85)
getch();
nothing_response();
}
/* AVR ISP/STK500 board requests */
else if(ch=='A')
{
ch2 = getch();
if(ch2 == 0x80)
byte_response(HW_VER); // Hardware version
else if(ch2==0x81)
byte_response(SW_MAJOR); // Software major version
else if(ch2==0x82)
byte_response(SW_MINOR); // Software minor version
else if(ch2==0x98)
byte_response(0x03); // Unknown but seems to be required by avr studio 3.56
else
byte_response(0x00); // Covers various unnecessary responses we don't care about
}
/* Device Parameters DON'T CARE, DEVICE IS FIXED */
else if(ch=='B')
{
getNch(20);
nothing_response();
}
/* Parallel programming stuff DON'T CARE */
else if(ch=='E')
{
getNch(5);
nothing_response();
}
/* Enter programming mode */
else if(ch=='P')
{
nothing_response();
}
/* Leave programming mode */
else if(ch=='Q')
{
nothing_response();
#ifdef ADABOOT
// autoreset via watchdog (sneaky!) BBR/LF 9/13/2008
WDTCSR = _BV(WDE);
while (1); // 16 ms
#endif
}
/* Erase device, don't care as we will erase one page at a time anyway. */
else if(ch=='R')
{
nothing_response();
}
/* Set address, little endian. EEPROM in bytes, FLASH in words */
/* Perhaps extra address bytes may be added in future to support > 128kB FLASH. */
/* This might explain why little endian was used here, big endian used everywhere else. */
else if(ch=='U')
{
address.byte[0] = getch();
address.byte[1] = getch();
nothing_response();
}
/* Universal SPI programming command, disabled. Would be used for fuses and lock bits. */
else if(ch=='V')
{
getNch(4);
byte_response(0x00);
}
/* Write memory, length is big endian and is in bytes */
else if(ch=='d')
{
length.byte[1] = getch();
length.byte[0] = getch();
flags.eeprom = 0;
if (getch() == 'E')
flags.eeprom = 1;
for (i=0; i<PAGE_SIZE; i++)
buff[i] = 0;
for (w = 0; w < length.word; w++)
{
// Store data in buffer, can't keep up with serial data stream whilst programming pages
buff[w] = getch();
}
if (getch() == ' ')
{
if (flags.eeprom)
{
//Write to EEPROM one byte at a time
for(w=0;w<length.word;w++)
{
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EEDR = buff[w];
EECR |= (1<<EEMPE);
EECR |= (1<<EEPE);
address.word++;
}
}
else
{
//address * 2 -> byte location
address.word = address.word << 1;
//Even up an odd number of bytes
if ((length.byte[0] & 0x01))
length.word++;
// HACKME: EEPE used to be EEWE
//Wait for previous EEPROM writes to complete
//while(bit_is_set(EECR,EEPE));
while(EECR & (1<<EEPE));
asm volatile(
"clr r17 \n\t" //page_word_count
"lds r30,address \n\t" //Address of FLASH location (in bytes)
"lds r31,address+1 \n\t"
"ldi r28,lo8(buff) \n\t" //Start of buffer array in RAM
"ldi r29,hi8(buff) \n\t"
"lds r24,length \n\t" //Length of data to be written (in bytes)
"lds r25,length+1 \n\t"
"length_loop: \n\t" //Main loop, repeat for number of words in block
"cpi r17,0x00 \n\t" //If page_word_count=0 then erase page
"brne no_page_erase \n\t"
"wait_spm1: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm1 \n\t"
"ldi r16,0x03 \n\t" //Erase page pointed to by Z
"sts %0,r16 \n\t"
"spm \n\t"
"wait_spm2: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm2 \n\t"
"ldi r16,0x11 \n\t" //Re-enable RWW section
"sts %0,r16 \n\t"
"spm \n\t"
"no_page_erase: \n\t"
"ld r0,Y+ \n\t" //Write 2 bytes into page buffer
"ld r1,Y+ \n\t"
"wait_spm3: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm3 \n\t"
"ldi r16,0x01 \n\t" //Load r0,r1 into FLASH page buffer
"sts %0,r16 \n\t"
"spm \n\t"
"inc r17 \n\t" //page_word_count++
"cpi r17,%1 \n\t"
"brlo same_page \n\t" //Still same page in FLASH
"write_page: \n\t"
"clr r17 \n\t" //New page, write current one first
"wait_spm4: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm4 \n\t"
"ldi r16,0x05 \n\t" //Write page pointed to by Z
"sts %0,r16 \n\t"
"spm \n\t"
"wait_spm5: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm5 \n\t"
"ldi r16,0x11 \n\t" //Re-enable RWW section
"sts %0,r16 \n\t"
"spm \n\t"
"same_page: \n\t"
"adiw r30,2 \n\t" //Next word in FLASH
"sbiw r24,2 \n\t" //length-2
"breq final_write \n\t" //Finished
"rjmp length_loop \n\t"
"final_write: \n\t"
"cpi r17,0 \n\t"
"breq block_done \n\t"
"adiw r24,2 \n\t" //length+2, fool above check on length after short page write
"rjmp write_page \n\t"
"block_done: \n\t"
"clr __zero_reg__ \n\t" //restore zero register
: "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
);
}
putch(0x14);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
/* Read memory block mode, length is big endian. */
else if(ch=='t')
{
length.byte[1] = getch();
length.byte[0] = getch();
if (getch() == 'E')
flags.eeprom = 1;
else
{
flags.eeprom = 0;
address.word = address.word << 1; // address * 2 -> byte location
}
// Command terminator
if (getch() == ' ')
{
putch(0x14);
for (w=0; w<length.word; w++)
{
// Can handle odd and even lengths okay
if (flags.eeprom)
{
// Byte access EEPROM read
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EECR |= (1<<EERE);
putch(EEDR);
address.word++;
}
else
{
if (!flags.rampz)
putch(pgm_read_byte_near(address.word));
address.word++;
}
}
putch(0x10);
}
}
/* Get device signature bytes */
else if(ch=='u')
{
if (getch() == ' ')
{
putch(0x14);
putch(SIG1);
putch(SIG2);
putch(SIG3);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
/* Read oscillator calibration byte */
else if(ch=='v')
byte_response(0x00);
else if (++error_count == MAX_ERROR_COUNT)
app_start();
}
/* end of forever loop */
}
char gethex(void)
{
char ah,al;
ah = getch();
putch(ah);
al = getch();
putch(al);
if(ah >= 'a')
ah = ah - 'a' + 0x0a;
else if(ah >= '0')
ah -= '0';
if(al >= 'a')
al = al - 'a' + 0x0a;
else if(al >= '0')
al -= '0';
return (ah << 4) + al;
}
void puthex(char ch)
{
char ah,al;
ah = (ch & 0xf0) >> 4;
if(ah >= 0x0a)
ah = ah - 0x0a + 'a';
else
ah += '0';
al = (ch & 0x0f);
if(al >= 0x0a)
al = al - 0x0a + 'a';
else
al += '0';
putch(ah);
putch(al);
}
void putch(char ch)
{
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
}
char getch(void)
{
uint32_t count = 0;
#ifdef ADABOOT
LED_PORT &= ~_BV(LED); // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
#endif
while(!(UCSR0A & _BV(RXC0)))
{
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
/* HACKME:: here is a good place to count times*/
count++;
if (count > MAX_TIME_COUNT)
app_start();
}
#ifdef ADABOOT
LED_PORT |= _BV(LED); // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
#endif
return UDR0;
}
void getNch(uint8_t count)
{
uint8_t i;
for(i=0;i<count;i++)
{
while(!(UCSR0A & _BV(RXC0)));
UDR0;
}
}
void byte_response(uint8_t val)
{
if (getch() == ' ')
{
putch(0x14);
putch(val);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
void nothing_response(void)
{
if (getch() == ' ')
{
putch(0x14);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
#ifdef ADABOOT
void flash_led(uint8_t count)
{
/* flash onboard LED count times to signal entering of bootloader */
/* l needs to be volatile or the delay loops below might get */
/* optimized away if compiling with optimizations (DAM). */
volatile uint32_t l;
if (count == 0) {
count = ADABOOT;
}
int8_t i;
for (i = 0; i < count; ++i) {
LED_PORT |= _BV(LED); // LED on
for(l = 0; l < (F_CPU / 1000); ++l); // delay NGvalue was 1000 for both loops - BBR
LED_PORT &= ~_BV(LED); // LED off
for(l = 0; l < (F_CPU / 250); ++l); // delay asymmteric for ADA BOOT BBR
}
for(l = 0; l < (F_CPU / 100); ++l); // pause ADA BOOT BBR
}
#else
void flash_led(uint8_t count)
{
/* flash onboard LED three times to signal entering of bootloader */
/* l needs to be volatile or the delay loops below might get
optimized away if compiling with optimizations (DAM). */
volatile uint32_t l;
if (count == 0) {
count = 3;
}
int8_t i;
for (i = 0; i < count; ++i) {
LED_PORT |= _BV(LED);
for(l = 0; l < (F_CPU / 1000); ++l);
LED_PORT &= ~_BV(LED);
for(l = 0; l < (F_CPU / 1000); ++l);
}
}
#endif
/* end of file ATmegaBOOT.c */

View File

@ -0,0 +1,388 @@
/**********************************************************/
/* Serial Bootloader for Atmel megaAVR Controllers */
/* */
/* tested with ATmega644 and ATmega644P */
/* should work with other mega's, see code for details */
/* */
/* ATmegaBOOT.c */
/* */
/* 20090131: Added 324P support from Alex Leone */
/* Marius Kintel */
/* 20080915: applied ADABoot mods for Sanguino 644P */
/* Brian Riley */
/* 20080711: hacked for Sanguino by Zach Smith */
/* and Justin Day */
/* 20070626: hacked for Arduino Diecimila (which auto- */
/* resets when a USB connection is made to it) */
/* by D. Mellis */
/* 20060802: hacked for Arduino by D. Cuartielles */
/* based on a previous hack by D. Mellis */
/* and D. Cuartielles */
/* */
/* Monitor and debug functions were added to the original */
/* code by Dr. Erik Lins, chip45.com. (See below) */
/* */
/* Thanks to Karl Pitrich for fixing a bootloader pin */
/* problem and more informative LED blinking! */
/* */
/* For the latest version see: */
/* http://www.chip45.com/ */
/* */
/* ------------------------------------------------------ */
/* */
/* based on stk500boot.c */
/* Copyright (c) 2003, Jason P. Kyle */
/* All rights reserved. */
/* see avr1.org for original file and information */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or FITNESS FOR A */
/* PARTICULAR PURPOSE. See the GNU General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, write */
/* to the Free Software Foundation, Inc., */
/* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* */
/* Licence can be viewed at */
/* http://www.fsf.org/licenses/gpl.txt */
/* */
/* Target = Atmel AVR m128,m64,m32,m16,m8,m162,m163,m169, */
/* m8515,m8535. ATmega161 has a very small boot block so */
/* isn't supported. */
/* */
/* Tested with m168 */
/**********************************************************/
/* $Id$ */
/* some includes */
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <avr/boot.h>
#include <util/delay.h>
#ifdef ADABOOT
#define NUM_LED_FLASHES 3
#define ADABOOT_VER 1
#endif
/* 20070707: hacked by David A. Mellis - after this many errors give up and launch application */
#define MAX_ERROR_COUNT 5
/* set the UART baud rate */
/* 20080711: hack by Zach Hoeken */
#define BAUD_RATE 38400
/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */
/* never allow AVR Studio to do an update !!!! */
#define HW_VER 0x02
#define SW_MAJOR 0x01
#define SW_MINOR 0x10
/* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */
/* if monitor functions are included, LED goes on after monitor was entered */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED PINB0
/* define various device id's */
/* manufacturer byte is always the same */
#define SIG1 0x1E // Yep, Atmel is the only manufacturer of AVR micros. Single source :(
#if defined(__AVR_ATmega1284P__)
#define SIG2 0x97
#define SIG3 0x05
#elif defined(__AVR_ATmega644P__)
#define SIG2 0x96
#define SIG3 0x0A
#elif defined(__AVR_ATmega644__)
#define SIG2 0x96
#define SIG3 0x09
#elif defined(__AVR_ATmega324P__)
#define SIG2 0x95
#define SIG3 0x08
#endif
#define PAGE_SIZE 0x080U //128 words
#define PAGE_SIZE_BYTES 0x100U //256 bytes
/* function prototypes */
void putch(char);
char getch(void);
void getNch(uint8_t);
void byte_response(uint8_t);
void nothing_response(void);
char gethex(void);
void puthex(char);
void flash_led(uint8_t);
/* some variables */
union address_union
{
uint16_t word;
uint8_t byte[2];
} address;
union length_union
{
uint16_t word;
uint8_t byte[2];
} length;
struct flags_struct
{
unsigned eeprom : 1;
unsigned rampz : 1;
} flags;
uint8_t buff[256];
uint8_t error_count = 0;
uint8_t sreg;
void (*app_start)(void) = 0x0000;
/* main program starts here */
int main(void)
{
uint8_t ch,ch2;
uint16_t w;
uint16_t i;
asm volatile("nop\n\t");
#ifdef ADABOOT // BBR/LF 10/8/2007 & 9/13/2008
ch = MCUSR;
MCUSR = 0;
WDTCSR |= _BV(WDCE) | _BV(WDE);
WDTCSR = 0;
// Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
if (! (ch & _BV(EXTRF))) // if its a not an external reset...
app_start(); // skip bootloader
#endif
//initialize our serial port.
UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSR0B = (1<<RXEN0) | (1<<TXEN0);
UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
/* Enable internal pull-up resistor on pin D0 (RX), in order
to supress line noise that prevents the bootloader from
timing out (DAM: 20070509) */
DDRD &= ~_BV(PIND0);
PORTD |= _BV(PIND0);
/* set LED pin as output */
LED_DDR |= _BV(LED);
/* flash onboard LED to signal entering of bootloader */
/* ADABOOT will do two series of flashes. first 4 - signifying ADABOOT */
/* then a pause and another flash series signifying ADABOOT sub-version */
flash_led(NUM_LED_FLASHES);
#ifdef ADABOOT
flash_led(ADABOOT_VER); // BBR 9/13/2008
#endif
/* forever loop */
for (;;)
{
putch('\r');
_delay_ms(500);
}
/* end of forever loop */
}
char gethex(void)
{
char ah,al;
ah = getch();
putch(ah);
al = getch();
putch(al);
if(ah >= 'a')
ah = ah - 'a' + 0x0a;
else if(ah >= '0')
ah -= '0';
if(al >= 'a')
al = al - 'a' + 0x0a;
else if(al >= '0')
al -= '0';
return (ah << 4) + al;
}
void puthex(char ch)
{
char ah,al;
ah = (ch & 0xf0) >> 4;
if(ah >= 0x0a)
ah = ah - 0x0a + 'a';
else
ah += '0';
al = (ch & 0x0f);
if(al >= 0x0a)
al = al - 0x0a + 'a';
else
al += '0';
putch(ah);
putch(al);
}
void putch(char ch)
{
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
}
char getch(void)
{
uint32_t count = 0;
#ifdef ADABOOT
LED_PORT &= ~_BV(LED); // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
#endif
while(!(UCSR0A & _BV(RXC0)))
{
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
/* HACKME:: here is a good place to count times*/
count++;
if (count > MAX_TIME_COUNT)
app_start();
}
#ifdef ADABOOT
LED_PORT |= _BV(LED); // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
#endif
return UDR0;
}
void getNch(uint8_t count)
{
uint8_t i;
for(i=0;i<count;i++)
{
while(!(UCSR0A & _BV(RXC0)));
UDR0;
}
}
void byte_response(uint8_t val)
{
if (getch() == ' ')
{
putch(0x14);
putch(val);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
void nothing_response(void)
{
if (getch() == ' ')
{
putch(0x14);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
#ifdef ADABOOT
void flash_led(uint8_t count)
{
/* flash onboard LED count times to signal entering of bootloader */
/* l needs to be volatile or the delay loops below might get */
/* optimized away if compiling with optimizations (DAM). */
volatile uint32_t l;
if (count == 0) {
count = ADABOOT;
}
int8_t i;
for (i = 0; i < count; ++i) {
LED_PORT |= _BV(LED); // LED on
for(l = 0; l < (F_CPU / 1000); ++l); // delay NGvalue was 1000 for both loops - BBR
LED_PORT &= ~_BV(LED); // LED off
for(l = 0; l < (F_CPU / 250); ++l); // delay asymmteric for ADA BOOT BBR
}
for(l = 0; l < (F_CPU / 100); ++l); // pause ADA BOOT BBR
}
#else
void flash_led(uint8_t count)
{
/* flash onboard LED three times to signal entering of bootloader */
/* l needs to be volatile or the delay loops below might get
optimized away if compiling with optimizations (DAM). */
volatile uint32_t l;
if (count == 0) {
count = 3;
}
int8_t i;
for (i = 0; i < count; ++i) {
LED_PORT |= _BV(LED);
for(l = 0; l < (F_CPU / 1000); ++l);
LED_PORT &= ~_BV(LED);
for(l = 0; l < (F_CPU / 1000); ++l);
}
}
#endif
/* end of file ATmegaBOOT.c */

View File

@ -0,0 +1,110 @@
:020000021000EC
:10F000000C943EF80C9450F80C9450F80C9450F872
:10F010000C9450F80C9450F80C9450F80C9450F850
:10F020000C9450F80C9450F80C9450F80C9450F840
:10F030000C9450F80C9450F80C9450F80C9450F830
:10F040000C9450F80C9450F80C9450F80C9450F820
:10F050000C9450F80C9450F80C9450F80C9450F810
:10F060000C9450F80C9450F80C9450F80C9450F800
:10F070000C9450F80C9450F80C9450F811241FBEC6
:10F08000CFEFD0E1DEBFCDBF12E0A0E0B1E001C024
:10F090001D92A930B107E1F70E9471F90C944FFB62
:10F0A0000C9400F89091C00095FFFCCF8093C600AF
:10F0B00008951F93282F332727FD3095207F307028
:10F0C00094E0359527959A95E1F72A3014F0295A5E
:10F0D00001C0205D182F1F701A3014F0195A01C09A
:10F0E000105D822F0E9452F8812F0E9452F81F91CA
:10F0F0000895EF92FF920F931F932898EE24FF2418
:10F10000870113C00894E11CF11C011D111D81E051
:10F11000E81689E0F8068DE3080780E0180728F074
:10F12000E0910101F091020109958091C00087FFF3
:10F13000E9CF289A8091C6001F910F91FF90EF9020
:10F1400008950F931F930E9479F8082F0E9452F898
:10F150000E9479F8182F0E9452F8013614F00755D2
:10F1600003C000330CF00053113614F0175503C0E0
:10F1700010330CF01053802F8295807F810F1F91E8
:10F180000F91089590E007C02091C00027FFFCCFA9
:10F190002091C6009F5F9817B8F308951F93182F0A
:10F1A0000E9479F8803251F484E10E9452F8812F54
:10F1B0000E9452F880E10E9452F80CC08091000138
:10F1C0008F5F80930001853029F4E0910101F09177
:10F1D000020109951F9108950E9479F8803239F44F
:10F1E00084E10E9452F880E10E9452F808958091D3
:10F1F00000018F5F80930001853029F4E0910101C7
:10F20000F091020109950895DF93CF9300D000D0CB
:10F21000CDB7DEB7882309F481E090E03DC0289A9D
:10F2200019821A821B821C820CC029813A814B816F
:10F230005C812F5F3F4F4F4F5F4F29833A834B8352
:10F240005C8329813A814B815C8120386EE33607EB
:10F2500060E0460760E0560740F3289819821A825A
:10F260001B821C820CC029813A814B815C812F5FFB
:10F270003F4F4F4F5F4F29833A834B835C832981F4
:10F280003A814B815C8120306AEF360760E04607A7
:10F2900060E0560740F39F5F981709F619821A82BB
:10F2A0001B821C820BC089819A81AB81BC81019633
:10F2B000A11DB11D89839A83AB83BC8389819A8107
:10F2C000AB81BC81803021E7920722E0A20720E0D9
:10F2D000B20748F30F900F900F900F90CF91DF91EE
:10F2E0000895CF92DF92EF92FF920F931F93CF93E7
:10F2F000DF93000094B714BE809160008861809312
:10F3000060001092600091FD05C0E0910101F09154
:10F310000201099589E18093C4001092C50088E13B
:10F320008093C10086E08093C2005098589A209A3A
:10F3300083E00E9404F981E00E9404F90E9479F8B8
:10F34000803309F441C08133E1F40E9479F88032BE
:10F3500009F097C184E10E9452F881E40E9452F8BA
:10F3600086E50E9452F882E50E9452F880E20E94EF
:10F3700052F889E40E9452F883E50E9452F880E531
:10F380000BC1803439F40E9479F88638E8F00E9485
:10F3900079F81AC0813499F40E9479F8803811F410
:10F3A00082E06CC1813811F481E068C1823811F4C7
:10F3B00080E164C1883909F060C183E05FC18234B3
:10F3C00031F484E10E94C2F80E94ECF8B7CF853492
:10F3D00011F485E0F7CF8035B9F3813531F40E941F
:10F3E000ECF888E080936000FFCF823569F38535C3
:10F3F00049F40E9479F8809303010E9479F8809380
:10F400000401E2CF863521F484E00E94C2F835C1C0
:10F41000843609F0C7C00E9479F8809306020E94E2
:10F4200079F880930502809108028E7F809308020C
:10F430000E9479F8853429F48091080281608093D4
:10F44000080205E011E0F801119281E0E538F807C3
:10F45000D9F745E0C42E41E0D42EEE24FF2408C0A5
:10F460000E9479F8F60181936F010894E11CF11C68
:10F470008091050290910602E816F90688F30E9431
:10F4800079F8803209F0FDC08091080280FD17C034
:10F4900020C0F999FECF209103013091040132BDC3
:10F4A00021BDF80141918F0140BDFA9AF99A2F5F71
:10F4B0003F4F3093040120930301019602C080E086
:10F4C00090E020910502309106028217930708F31D
:10F4D00062C08091030190910401880F991F90935D
:10F4E0000401809303018091050280FF09C080918F
:10F4F0000502909106020196909306028093050200
:10F50000F999FECF1127E0910301F0910401C5E0C4
:10F51000D1E08091050290910602103091F40091A3
:10F52000570001700130D9F303E000935700E895CC
:10F530000091570001700130D9F301E100935700A9
:10F54000E895099019900091570001700130D9F3A6
:10F5500001E000935700E8951395103898F01127B3
:10F560000091570001700130D9F305E00093570076
:10F57000E8950091570001700130D9F301E1009343
:10F580005700E8953296029709F0C7CF103011F076
:10F590000296E5CF112484E10E9452F880E10E9496
:10F5A00052F8CCCE843709F055C00E9479F8809388
:10F5B00006020E9479F8809305020E9479F89091E2
:10F5C0000802853421F49160909308020DC09E7F5B
:10F5D000909308028091030190910401880F991F74
:10F5E00090930401809303010E9479F8803209F01E
:10F5F000A5CE84E10E9452F800E010E023C0809183
:10F60000080280FF0BC0F999FECF80910301909111
:10F61000040192BD81BDF89A80B507C081FD07C085
:10F62000E0910301F091040184910E9452F88091CD
:10F6300003019091040101969093040180930301CA
:10F640000F5F1F4F8091050290910602081719075E
:10F65000B0F2A4CF853779F40E9479F8803289F42A
:10F6600084E10E9452F88EE10E9452F886E90E94DD
:10F6700052F88AE091CF863721F480E00E94CEF8DC
:10F680005DCE809100018F5F80930001853009F08D
:10F6900055CEE0910101F091020109954FCEF89409
:02F6A000FFCF9A
:040000031000F000F9
:00000001FF

View File

@ -0,0 +1,56 @@
#Makefile for ATmegaBOOT
# E.Lins, 18.7.2005
# $Id$
# program name should not be changed...
PROGRAM = ATmegaBOOT_644P
# enter the target CPU frequency
AVR_FREQ = 16000000L
MCU_TARGET = atmega644p
LDSECTION = --section-start=.text=0x1F000
OBJ = $(PROGRAM).o
OPTIMIZE = -Os
DEFS =
LIBS =
CC = avr-gcc
# Override is only needed by avr-lib build system.
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)
override LDFLAGS = -Wl,$(LDSECTION)
#override LDFLAGS = -Wl,-Map,$(PROGRAM).map,$(LDSECTION)
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
all: CFLAGS += '-DMAX_TIME_COUNT=8000000L>>1' -DADABOOT
all: $(PROGRAM).hex
$(PROGRAM).hex: $(PROGRAM).elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
$(PROGRAM).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
$(OBJ): ATmegaBOOT.c
avr-gcc $(CFLAGS) $(LDFLAGS) -c -g -Os -Wall -mmcu=$(MCU_TARGET) ATmegaBOOT.c -o $(PROGRAM).o
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
clean:
rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex

View File

@ -0,0 +1,3 @@
Note: This bootloader support ATmega644, ATmega644P and ATmega324P.
To build, set PROGRAM and MCU_TARGET in the Makefile according to your target device.