Version 0.83 (20080412)
This commit is contained in:
parent
2c2646b64f
commit
7c18de72f8
@ -1 +1 @@
|
|||||||
<Project name="avrprog_boot"><File path="chipdef.h"></File><File path="main.c"></File><File path="makefile"></File><File path="mega128.h"></File><File path="mega128can.h"></File><File path="mega16.h"></File><File path="mega169.h"></File><File path="mega32.h"></File><File path="mega8.h"></File><File path="readme.txt"></File><File path="ldscripts_no_vector\avr5.x"></File><File path="main.lss"></File><File path="main.map"></File><File path="ldscripts_no_vector\avr4.x"></File></Project>
|
<Project name="avrprog_boot"><File path="chipdef.h"></File><File path="main.c"></File><File path="makefile"></File><File path="mega128.h"></File><File path="mega128can.h"></File><File path="mega16.h"></File><File path="mega169.h"></File><File path="mega32.h"></File><File path="mega8.h"></File><File path="readme.txt"></File><File path="ldscripts_no_vector\avr5.x"></File><File path="main.lss"></File><File path="main.map"></File><File path="ldscripts_no_vector\avr4.x"></File><File path="mega162.h"></File><File path="mega644.h"></File><File path="mega644p.h"></File><File path="megaxx4p.h"></File><File path="mega324p.h"></File></Project>
|
12
chipdef.h
12
chipdef.h
@ -25,12 +25,24 @@ typedef uint8_t pagebuf_t;
|
|||||||
#elif defined(__AVR_ATmega16__)
|
#elif defined(__AVR_ATmega16__)
|
||||||
#include "mega16.h"
|
#include "mega16.h"
|
||||||
|
|
||||||
|
#elif defined(__AVR_ATmega162__)
|
||||||
|
#include "mega162.h"
|
||||||
|
|
||||||
#elif defined(__AVR_ATmega8__)
|
#elif defined(__AVR_ATmega8__)
|
||||||
#include "mega8.h"
|
#include "mega8.h"
|
||||||
|
|
||||||
#elif defined(__AVR_ATmega32__)
|
#elif defined(__AVR_ATmega32__)
|
||||||
#include "mega32.h"
|
#include "mega32.h"
|
||||||
|
|
||||||
|
#elif defined(__AVR_ATmega324P__)
|
||||||
|
#include "mega324p.h"
|
||||||
|
|
||||||
|
#elif defined(__AVR_ATmega644__)
|
||||||
|
#include "mega644.h"
|
||||||
|
|
||||||
|
#elif defined(__AVR_ATmega644P__)
|
||||||
|
#include "mega644p.h"
|
||||||
|
|
||||||
#elif defined(__AVR_ATmega128__)
|
#elif defined(__AVR_ATmega128__)
|
||||||
#include "mega128.h"
|
#include "mega128.h"
|
||||||
|
|
||||||
|
136
main.c
136
main.c
@ -1,8 +1,8 @@
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* AVRPROG compatible boot-loader
|
* AVRPROG compatible boot-loader
|
||||||
* Version : 0.80beta3 (May 2006)
|
* Version : 0.83 (Apr. 2008)
|
||||||
* Compiler : avr-gcc 3.4.6 / avr-libc 1.4.4
|
* Compiler : avr-gcc 4.1.2 / avr-libc 1.4.6
|
||||||
* size : depends on features and startup ( minmal features < 512 words)
|
* size : depends on features and startup ( minmal features < 512 words)
|
||||||
* by : Martin Thomas, Kaiserslautern, Germany
|
* by : Martin Thomas, Kaiserslautern, Germany
|
||||||
* eversmith@heizung-thomas.de
|
* eversmith@heizung-thomas.de
|
||||||
@ -11,33 +11,27 @@
|
|||||||
* - Bjoern Riemer
|
* - Bjoern Riemer
|
||||||
* - Olaf Rempel
|
* - Olaf Rempel
|
||||||
*
|
*
|
||||||
* License : Copyright (c) 2006 Martin Thomas
|
* License : Copyright (c) 2006-2008 M. Thomas, U. Bonnes, O. Rempel
|
||||||
* Free to use. You have to mention the copyright
|
* Free to use. You have to mention the copyright
|
||||||
* owners in source-code and documentation of derived
|
* owners in source-code and documentation of derived
|
||||||
* work. No warranty!
|
* work. No warranty! (Yes, you can insert the BSD
|
||||||
|
* license here)
|
||||||
*
|
*
|
||||||
* Tested with ATmega8, ATmega16, ATmega32, ATmega128, AT90CAN128
|
* Tested with ATmega8, ATmega16, ATmega162, ATmega32, ATmega324P,
|
||||||
|
* ATmega644, ATmega644P, ATmega128, AT90CAN128
|
||||||
*
|
*
|
||||||
* - Initial versions have been based on the Butterfly bootloader-code
|
* - Initial versions have been based on the Butterfly bootloader-code
|
||||||
* by Atmel Corporation (Authors: BBrandal, PKastnes, ARodland, LHM)
|
* by Atmel Corporation (Authors: BBrandal, PKastnes, ARodland, LHM)
|
||||||
*
|
*
|
||||||
****************************************************************************
|
****************************************************************************
|
||||||
*
|
*
|
||||||
* See the makefile for information how to adapt the linker-settings to
|
* See the makefile and readme.txt for information on how to adapt
|
||||||
* the selected Boot Size (BOOTSIZE=xxxx), the AVR clock-frequency and the
|
* the linker-settings to the selected Boot Size (BOOTSIZE=xxxx) and
|
||||||
* MCU-type in
|
* the MCU-type. Other configurations futher down in this file.
|
||||||
*
|
*
|
||||||
* With BOOT_SIMPLE, minimal features and discarded int-vectors
|
* With BOOT_SIMPLE, minimal features and discarded int-vectors
|
||||||
* this bootloader has
|
* this bootloader has should fit into a a 512 word (1024, 0x400 bytes)
|
||||||
* 0x2CA - atmega8
|
* bootloader-section.
|
||||||
* 0x308 - atmega16
|
|
||||||
* 0x322 - atmega169
|
|
||||||
* 0x308 - atmega32
|
|
||||||
* 0x34C - atmega128
|
|
||||||
* 0x352 - at90can128
|
|
||||||
* bytes size and should fit into a 512 word (0x400 byte) bootloader-section.
|
|
||||||
* The above values depend on the compiler-version and may differ from
|
|
||||||
* your results.
|
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
/*
|
/*
|
||||||
@ -46,6 +40,7 @@
|
|||||||
- __bad_interrupt still linked even with modified
|
- __bad_interrupt still linked even with modified
|
||||||
linker-scripts which needs a default-handler,
|
linker-scripts which needs a default-handler,
|
||||||
"wasted": 3 words for AVR5 (>8kB), 2 words for AVR4
|
"wasted": 3 words for AVR5 (>8kB), 2 words for AVR4
|
||||||
|
- Check watchdog-disable-function in avr-libc.
|
||||||
*/
|
*/
|
||||||
// tabsize: 4
|
// tabsize: 4
|
||||||
|
|
||||||
@ -63,7 +58,7 @@
|
|||||||
/* use "Double Speed Operation" */
|
/* use "Double Speed Operation" */
|
||||||
//#define UART_DOUBLESPEED
|
//#define UART_DOUBLESPEED
|
||||||
|
|
||||||
/* use second UART on mega128 / can128 */
|
/* use second UART on mega128 / can128 / mega162 / mega324p / mega644p */
|
||||||
//#define UART_USE_SECOND
|
//#define UART_USE_SECOND
|
||||||
|
|
||||||
/* Device-Type:
|
/* Device-Type:
|
||||||
@ -71,16 +66,27 @@
|
|||||||
which is the "correct" value for a bootloader.
|
which is the "correct" value for a bootloader.
|
||||||
avrdude may only detect the part-code for ISP */
|
avrdude may only detect the part-code for ISP */
|
||||||
#define DEVTYPE DEVTYPE_BOOT
|
#define DEVTYPE DEVTYPE_BOOT
|
||||||
//#define DEVTYPE DEVTYPE_ISP
|
// #define DEVTYPE DEVTYPE_ISP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pin "STARTPIN" on port "STARTPORT" in this port has to grounded
|
* Pin "STARTPIN" on port "STARTPORT" in this port has to grounded
|
||||||
* (active low) to start the bootloader
|
* (active low) to start the bootloader
|
||||||
*/
|
*/
|
||||||
#define BLPORT PORTB
|
#define BLPORT PORTC
|
||||||
#define BLDDR DDRB
|
#define BLDDR DDRC
|
||||||
#define BLPIN PINB
|
#define BLPIN PINC
|
||||||
#define BLPNUM PINB0
|
#define BLPNUM PINC7
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define if Watchdog-Timer should be disable at startup
|
||||||
|
*/
|
||||||
|
#define DISABLE_WDT_AT_STARTUP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Watchdog-reset is issued at exit
|
||||||
|
* define the timeout-value here (see avr-libc manual)
|
||||||
|
*/
|
||||||
|
#define EXIT_WDT_TIME WDTO_250MS
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Select startup-mode
|
* Select startup-mode
|
||||||
@ -108,8 +114,8 @@
|
|||||||
/* character to start the bootloader in mode START_WAIT */
|
/* character to start the bootloader in mode START_WAIT */
|
||||||
#define START_WAIT_UARTCHAR 'S'
|
#define START_WAIT_UARTCHAR 'S'
|
||||||
|
|
||||||
/* wait 1s in START_WAIT mode (10ms steps) */
|
/* wait-time for START_WAIT mode ( t = WAIT_TIME * 10ms ) */
|
||||||
#define WAIT_VALUE 100
|
#define WAIT_VALUE 100 /* here: 100*10ms = 1000ms = 1sec */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* enable/disable readout of fuse and lock-bits
|
* enable/disable readout of fuse and lock-bits
|
||||||
@ -118,7 +124,7 @@
|
|||||||
*/
|
*/
|
||||||
//#define ENABLEREADFUSELOCK
|
//#define ENABLEREADFUSELOCK
|
||||||
|
|
||||||
/* enable/disable write of lock-bits
|
/* enable/disable write of lock-bits
|
||||||
* WARNING: lock-bits can not be reseted by bootloader (as far as I know)
|
* WARNING: lock-bits can not be reseted by bootloader (as far as I know)
|
||||||
* Only protection no unprotection, "chip erase" from bootloader only
|
* Only protection no unprotection, "chip erase" from bootloader only
|
||||||
* clears the flash but does no real "chip erase" (this is not possible
|
* clears the flash but does no real "chip erase" (this is not possible
|
||||||
@ -127,6 +133,13 @@
|
|||||||
*/
|
*/
|
||||||
//#define WRITELOCKBITS
|
//#define WRITELOCKBITS
|
||||||
|
|
||||||
|
/*
|
||||||
|
* define the following if the bootloader should not output
|
||||||
|
* itself at flash read (will fake an empty boot-section)
|
||||||
|
*/
|
||||||
|
#define READ_PROTECT_BOOTLOADER
|
||||||
|
|
||||||
|
|
||||||
#define VERSION_HIGH '0'
|
#define VERSION_HIGH '0'
|
||||||
#define VERSION_LOW '8'
|
#define VERSION_LOW '8'
|
||||||
|
|
||||||
@ -141,8 +154,9 @@
|
|||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
#include <avr/boot.h>
|
#include <avr/boot.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
// #include <util/delay.h>
|
#include <avr/eeprom.h>
|
||||||
#include <avr/delay.h>
|
#include <avr/interrupt.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
#include "chipdef.h"
|
#include "chipdef.h"
|
||||||
|
|
||||||
@ -184,8 +198,9 @@ static inline void recvBuffer(pagebuf_t size)
|
|||||||
pagebuf_t cnt;
|
pagebuf_t cnt;
|
||||||
uint8_t *tmp = gBuffer;
|
uint8_t *tmp = gBuffer;
|
||||||
|
|
||||||
for (cnt = 0; cnt < sizeof(gBuffer); cnt++)
|
for (cnt = 0; cnt < sizeof(gBuffer); cnt++) {
|
||||||
*tmp++ = (cnt < size) ? recvchar() : 0xFF;
|
*tmp++ = (cnt < size) ? recvchar() : 0xFF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint16_t writeFlashPage(uint16_t waddr, pagebuf_t size)
|
static inline uint16_t writeFlashPage(uint16_t waddr, pagebuf_t size)
|
||||||
@ -216,18 +231,13 @@ static inline uint16_t writeEEpromPage(uint16_t address, pagebuf_t size)
|
|||||||
uint8_t *tmp = gBuffer;
|
uint8_t *tmp = gBuffer;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
EEARL = address; // Setup EEPROM address
|
eeprom_write_byte( (uint8_t*)address, *tmp++ );
|
||||||
EEARH = (address >> 8);
|
|
||||||
EEDR = *tmp++;
|
|
||||||
address++; // Select next byte
|
address++; // Select next byte
|
||||||
|
|
||||||
EECR |= (1<<EEMWE); // Write data into EEPROM
|
|
||||||
EECR |= (1<<EEWE);
|
|
||||||
eeprom_busy_wait();
|
|
||||||
|
|
||||||
size--; // Decreas number of bytes to write
|
size--; // Decreas number of bytes to write
|
||||||
} while (size); // Loop until all bytes written
|
} while (size); // Loop until all bytes written
|
||||||
|
|
||||||
|
// eeprom_busy_wait();
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,16 +247,31 @@ static inline uint16_t readFlashPage(uint16_t waddr, pagebuf_t size)
|
|||||||
uint16_t data;
|
uint16_t data;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
#ifndef READ_PROTECT_BOOTLOADER
|
||||||
|
#warning "Bootloader not read-protected"
|
||||||
#if defined(RAMPZ)
|
#if defined(RAMPZ)
|
||||||
data = pgm_read_word_far(baddr);
|
data = pgm_read_word_far(baddr);
|
||||||
#else
|
#else
|
||||||
data = pgm_read_word_near(baddr);
|
data = pgm_read_word_near(baddr);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
// don't read bootloader
|
||||||
|
if ( baddr < APP_END ) {
|
||||||
|
#if defined(RAMPZ)
|
||||||
|
data = pgm_read_word_far(baddr);
|
||||||
|
#else
|
||||||
|
data = pgm_read_word_near(baddr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
data = 0xFFFF; // fake empty
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
sendchar(data); // send LSB
|
sendchar(data); // send LSB
|
||||||
sendchar((data >> 8)); // send MSB
|
sendchar((data >> 8)); // send MSB
|
||||||
baddr += 2; // Select next word in memory
|
baddr += 2; // Select next word in memory
|
||||||
size -= 2; // Subtract two bytes from number of bytes to read
|
size -= 2; // Subtract two bytes from number of bytes to read
|
||||||
} while (size); // Repeat until all block has been read
|
} while (size); // Repeat until block has been read
|
||||||
|
|
||||||
return baddr>>1;
|
return baddr>>1;
|
||||||
}
|
}
|
||||||
@ -254,15 +279,10 @@ static inline uint16_t readFlashPage(uint16_t waddr, pagebuf_t size)
|
|||||||
static inline uint16_t readEEpromPage(uint16_t address, pagebuf_t size)
|
static inline uint16_t readEEpromPage(uint16_t address, pagebuf_t size)
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
EEARL = address; // Setup EEPROM address
|
sendchar( eeprom_read_byte( (uint8_t*)address ) );
|
||||||
EEARH = (address >> 8);
|
address++;
|
||||||
EECR |= (1<<EERE); // Read EEPROM
|
|
||||||
address++; // Select next EEPROM byte
|
|
||||||
|
|
||||||
sendchar(EEDR); // Transmit EEPROM data to PC
|
|
||||||
|
|
||||||
size--; // Decrease number of bytes to read
|
size--; // Decrease number of bytes to read
|
||||||
} while (size); // Repeat until all block has been read
|
} while (size); // Repeat until block has been read
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
@ -307,6 +327,17 @@ int main(void)
|
|||||||
uint16_t address = 0;
|
uint16_t address = 0;
|
||||||
uint8_t device = 0, val;
|
uint8_t device = 0, val;
|
||||||
|
|
||||||
|
#ifdef DISABLE_WDT_AT_STARTUP
|
||||||
|
#ifdef WDT_OFF_SPECIAL
|
||||||
|
#warning "using target specific watchdog_off"
|
||||||
|
bootloader_wdt_off();
|
||||||
|
#else
|
||||||
|
cli();
|
||||||
|
wdt_reset();
|
||||||
|
wdt_disable();
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef START_POWERSAVE
|
#ifdef START_POWERSAVE
|
||||||
uint8_t OK = 1;
|
uint8_t OK = 1;
|
||||||
#endif
|
#endif
|
||||||
@ -319,7 +350,7 @@ int main(void)
|
|||||||
UART_BAUD_LOW = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF);
|
UART_BAUD_LOW = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF);
|
||||||
|
|
||||||
#ifdef UART_DOUBLESPEED
|
#ifdef UART_DOUBLESPEED
|
||||||
UART_STATUS = (1<<UART_DOUBLE);
|
UART_STATUS = ( 1<<UART_DOUBLE );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
UART_CTRL = UART_CTRL_DATA;
|
UART_CTRL = UART_CTRL_DATA;
|
||||||
@ -419,12 +450,10 @@ int main(void)
|
|||||||
if (device == DEVTYPE) {
|
if (device == DEVTYPE) {
|
||||||
if (val == 'F') {
|
if (val == 'F') {
|
||||||
address = writeFlashPage(address, size);
|
address = writeFlashPage(address, size);
|
||||||
|
|
||||||
} else if (val == 'E') {
|
} else if (val == 'E') {
|
||||||
address = writeEEpromPage(address, size);
|
address = writeEEpromPage(address, size);
|
||||||
}
|
}
|
||||||
sendchar('\r');
|
sendchar('\r');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sendchar(0);
|
sendchar(0);
|
||||||
}
|
}
|
||||||
@ -438,21 +467,20 @@ int main(void)
|
|||||||
|
|
||||||
if (val == 'F') {
|
if (val == 'F') {
|
||||||
address = readFlashPage(address, size);
|
address = readFlashPage(address, size);
|
||||||
|
|
||||||
} else if (val == 'E') {
|
} else if (val == 'E') {
|
||||||
address = readEEpromPage(address, size);
|
address = readEEpromPage(address, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chip erase
|
// Chip erase
|
||||||
} else if (val == 'e') {
|
} else if (val == 'e') {
|
||||||
if (device == DEVTYPE)
|
if (device == DEVTYPE) {
|
||||||
eraseFlash();
|
eraseFlash();
|
||||||
|
}
|
||||||
sendchar('\r');
|
sendchar('\r');
|
||||||
|
|
||||||
// Exit upgrade
|
// Exit upgrade
|
||||||
} else if (val == 'E') {
|
} else if (val == 'E') {
|
||||||
wdt_enable(WDTO_15MS); // Enable Watchdog Timer to give reset
|
wdt_enable(EXIT_WDT_TIME); // Enable Watchdog Timer to give reset
|
||||||
sendchar('\r');
|
sendchar('\r');
|
||||||
|
|
||||||
#ifdef WRITELOCKBITS
|
#ifdef WRITELOCKBITS
|
||||||
|
94
makefile
94
makefile
@ -39,15 +39,27 @@
|
|||||||
# MCU name
|
# MCU name
|
||||||
## MCU = atmega8
|
## MCU = atmega8
|
||||||
## MCU = atmega16
|
## MCU = atmega16
|
||||||
MCU = atmega32
|
## MCU = atmega162
|
||||||
|
## MCU = atmega169
|
||||||
|
## MCU = atmega32
|
||||||
|
MCU = atmega324p
|
||||||
|
## MCU = atmega644
|
||||||
|
## MCU = atmega644p
|
||||||
## MCU = atmega128
|
## MCU = atmega128
|
||||||
## MCU = at90can128
|
## MCU = at90can128
|
||||||
|
|
||||||
|
################## BOOTLOADER ######################
|
||||||
|
# mt: Boot loader support. So far not done with a separate section
|
||||||
|
# to get the interrupt vector into the bootloader area (for BOOTINTVEC=yes).
|
||||||
|
# Bootloader address in datasheet and stk500 is given as
|
||||||
|
# "word", gcc toolchain needs "byte"-address
|
||||||
|
# (see LDFLAGS further down)
|
||||||
|
|
||||||
#/* Select Boot Size in Words (select one, comment out the others) */
|
#/* Select Boot Size in Words (select one, comment out the others) */
|
||||||
## NO! BOOTSIZE=128
|
## NO! BOOTSIZE=128
|
||||||
## NO! BOOTSIZE=256
|
## NO! BOOTSIZE=256
|
||||||
BOOTSIZE=512
|
## BOOTSIZE=512
|
||||||
## BOOTSIZE=1024
|
BOOTSIZE=1024
|
||||||
## BOOTSIZE=2048
|
## BOOTSIZE=2048
|
||||||
|
|
||||||
# /* Select if bootloader should include the inverrupt-vectors
|
# /* Select if bootloader should include the inverrupt-vectors
|
||||||
@ -56,14 +68,6 @@ BOOTSIZE=512
|
|||||||
##BOOTINTVEC=yes
|
##BOOTINTVEC=yes
|
||||||
BOOTINTVEC=no
|
BOOTINTVEC=no
|
||||||
|
|
||||||
|
|
||||||
################## BOOTLOADER ######################
|
|
||||||
# mt: Boot loader support. So far not done with a separate section
|
|
||||||
# to get the interrupt vector into the bootloader area.
|
|
||||||
# Bootloader address in datasheet and stk500 is given as
|
|
||||||
# "word", gcc toolchain needs "byte"-address
|
|
||||||
# (see LDFLAGS further down)
|
|
||||||
|
|
||||||
##
|
##
|
||||||
ifeq ($(MCU), atmega8)
|
ifeq ($(MCU), atmega8)
|
||||||
BFD_MACH=avr4
|
BFD_MACH=avr4
|
||||||
@ -98,6 +102,23 @@ ifeq ($(BOOTSIZE), 1024)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
##
|
||||||
|
ifeq ($(MCU), atmega162)
|
||||||
|
BFD_MACH=avr5
|
||||||
|
ifeq ($(BOOTSIZE), 128)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0x3F00
|
||||||
|
endif
|
||||||
|
ifeq ($(BOOTSIZE), 256)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0x3E00
|
||||||
|
endif
|
||||||
|
ifeq ($(BOOTSIZE), 512)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0x3C00
|
||||||
|
endif
|
||||||
|
ifeq ($(BOOTSIZE), 1024)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0x3800
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
##
|
##
|
||||||
ifeq ($(MCU), atmega169)
|
ifeq ($(MCU), atmega169)
|
||||||
BFD_MACH=avr5
|
BFD_MACH=avr5
|
||||||
@ -132,6 +153,57 @@ ifeq ($(BOOTSIZE), 2048)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
##
|
||||||
|
ifeq ($(MCU), atmega324p)
|
||||||
|
BFD_MACH=avr5
|
||||||
|
ifeq ($(BOOTSIZE), 256)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0x7E00
|
||||||
|
endif
|
||||||
|
ifeq ($(BOOTSIZE), 512)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0x7C00
|
||||||
|
endif
|
||||||
|
ifeq ($(BOOTSIZE), 1024)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0x7800
|
||||||
|
endif
|
||||||
|
ifeq ($(BOOTSIZE), 2048)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0x7000
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
##
|
||||||
|
ifeq ($(MCU), atmega644)
|
||||||
|
BFD_MACH=avr5
|
||||||
|
ifeq ($(BOOTSIZE), 512)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0xFC00
|
||||||
|
endif
|
||||||
|
ifeq ($(BOOTSIZE), 1024)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0xF800
|
||||||
|
endif
|
||||||
|
ifeq ($(BOOTSIZE), 2048)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0xF000
|
||||||
|
endif
|
||||||
|
ifeq ($(BOOTSIZE), 4096)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0xE000
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
##
|
||||||
|
ifeq ($(MCU), atmega644p)
|
||||||
|
BFD_MACH=avr5
|
||||||
|
ifeq ($(BOOTSIZE), 512)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0xFC00
|
||||||
|
endif
|
||||||
|
ifeq ($(BOOTSIZE), 1024)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0xF800
|
||||||
|
endif
|
||||||
|
ifeq ($(BOOTSIZE), 2048)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0xF000
|
||||||
|
endif
|
||||||
|
ifeq ($(BOOTSIZE), 4096)
|
||||||
|
MT_BOOTLOADER_ADDRESS = 0xE000
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
##
|
##
|
||||||
ifeq ($(MCU), atmega128)
|
ifeq ($(MCU), atmega128)
|
||||||
BFD_MACH=avr5
|
BFD_MACH=avr5
|
||||||
|
52
mega162.h
Normal file
52
mega162.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#ifndef _MEGA162_H_
|
||||||
|
#define _MEGA162_H_
|
||||||
|
|
||||||
|
/* Part-Code ISP */
|
||||||
|
// documented code (AVR109 AppNote) but not supported by AVRProg 1.40
|
||||||
|
// #define DEVTYPE_ISP 0x62
|
||||||
|
// fake ATmega16 instead:
|
||||||
|
#define DEVTYPE_ISP 0x74
|
||||||
|
/* Part-Code Boot */
|
||||||
|
// documented code but not supported by AVRProg 1.40
|
||||||
|
// #define DEVTYPE_BOOT 0x63
|
||||||
|
// fake ATmega16:
|
||||||
|
#define DEVTYPE_BOOT 0x75
|
||||||
|
|
||||||
|
#define SIG_BYTE1 0x1E
|
||||||
|
#define SIG_BYTE2 0x94
|
||||||
|
#define SIG_BYTE3 0x04
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef UART_DOUBLESPEED
|
||||||
|
#define UART_CALC_BAUDRATE(baudRate) ((uint32_t)(F_CPU) / ((uint32_t)(baudRate) *8) -1)
|
||||||
|
#else
|
||||||
|
#define UART_CALC_BAUDRATE(baudRate) ((uint32_t)(F_CPU) / ((uint32_t)(baudRate)*16) -1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART_USE_SECOND
|
||||||
|
#define UART_BAUD_HIGH UBRR0H
|
||||||
|
#define UART_BAUD_LOW UBRR0L
|
||||||
|
#define UART_STATUS UCSR0A
|
||||||
|
#define UART_TXREADY UDRE0
|
||||||
|
#define UART_RXREADY RXC0
|
||||||
|
#define UART_DOUBLE U2X0
|
||||||
|
#define UART_CTRL UCSR0B
|
||||||
|
#define UART_CTRL_DATA ((1<<TXEN0) | (1<<RXEN0))
|
||||||
|
#define UART_CTRL2 UCSR0C
|
||||||
|
#define UART_CTRL2_DATA ((1<<URSEL0) | (1<<UCSZ01) | (1<<UCSZ00))
|
||||||
|
#define UART_DATA UDR0
|
||||||
|
#else
|
||||||
|
#define UART_BAUD_HIGH UBRR1H
|
||||||
|
#define UART_BAUD_LOW UBRR1L
|
||||||
|
#define UART_STATUS UCSR1A
|
||||||
|
#define UART_TXREADY UDRE1
|
||||||
|
#define UART_RXREADY RXC1
|
||||||
|
#define UART_DOUBLE U2X1
|
||||||
|
#define UART_CTRL UCSR1B
|
||||||
|
#define UART_CTRL_DATA ((1<<TXEN1) | (1<<RXEN1))
|
||||||
|
#define UART_CTRL2 UCSR1C
|
||||||
|
#define UART_CTRL2_DATA ( (1<<URSEL1) | (1<<UCSZ11) | (1<<UCSZ10))
|
||||||
|
#define UART_DATA UDR1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef _MEGA162_H_
|
@ -1,7 +1,8 @@
|
|||||||
#ifndef _MEGA169_H_
|
#ifndef _MEGA169_H_
|
||||||
#define _MEGA169_H_
|
#define _MEGA169_H_
|
||||||
|
|
||||||
#define DEVTYPE 0x79
|
#define DEVTYPE_ISP 0x78
|
||||||
|
#define DEVTYPE_BOOT 0x79
|
||||||
|
|
||||||
#define SIG_BYTE3 0x1E
|
#define SIG_BYTE3 0x1E
|
||||||
#define SIG_BYTE2 0x94
|
#define SIG_BYTE2 0x94
|
||||||
|
17
mega324p.h
Normal file
17
mega324p.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef _MEGA324P_H_
|
||||||
|
#define _MEGA324P_H_
|
||||||
|
|
||||||
|
/* I (M. Thomas) could not find an official Boot-ID
|
||||||
|
for the ATmega324P so pretend it's an ATmega32 */
|
||||||
|
/* Part-Code ISP */
|
||||||
|
#define DEVTYPE_ISP 0x72
|
||||||
|
/* Part-Code Boot */
|
||||||
|
#define DEVTYPE_BOOT 0x73
|
||||||
|
|
||||||
|
#define SIG_BYTE1 0x1E
|
||||||
|
#define SIG_BYTE2 0x95
|
||||||
|
#define SIG_BYTE3 0x08
|
||||||
|
|
||||||
|
#include "megaxx4p.h"
|
||||||
|
|
||||||
|
#endif // #ifndef _MEGA324P_H_
|
49
mega644.h
Normal file
49
mega644.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef _MEGA644_H_
|
||||||
|
#define _MEGA644_H_
|
||||||
|
|
||||||
|
/* I (M. Thomas) could not find an official Boot-ID
|
||||||
|
for the ATmega644 so pretend it's an ATmega64 */
|
||||||
|
/* Part-Code ISP */
|
||||||
|
#define DEVTYPE_ISP 0x45
|
||||||
|
/* Part-Code Boot */
|
||||||
|
#define DEVTYPE_BOOT 0x46
|
||||||
|
|
||||||
|
#define SIG_BYTE1 0x1E
|
||||||
|
#define SIG_BYTE2 0x96
|
||||||
|
#define SIG_BYTE3 0x09
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef UART_DOUBLESPEED
|
||||||
|
#define UART_CALC_BAUDRATE(baudRate) ((uint32_t)(F_CPU) / ((uint32_t)(baudRate) *8) -1)
|
||||||
|
#else
|
||||||
|
#define UART_CALC_BAUDRATE(baudRate) ((uint32_t)(F_CPU) / ((uint32_t)(baudRate)*16) -1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define UART_BAUD_HIGH UBRR0H
|
||||||
|
#define UART_BAUD_LOW UBRR0L
|
||||||
|
#define UART_STATUS UCSR0A
|
||||||
|
#define UART_TXREADY UDRE0
|
||||||
|
#define UART_RXREADY RXC0
|
||||||
|
#define UART_DOUBLE U2X0
|
||||||
|
#define UART_CTRL UCSR0B
|
||||||
|
#define UART_CTRL_DATA ((1<<TXEN0) | (1<<RXEN0))
|
||||||
|
#define UART_CTRL2 UCSR0C
|
||||||
|
#define UART_CTRL2_DATA ( (1<<UCSZ01) | (1<<UCSZ00))
|
||||||
|
#define UART_DATA UDR0
|
||||||
|
|
||||||
|
#define WDT_OFF_SPECIAL
|
||||||
|
static inline void bootloader_wdt_off(void)
|
||||||
|
{
|
||||||
|
cli();
|
||||||
|
wdt_reset();
|
||||||
|
/* Clear WDRF in MCUSR */
|
||||||
|
MCUSR &= ~(1<<WDRF);
|
||||||
|
/* Write logical one to WDCE and WDE */
|
||||||
|
/* Keep old prescaler setting to prevent unintentional time-out */
|
||||||
|
WDTCSR |= (1<<WDCE) | (1<<WDE);
|
||||||
|
/* Turn off WDT */
|
||||||
|
WDTCSR = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // #ifndef _MEGA644_H_
|
17
mega644p.h
Normal file
17
mega644p.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef _MEGA644P_H_
|
||||||
|
#define _MEGA644P_H_
|
||||||
|
|
||||||
|
/* I (M. Thomas) could not find an official Boot-ID
|
||||||
|
for the ATmega644P so pretend it's an ATmega64 */
|
||||||
|
/* Part-Code ISP */
|
||||||
|
#define DEVTYPE_ISP 0x45
|
||||||
|
/* Part-Code Boot */
|
||||||
|
#define DEVTYPE_BOOT 0x46
|
||||||
|
|
||||||
|
#define SIG_BYTE1 0x1E
|
||||||
|
#define SIG_BYTE2 0x96
|
||||||
|
#define SIG_BYTE3 0x0A
|
||||||
|
|
||||||
|
#include "megaxx4p.h"
|
||||||
|
|
||||||
|
#endif // #ifndef _MEGA644P_H_
|
53
megaxx4p.h
Normal file
53
megaxx4p.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#ifndef _MEGAxx4_H_
|
||||||
|
#define _MEGAxx4_H_
|
||||||
|
|
||||||
|
#ifdef UART_DOUBLESPEED
|
||||||
|
#define UART_CALC_BAUDRATE(baudRate) ((uint32_t)(F_CPU) / ((uint32_t)(baudRate) *8) -1)
|
||||||
|
#else
|
||||||
|
#define UART_CALC_BAUDRATE(baudRate) ((uint32_t)(F_CPU) / ((uint32_t)(baudRate)*16) -1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UART_USE_SECOND
|
||||||
|
/* UART 0 */
|
||||||
|
#define UART_BAUD_HIGH UBRR0H
|
||||||
|
#define UART_BAUD_LOW UBRR0L
|
||||||
|
#define UART_STATUS UCSR0A
|
||||||
|
#define UART_TXREADY UDRE0
|
||||||
|
#define UART_RXREADY RXC0
|
||||||
|
#define UART_DOUBLE U2X0
|
||||||
|
#define UART_CTRL UCSR0B
|
||||||
|
#define UART_CTRL_DATA ((1<<TXEN0) | (1<<RXEN0))
|
||||||
|
#define UART_CTRL2 UCSR0C
|
||||||
|
#define UART_CTRL2_DATA ( (1<<UCSZ01) | (1<<UCSZ00))
|
||||||
|
#define UART_DATA UDR0
|
||||||
|
#else
|
||||||
|
/* UART 1 */
|
||||||
|
#define UART_BAUD_HIGH UBRR1H
|
||||||
|
#define UART_BAUD_LOW UBRR1L
|
||||||
|
#define UART_STATUS UCSR1A
|
||||||
|
#define UART_TXREADY UDRE1
|
||||||
|
#define UART_RXREADY RXC1
|
||||||
|
#define UART_DOUBLE U2X1
|
||||||
|
#define UART_CTRL UCSR1B
|
||||||
|
#define UART_CTRL_DATA ((1<<TXEN1) | (1<<RXEN1))
|
||||||
|
#define UART_CTRL2 UCSR1C
|
||||||
|
#define UART_CTRL2_DATA ( (1<<UCSZ11) | (1<<UCSZ10))
|
||||||
|
#define UART_DATA UDR1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define WDT_OFF_SPECIAL
|
||||||
|
|
||||||
|
static inline void bootloader_wdt_off(void)
|
||||||
|
{
|
||||||
|
cli();
|
||||||
|
wdt_reset();
|
||||||
|
/* Clear WDRF in MCUSR */
|
||||||
|
MCUSR &= ~(1<<WDRF);
|
||||||
|
/* Write logical one to WDCE and WDE */
|
||||||
|
/* Keep old prescaler setting to prevent unintentional time-out */
|
||||||
|
WDTCSR |= (1<<WDCE) | (1<<WDE);
|
||||||
|
/* Turn off WDT */
|
||||||
|
WDTCSR = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // #ifndef _MEGA644_H_
|
54
readme.txt
54
readme.txt
@ -30,17 +30,41 @@ Programming-Software (on the "PC-Side"):
|
|||||||
* Installation instructions at the end of this file.
|
* Installation instructions at the end of this file.
|
||||||
|
|
||||||
|
|
||||||
2. Oct. 2006 - Version 0.81
|
12. Apr. 2008 - Version 0.83
|
||||||
|
|
||||||
* Bernhard Roth reported a mistake in the UART-configuration
|
* Added definitions for ATmega644P and ATmega324P
|
||||||
for double-speed. Thanks for the report.
|
* Tested with ATmega324P, gcc 4.2.2, avr-libc 1.4.6
|
||||||
Change in main.c:
|
* Added testapp to verify "exit bootloader" with
|
||||||
UART_STATUS = UART_DOUBLE; -> UART_STATUS = (1<<UART_DOUBLE);
|
watchdog (n.b.: watchdog-disable called early in testapp)
|
||||||
|
|
||||||
|
27. Jan. 2007 - Version 0.82
|
||||||
|
|
||||||
|
* Added definitions for ATmega644.
|
||||||
|
* Using avr-lib's eeprom-functions (old "direct-access"-code
|
||||||
|
has not been compatible with ATmega644).
|
||||||
|
* Watchdog-disable at startup (configurable): avoids problems with
|
||||||
|
repeated login to bootloader. Not needed if the bootloader is
|
||||||
|
never re-entered again between an "exit programming" and
|
||||||
|
a system-reset/power-toogle.
|
||||||
|
* Additional watchdog disable-function for ATmega644.
|
||||||
|
* Made watchdog-enable time at exit-programming a configuration-value
|
||||||
|
(define).
|
||||||
|
* Bootloader read-protection: if enabled the bootloader fakes
|
||||||
|
an empty boot-section (configurable by define)
|
||||||
|
Since more of the avr-libc functions's are used this version
|
||||||
|
should be more portable for other AVRs but the size of the
|
||||||
|
binary increases a little bit.
|
||||||
|
Make sure to disable the watchdog early in the user-application
|
||||||
|
esp. when using a "modern" AVR (i.e. ATmega48/88/168/644/324P/644P).
|
||||||
|
|
||||||
|
3. Dec. 2006 - Version 0.81
|
||||||
|
|
||||||
|
* Added definitions for ATmega162.
|
||||||
|
* Fixed init for double-speed (bitmask). Thanks to Bernhard Roth
|
||||||
|
|
||||||
28. May 2006 - Version 0.8beta3
|
28. May 2006 - Version 0.8beta3
|
||||||
|
|
||||||
* Support discarding of interrupt-vectors which saves some space
|
* Supports discarding of interrupt-vectors which saves some space
|
||||||
if no interrupts are needed in the bootloader. Added option
|
if no interrupts are needed in the bootloader. Added option
|
||||||
in makefile to enable this feature, modified LDFLAGS,
|
in makefile to enable this feature, modified LDFLAGS,
|
||||||
additional code in main.c for a pseudo default_interrupt ISR.
|
additional code in main.c for a pseudo default_interrupt ISR.
|
||||||
@ -71,7 +95,7 @@ Programming-Software (on the "PC-Side"):
|
|||||||
* This bootloader lets the watchdog do a reset when the
|
* This bootloader lets the watchdog do a reset when the
|
||||||
user selects "Exit programmer" (i.e. in AVRProg) after an
|
user selects "Exit programmer" (i.e. in AVRProg) after an
|
||||||
update. Make sure to disable or reset the watchdog early in
|
update. Make sure to disable or reset the watchdog early in
|
||||||
you application.
|
your application.
|
||||||
|
|
||||||
27. May 2006 - Version 0.8beta2
|
27. May 2006 - Version 0.8beta2
|
||||||
|
|
||||||
@ -198,9 +222,10 @@ not enabled (TODO).
|
|||||||
|
|
||||||
- Program the "Boot Flash section size" (BOOTSZ fuses)
|
- Program the "Boot Flash section size" (BOOTSZ fuses)
|
||||||
according to the boot-size selected in the makefile
|
according to the boot-size selected in the makefile
|
||||||
i.e. BOOTSZ=00 for boot-size 1024 words on ATmega16
|
i.e. BOOTSZ=00 for boot-size 1024 words (2048 bytes)
|
||||||
|
on ATmega16
|
||||||
|
|
||||||
- enable the BOOT Reset Vector fuse (BOOTTRST=0)
|
- enable the BOOT Reset Vector fuse (BOOTRST=0)
|
||||||
|
|
||||||
- Set the lock bits to protect the bootloader from
|
- Set the lock bits to protect the bootloader from
|
||||||
SPM-writes (Boot Loader Protection Mode 2 in STK500-
|
SPM-writes (Boot Loader Protection Mode 2 in STK500-
|
||||||
@ -214,13 +239,14 @@ not enabled (TODO).
|
|||||||
The condition must be "true" until you see the
|
The condition must be "true" until you see the
|
||||||
AVRPROG dialog or avrdude connects.
|
AVRPROG dialog or avrdude connects.
|
||||||
|
|
||||||
- Start AVRPROG (AVRStuido/Tools or stand-alone)
|
- Start AVRPROG (AVRStudio/Tools or stand-alone avrprog.exe)
|
||||||
avrdude is supported too, check the avrdude manual
|
AVRDUDE is supported too, check it's manual
|
||||||
for command-line options.
|
for command-line options. Read the text above for
|
||||||
|
information about Device-Types and AVRDUDE
|
||||||
|
|
||||||
- AVRPROG or avrdude should detect the bootloader.
|
- AVRPROG or AVRDUDE should detect the bootloader.
|
||||||
|
|
||||||
- see AVRStudio online-help for more information how
|
- see AVRStudio's online-help for more information how
|
||||||
to use AVRPROG
|
to use AVRPROG
|
||||||
|
|
||||||
- make sure to EXIT from AVRPROG (button) to start
|
- make sure to EXIT from AVRPROG (button) to start
|
||||||
|
619
testapp/Makefile
Normal file
619
testapp/Makefile
Normal file
@ -0,0 +1,619 @@
|
|||||||
|
# Hey Emacs, this is a -*- makefile -*-
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
|
||||||
|
#
|
||||||
|
# Released to the Public Domain
|
||||||
|
#
|
||||||
|
# Additional material for this makefile was written by:
|
||||||
|
# Peter Fleury
|
||||||
|
# Tim Henigan
|
||||||
|
# Colin O'Flynn
|
||||||
|
# Reiner Patommel
|
||||||
|
# Markus Pfaff
|
||||||
|
# Sander Pool
|
||||||
|
# Frederik Rouleau
|
||||||
|
# Carlos Lamas
|
||||||
|
#
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# On command line:
|
||||||
|
#
|
||||||
|
# make all = Make software.
|
||||||
|
#
|
||||||
|
# make clean = Clean out built project files.
|
||||||
|
#
|
||||||
|
# make coff = Convert ELF to AVR COFF.
|
||||||
|
#
|
||||||
|
# make extcoff = Convert ELF to AVR Extended COFF.
|
||||||
|
#
|
||||||
|
# make program = Download the hex file to the device, using avrdude.
|
||||||
|
# Please customize the avrdude settings below first!
|
||||||
|
#
|
||||||
|
# make debug = Start either simulavr or avarice as specified for debugging,
|
||||||
|
# with avr-gdb or avr-insight as the front end for debugging.
|
||||||
|
#
|
||||||
|
# make filename.s = Just compile filename.c into the assembler code only.
|
||||||
|
#
|
||||||
|
# make filename.i = Create a preprocessed source file for use in submitting
|
||||||
|
# bug reports to the GCC project.
|
||||||
|
#
|
||||||
|
# To rebuild project do "make clean" then "make all".
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# MCU name
|
||||||
|
MCU = atmega324p
|
||||||
|
|
||||||
|
|
||||||
|
# Processor frequency.
|
||||||
|
# This will define a symbol, F_CPU, in all source code files equal to the
|
||||||
|
# processor frequency. You can then use this symbol in your source code to
|
||||||
|
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
|
||||||
|
# automatically to create a 32-bit value in your source code.
|
||||||
|
# Typical values are:
|
||||||
|
# F_CPU = 1000000
|
||||||
|
# F_CPU = 1843200
|
||||||
|
# F_CPU = 2000000
|
||||||
|
# F_CPU = 3686400
|
||||||
|
# F_CPU = 4000000
|
||||||
|
# F_CPU = 7372800
|
||||||
|
# F_CPU = 8000000
|
||||||
|
# F_CPU = 11059200
|
||||||
|
# F_CPU = 14745600
|
||||||
|
# F_CPU = 16000000
|
||||||
|
# F_CPU = 18432000
|
||||||
|
# F_CPU = 20000000
|
||||||
|
F_CPU = 3686400
|
||||||
|
|
||||||
|
|
||||||
|
# Output format. (can be srec, ihex, binary)
|
||||||
|
FORMAT = ihex
|
||||||
|
|
||||||
|
|
||||||
|
# Target file name (without extension).
|
||||||
|
TARGET = testapp
|
||||||
|
|
||||||
|
|
||||||
|
# Object files directory
|
||||||
|
# To put object files in current directory, use a dot (.), do NOT make
|
||||||
|
# this an empty or blank macro!
|
||||||
|
OBJDIR = .
|
||||||
|
|
||||||
|
|
||||||
|
# List C source files here. (C dependencies are automatically generated.)
|
||||||
|
SRC = $(TARGET).c
|
||||||
|
|
||||||
|
|
||||||
|
# List C++ source files here. (C dependencies are automatically generated.)
|
||||||
|
CPPSRC =
|
||||||
|
|
||||||
|
|
||||||
|
# List Assembler source files here.
|
||||||
|
# Make them always end in a capital .S. Files ending in a lowercase .s
|
||||||
|
# will not be considered source files but generated files (assembler
|
||||||
|
# output from the compiler), and will be deleted upon "make clean"!
|
||||||
|
# Even though the DOS/Win* filesystem matches both .s and .S the same,
|
||||||
|
# it will preserve the spelling of the filenames, and gcc itself does
|
||||||
|
# care about how the name is spelled on its command-line.
|
||||||
|
ASRC =
|
||||||
|
|
||||||
|
|
||||||
|
# Optimization level, can be [0, 1, 2, 3, s].
|
||||||
|
# 0 = turn off optimization. s = optimize for size.
|
||||||
|
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
|
||||||
|
OPT = s
|
||||||
|
|
||||||
|
|
||||||
|
# Debugging format.
|
||||||
|
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
|
||||||
|
# AVR Studio 4.10 requires dwarf-2.
|
||||||
|
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
|
||||||
|
DEBUG = dwarf-2
|
||||||
|
|
||||||
|
|
||||||
|
# List any extra directories to look for include files here.
|
||||||
|
# Each directory must be seperated by a space.
|
||||||
|
# Use forward slashes for directory separators.
|
||||||
|
# For a directory that has spaces, enclose it in quotes.
|
||||||
|
EXTRAINCDIRS =
|
||||||
|
|
||||||
|
|
||||||
|
# Compiler flag to set the C Standard level.
|
||||||
|
# c89 = "ANSI" C
|
||||||
|
# gnu89 = c89 plus GCC extensions
|
||||||
|
# c99 = ISO C99 standard (not yet fully implemented)
|
||||||
|
# gnu99 = c99 plus GCC extensions
|
||||||
|
CSTANDARD = -std=gnu99
|
||||||
|
|
||||||
|
|
||||||
|
# Place -D or -U options here for C sources
|
||||||
|
CDEFS = -DF_CPU=$(F_CPU)UL
|
||||||
|
|
||||||
|
|
||||||
|
# Place -D or -U options here for ASM sources
|
||||||
|
ADEFS = -DF_CPU=$(F_CPU)
|
||||||
|
|
||||||
|
|
||||||
|
# Place -D or -U options here for C++ sources
|
||||||
|
CPPDEFS = -DF_CPU=$(F_CPU)UL
|
||||||
|
#CPPDEFS += -D__STDC_LIMIT_MACROS
|
||||||
|
#CPPDEFS += -D__STDC_CONSTANT_MACROS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Compiler Options C ----------------
|
||||||
|
# -g*: generate debugging information
|
||||||
|
# -O*: optimization level
|
||||||
|
# -f...: tuning, see GCC manual and avr-libc documentation
|
||||||
|
# -Wall...: warning level
|
||||||
|
# -Wa,...: tell GCC to pass this to the assembler.
|
||||||
|
# -adhlns...: create assembler listing
|
||||||
|
CFLAGS = -g$(DEBUG)
|
||||||
|
CFLAGS += $(CDEFS)
|
||||||
|
CFLAGS += -O$(OPT)
|
||||||
|
CFLAGS += -funsigned-char
|
||||||
|
CFLAGS += -funsigned-bitfields
|
||||||
|
CFLAGS += -fpack-struct
|
||||||
|
CFLAGS += -fshort-enums
|
||||||
|
CFLAGS += -Wall
|
||||||
|
CFLAGS += -Wstrict-prototypes
|
||||||
|
#CFLAGS += -mshort-calls
|
||||||
|
#CFLAGS += -fno-unit-at-a-time
|
||||||
|
#CFLAGS += -Wundef
|
||||||
|
#CFLAGS += -Wunreachable-code
|
||||||
|
#CFLAGS += -Wsign-compare
|
||||||
|
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
|
||||||
|
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||||
|
CFLAGS += $(CSTANDARD)
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Compiler Options C++ ----------------
|
||||||
|
# -g*: generate debugging information
|
||||||
|
# -O*: optimization level
|
||||||
|
# -f...: tuning, see GCC manual and avr-libc documentation
|
||||||
|
# -Wall...: warning level
|
||||||
|
# -Wa,...: tell GCC to pass this to the assembler.
|
||||||
|
# -adhlns...: create assembler listing
|
||||||
|
CPPFLAGS = -g$(DEBUG)
|
||||||
|
CPPFLAGS += $(CPPDEFS)
|
||||||
|
CPPFLAGS += -O$(OPT)
|
||||||
|
CPPFLAGS += -funsigned-char
|
||||||
|
CPPFLAGS += -funsigned-bitfields
|
||||||
|
CPPFLAGS += -fpack-struct
|
||||||
|
CPPFLAGS += -fshort-enums
|
||||||
|
CPPFLAGS += -fno-exceptions
|
||||||
|
CPPFLAGS += -Wall
|
||||||
|
CFLAGS += -Wundef
|
||||||
|
#CPPFLAGS += -mshort-calls
|
||||||
|
#CPPFLAGS += -fno-unit-at-a-time
|
||||||
|
#CPPFLAGS += -Wstrict-prototypes
|
||||||
|
#CPPFLAGS += -Wunreachable-code
|
||||||
|
#CPPFLAGS += -Wsign-compare
|
||||||
|
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
|
||||||
|
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||||
|
#CPPFLAGS += $(CSTANDARD)
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Assembler Options ----------------
|
||||||
|
# -Wa,...: tell GCC to pass this to the assembler.
|
||||||
|
# -adhlns: create listing
|
||||||
|
# -gstabs: have the assembler create line number information; note that
|
||||||
|
# for use in COFF files, additional information about filenames
|
||||||
|
# and function names needs to be present in the assembler source
|
||||||
|
# files -- see avr-libc docs [FIXME: not yet described there]
|
||||||
|
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
|
||||||
|
# dump that will be displayed for a given single line of source input.
|
||||||
|
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Library Options ----------------
|
||||||
|
# Minimalistic printf version
|
||||||
|
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
|
||||||
|
|
||||||
|
# Floating point printf version (requires MATH_LIB = -lm below)
|
||||||
|
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
|
||||||
|
|
||||||
|
# If this is left blank, then it will use the Standard printf version.
|
||||||
|
PRINTF_LIB =
|
||||||
|
#PRINTF_LIB = $(PRINTF_LIB_MIN)
|
||||||
|
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
|
||||||
|
|
||||||
|
|
||||||
|
# Minimalistic scanf version
|
||||||
|
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
|
||||||
|
|
||||||
|
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
|
||||||
|
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
|
||||||
|
|
||||||
|
# If this is left blank, then it will use the Standard scanf version.
|
||||||
|
SCANF_LIB =
|
||||||
|
#SCANF_LIB = $(SCANF_LIB_MIN)
|
||||||
|
#SCANF_LIB = $(SCANF_LIB_FLOAT)
|
||||||
|
|
||||||
|
|
||||||
|
MATH_LIB = -lm
|
||||||
|
|
||||||
|
|
||||||
|
# List any extra directories to look for libraries here.
|
||||||
|
# Each directory must be seperated by a space.
|
||||||
|
# Use forward slashes for directory separators.
|
||||||
|
# For a directory that has spaces, enclose it in quotes.
|
||||||
|
EXTRALIBDIRS =
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- External Memory Options ----------------
|
||||||
|
|
||||||
|
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
|
||||||
|
# used for variables (.data/.bss) and heap (malloc()).
|
||||||
|
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
|
||||||
|
|
||||||
|
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
|
||||||
|
# only used for heap (malloc()).
|
||||||
|
#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
|
||||||
|
|
||||||
|
EXTMEMOPTS =
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Linker Options ----------------
|
||||||
|
# -Wl,...: tell GCC to pass this to linker.
|
||||||
|
# -Map: create map file
|
||||||
|
# --cref: add cross reference to map file
|
||||||
|
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
|
||||||
|
LDFLAGS += $(EXTMEMOPTS)
|
||||||
|
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
|
||||||
|
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
|
||||||
|
#LDFLAGS += -T linker_script.x
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Programming Options (avrdude) ----------------
|
||||||
|
|
||||||
|
# Programming hardware: alf avr910 avrisp bascom bsd
|
||||||
|
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
|
||||||
|
#
|
||||||
|
# Type: avrdude -c ?
|
||||||
|
# to get a full listing.
|
||||||
|
#
|
||||||
|
AVRDUDE_PROGRAMMER = stk500
|
||||||
|
|
||||||
|
# com1 = serial port. Use lpt1 to connect to parallel port.
|
||||||
|
AVRDUDE_PORT = com1 # programmer connected to serial device
|
||||||
|
|
||||||
|
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
|
||||||
|
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
|
||||||
|
|
||||||
|
|
||||||
|
# Uncomment the following if you want avrdude's erase cycle counter.
|
||||||
|
# Note that this counter needs to be initialized first using -Yn,
|
||||||
|
# see avrdude manual.
|
||||||
|
#AVRDUDE_ERASE_COUNTER = -y
|
||||||
|
|
||||||
|
# Uncomment the following if you do /not/ wish a verification to be
|
||||||
|
# performed after programming the device.
|
||||||
|
#AVRDUDE_NO_VERIFY = -V
|
||||||
|
|
||||||
|
# Increase verbosity level. Please use this when submitting bug
|
||||||
|
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
|
||||||
|
# to submit bug reports.
|
||||||
|
#AVRDUDE_VERBOSE = -v -v
|
||||||
|
|
||||||
|
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
|
||||||
|
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
|
||||||
|
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
|
||||||
|
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#---------------- Debugging Options ----------------
|
||||||
|
|
||||||
|
# For simulavr only - target MCU frequency.
|
||||||
|
DEBUG_MFREQ = $(F_CPU)
|
||||||
|
|
||||||
|
# Set the DEBUG_UI to either gdb or insight.
|
||||||
|
# DEBUG_UI = gdb
|
||||||
|
DEBUG_UI = insight
|
||||||
|
|
||||||
|
# Set the debugging back-end to either avarice, simulavr.
|
||||||
|
DEBUG_BACKEND = avarice
|
||||||
|
#DEBUG_BACKEND = simulavr
|
||||||
|
|
||||||
|
# GDB Init Filename.
|
||||||
|
GDBINIT_FILE = __avr_gdbinit
|
||||||
|
|
||||||
|
# When using avarice settings for the JTAG
|
||||||
|
JTAG_DEV = /dev/com1
|
||||||
|
|
||||||
|
# Debugging port used to communicate between GDB / avarice / simulavr.
|
||||||
|
DEBUG_PORT = 4242
|
||||||
|
|
||||||
|
# Debugging host used to communicate between GDB / avarice / simulavr, normally
|
||||||
|
# just set to localhost unless doing some sort of crazy debugging when
|
||||||
|
# avarice is running on a different computer.
|
||||||
|
DEBUG_HOST = localhost
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
# Define programs and commands.
|
||||||
|
SHELL = sh
|
||||||
|
CC = avr-gcc
|
||||||
|
OBJCOPY = avr-objcopy
|
||||||
|
OBJDUMP = avr-objdump
|
||||||
|
SIZE = avr-size
|
||||||
|
AR = avr-ar rcs
|
||||||
|
NM = avr-nm
|
||||||
|
AVRDUDE = avrdude
|
||||||
|
REMOVE = rm -f
|
||||||
|
REMOVEDIR = rm -rf
|
||||||
|
COPY = cp
|
||||||
|
WINSHELL = cmd
|
||||||
|
|
||||||
|
|
||||||
|
# Define Messages
|
||||||
|
# English
|
||||||
|
MSG_ERRORS_NONE = Errors: none
|
||||||
|
MSG_BEGIN = -------- begin --------
|
||||||
|
MSG_END = -------- end --------
|
||||||
|
MSG_SIZE_BEFORE = Size before:
|
||||||
|
MSG_SIZE_AFTER = Size after:
|
||||||
|
MSG_COFF = Converting to AVR COFF:
|
||||||
|
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
|
||||||
|
MSG_FLASH = Creating load file for Flash:
|
||||||
|
MSG_EEPROM = Creating load file for EEPROM:
|
||||||
|
MSG_EXTENDED_LISTING = Creating Extended Listing:
|
||||||
|
MSG_SYMBOL_TABLE = Creating Symbol Table:
|
||||||
|
MSG_LINKING = Linking:
|
||||||
|
MSG_COMPILING = Compiling C:
|
||||||
|
MSG_COMPILING_CPP = Compiling C++:
|
||||||
|
MSG_ASSEMBLING = Assembling:
|
||||||
|
MSG_CLEANING = Cleaning project:
|
||||||
|
MSG_CREATING_LIBRARY = Creating library:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Define all object files.
|
||||||
|
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
|
||||||
|
|
||||||
|
# Define all listing files.
|
||||||
|
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
|
||||||
|
|
||||||
|
|
||||||
|
# Compiler flags to generate dependency files.
|
||||||
|
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
|
||||||
|
|
||||||
|
|
||||||
|
# Combine all necessary flags and optional flags.
|
||||||
|
# Add target processor to flags.
|
||||||
|
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
|
||||||
|
ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
|
||||||
|
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Default target.
|
||||||
|
all: begin gccversion sizebefore build sizeafter end
|
||||||
|
|
||||||
|
# Change the build target to build a HEX file or a library.
|
||||||
|
build: elf hex eep lss sym
|
||||||
|
#build: lib
|
||||||
|
|
||||||
|
|
||||||
|
elf: $(TARGET).elf
|
||||||
|
hex: $(TARGET).hex
|
||||||
|
eep: $(TARGET).eep
|
||||||
|
lss: $(TARGET).lss
|
||||||
|
sym: $(TARGET).sym
|
||||||
|
LIBNAME=lib$(TARGET).a
|
||||||
|
lib: $(LIBNAME)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Eye candy.
|
||||||
|
# AVR Studio 3.x does not check make's exit code but relies on
|
||||||
|
# the following magic strings to be generated by the compile job.
|
||||||
|
begin:
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_BEGIN)
|
||||||
|
|
||||||
|
end:
|
||||||
|
@echo $(MSG_END)
|
||||||
|
@echo
|
||||||
|
|
||||||
|
|
||||||
|
# Display size of file.
|
||||||
|
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
|
||||||
|
ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
|
||||||
|
|
||||||
|
sizebefore:
|
||||||
|
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
|
||||||
|
2>/dev/null; echo; fi
|
||||||
|
|
||||||
|
sizeafter:
|
||||||
|
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
|
||||||
|
2>/dev/null; echo; fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Display compiler version information.
|
||||||
|
gccversion :
|
||||||
|
@$(CC) --version
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Program the device.
|
||||||
|
program: $(TARGET).hex $(TARGET).eep
|
||||||
|
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
|
||||||
|
|
||||||
|
|
||||||
|
# Generate avr-gdb config/init file which does the following:
|
||||||
|
# define the reset signal, load the target file, connect to target, and set
|
||||||
|
# a breakpoint at main().
|
||||||
|
gdb-config:
|
||||||
|
@$(REMOVE) $(GDBINIT_FILE)
|
||||||
|
@echo define reset >> $(GDBINIT_FILE)
|
||||||
|
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
|
||||||
|
@echo end >> $(GDBINIT_FILE)
|
||||||
|
@echo file $(TARGET).elf >> $(GDBINIT_FILE)
|
||||||
|
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
|
||||||
|
ifeq ($(DEBUG_BACKEND),simulavr)
|
||||||
|
@echo load >> $(GDBINIT_FILE)
|
||||||
|
endif
|
||||||
|
@echo break main >> $(GDBINIT_FILE)
|
||||||
|
|
||||||
|
debug: gdb-config $(TARGET).elf
|
||||||
|
ifeq ($(DEBUG_BACKEND), avarice)
|
||||||
|
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
|
||||||
|
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
|
||||||
|
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
|
||||||
|
@$(WINSHELL) /c pause
|
||||||
|
|
||||||
|
else
|
||||||
|
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
|
||||||
|
$(DEBUG_MFREQ) --port $(DEBUG_PORT)
|
||||||
|
endif
|
||||||
|
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
|
||||||
|
COFFCONVERT = $(OBJCOPY) --debugging
|
||||||
|
COFFCONVERT += --change-section-address .data-0x800000
|
||||||
|
COFFCONVERT += --change-section-address .bss-0x800000
|
||||||
|
COFFCONVERT += --change-section-address .noinit-0x800000
|
||||||
|
COFFCONVERT += --change-section-address .eeprom-0x810000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
coff: $(TARGET).elf
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_COFF) $(TARGET).cof
|
||||||
|
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
|
||||||
|
|
||||||
|
|
||||||
|
extcoff: $(TARGET).elf
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
|
||||||
|
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Create final output files (.hex, .eep) from ELF output file.
|
||||||
|
%.hex: %.elf
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_FLASH) $@
|
||||||
|
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
|
||||||
|
|
||||||
|
%.eep: %.elf
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_EEPROM) $@
|
||||||
|
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
||||||
|
--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
|
||||||
|
|
||||||
|
# Create extended listing file from ELF output file.
|
||||||
|
%.lss: %.elf
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_EXTENDED_LISTING) $@
|
||||||
|
$(OBJDUMP) -h -S $< > $@
|
||||||
|
|
||||||
|
# Create a symbol table from ELF output file.
|
||||||
|
%.sym: %.elf
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_SYMBOL_TABLE) $@
|
||||||
|
$(NM) -n $< > $@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Create library from object files.
|
||||||
|
.SECONDARY : $(TARGET).a
|
||||||
|
.PRECIOUS : $(OBJ)
|
||||||
|
%.a: $(OBJ)
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_CREATING_LIBRARY) $@
|
||||||
|
$(AR) $@ $(OBJ)
|
||||||
|
|
||||||
|
|
||||||
|
# Link: create ELF output file from object files.
|
||||||
|
.SECONDARY : $(TARGET).elf
|
||||||
|
.PRECIOUS : $(OBJ)
|
||||||
|
%.elf: $(OBJ)
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_LINKING) $@
|
||||||
|
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
# Compile: create object files from C source files.
|
||||||
|
$(OBJDIR)/%.o : %.c
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_COMPILING) $<
|
||||||
|
$(CC) -c $(ALL_CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Compile: create object files from C++ source files.
|
||||||
|
$(OBJDIR)/%.o : %.cpp
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_COMPILING_CPP) $<
|
||||||
|
$(CC) -c $(ALL_CPPFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Compile: create assembler files from C source files.
|
||||||
|
%.s : %.c
|
||||||
|
$(CC) -S $(ALL_CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Compile: create assembler files from C++ source files.
|
||||||
|
%.s : %.cpp
|
||||||
|
$(CC) -S $(ALL_CPPFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Assemble: create object files from assembler source files.
|
||||||
|
$(OBJDIR)/%.o : %.S
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_ASSEMBLING) $<
|
||||||
|
$(CC) -c $(ALL_ASFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Create preprocessed source for use in sending a bug report.
|
||||||
|
%.i : %.c
|
||||||
|
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Target: clean project.
|
||||||
|
clean: begin clean_list end
|
||||||
|
|
||||||
|
clean_list :
|
||||||
|
@echo
|
||||||
|
@echo $(MSG_CLEANING)
|
||||||
|
$(REMOVE) $(TARGET).hex
|
||||||
|
$(REMOVE) $(TARGET).eep
|
||||||
|
$(REMOVE) $(TARGET).cof
|
||||||
|
$(REMOVE) $(TARGET).elf
|
||||||
|
$(REMOVE) $(TARGET).map
|
||||||
|
$(REMOVE) $(TARGET).sym
|
||||||
|
$(REMOVE) $(TARGET).lss
|
||||||
|
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
|
||||||
|
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
|
||||||
|
$(REMOVE) $(SRC:.c=.s)
|
||||||
|
$(REMOVE) $(SRC:.c=.d)
|
||||||
|
$(REMOVE) $(SRC:.c=.i)
|
||||||
|
$(REMOVEDIR) .dep
|
||||||
|
|
||||||
|
|
||||||
|
# Create object files directory
|
||||||
|
$(shell mkdir $(OBJDIR) 2>/dev/null)
|
||||||
|
|
||||||
|
|
||||||
|
# Include the dependency files.
|
||||||
|
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
||||||
|
|
||||||
|
|
||||||
|
# Listing of phony targets.
|
||||||
|
.PHONY : all begin finish end sizebefore sizeafter gccversion \
|
||||||
|
build elf hex eep lss sym coff extcoff \
|
||||||
|
clean clean_list program debug gdb-config
|
62
testapp/testapp.c
Normal file
62
testapp/testapp.c
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// Martin Thomas 4/2008
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
#define LED_PORT PORTB
|
||||||
|
#define LED_DDR DDRB
|
||||||
|
#define LED_BIT PB2
|
||||||
|
|
||||||
|
#define BT_PORT PORTC
|
||||||
|
#define BT_DDR DDRC
|
||||||
|
#define BT_PIN PINC
|
||||||
|
#define BT_BIT PC7
|
||||||
|
|
||||||
|
static inline void my_wdt_off(void)
|
||||||
|
{
|
||||||
|
cli();
|
||||||
|
wdt_reset();
|
||||||
|
/* Clear WDRF in MCUSR */
|
||||||
|
MCUSR &= ~(1<<WDRF);
|
||||||
|
/* Write logical one to WDCE and WDE */
|
||||||
|
/* Keep old prescaler setting to prevent unintentional time-out */
|
||||||
|
WDTCSR |= (1<<WDCE) | (1<<WDE);
|
||||||
|
/* Turn off WDT */
|
||||||
|
WDTCSR = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void my_delay( void )
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for ( i=0; i<500; i++ ) {
|
||||||
|
_delay_ms(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( void )
|
||||||
|
{
|
||||||
|
my_wdt_off();
|
||||||
|
|
||||||
|
LED_PORT |= ( 1<<LED_BIT );
|
||||||
|
LED_DDR |= ( 1<<LED_BIT );
|
||||||
|
|
||||||
|
BT_DDR &= ~( 1<<BT_BIT );
|
||||||
|
BT_PORT |= ( 1<<BT_BIT );
|
||||||
|
|
||||||
|
while ( 1 ) {
|
||||||
|
LED_PORT &= ~( 1<<LED_BIT );
|
||||||
|
my_delay();
|
||||||
|
LED_PORT |= ( 1<<LED_BIT );
|
||||||
|
my_delay();
|
||||||
|
|
||||||
|
if ( !( BT_PIN & ( 1<<BT_BIT ) ) ) {
|
||||||
|
/* start bootloader */
|
||||||
|
wdt_enable( WDTO_250MS );
|
||||||
|
while (1) { ; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0; /* never reached */
|
||||||
|
}
|
117
testavrdude/dummy.hex
Normal file
117
testavrdude/dummy.hex
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
:103800000C942A1C0C94451C0C94451C0C94451CCF
|
||||||
|
:103810000C94451C0C94451C0C94451C0C94451CA4
|
||||||
|
:103820000C94451C0C94451C0C94451C0C94451C94
|
||||||
|
:103830000C94451C0C94451C0C94451C0C94451C84
|
||||||
|
:103840000C94451C0C94451C0C94451C0C94451C74
|
||||||
|
:103850000C94451C11241FBECFE5D4E0DEBFCDBFC4
|
||||||
|
:1038600010E0A0E6B0E0EEE2FFE302C005900D92AA
|
||||||
|
:10387000A036B107D9F710E0A0E6B0E001C01D9274
|
||||||
|
:10388000A53EB107E1F70C94871D0C94001C8F9A9C
|
||||||
|
:1038900084E083BD89E185BD089581E40E94E21E34
|
||||||
|
:1038A00086E50E94E21E82E50E94E21E82E40E94FA
|
||||||
|
:1038B000E21E8FE40E94E21E8FE40E94E21E84E575
|
||||||
|
:1038C0000E94E21E08958F929F92AF92BF92CF9274
|
||||||
|
:1038D000DF92EF92FF920F931F93CF93DF936C01D0
|
||||||
|
:1038E000962EEE24FF2487010E591F4FE7012196E3
|
||||||
|
:1038F000EC14FD0418F40E94E61E01C08FEFF801DD
|
||||||
|
:1039000080837E01C038D10570F3EE24FF248091BE
|
||||||
|
:10391000E400853721F08B3311F0C7018CC0A090F3
|
||||||
|
:10392000E200B090E300E199FECF8FB6F89426E470
|
||||||
|
:10393000921609F07DC08091E40087010E591F4F57
|
||||||
|
:10394000E7012196EEEFFFEFCE0EDF1E8537F1F493
|
||||||
|
:10395000F8018081282F3327FE01EE59FF4F808127
|
||||||
|
:103960009927982F8827282B392B7E010894E11C52
|
||||||
|
:10397000F11C41E08091E2009091E3000901FC011B
|
||||||
|
:1039800040935700E8951124029628C080E40E94D5
|
||||||
|
:103990004B1F8091E3000E944B1F8091E2000E9428
|
||||||
|
:1039A0004B1FF80180810E944B1F88E40E944B1F2F
|
||||||
|
:1039B0008091E3000E944B1F8091E2000E944B1F08
|
||||||
|
:1039C0007E010894E11CF11CCE59DF4F88810E94D2
|
||||||
|
:1039D0004B1F8091E2009091E30001969093E300E9
|
||||||
|
:1039E0008093E200C114D10409F0A5CF8091E400D6
|
||||||
|
:1039F000853769F485E0F50180935700E89507B6AF
|
||||||
|
:103A000000FCFDCF81E180935700E89511C08CE464
|
||||||
|
:103A10000E944B1F8B2D99270E944B1F8A2D0E94BD
|
||||||
|
:103A20004B1F80E00E944B1F88E893E10E94F51E27
|
||||||
|
:103A30008FBE8DE090E0DF91CF911F910F91FF90AD
|
||||||
|
:103A4000EF90DF90CF90BF90AF909F908F900895B0
|
||||||
|
:103A5000FF920F931F93CF93DF93EC01FFB6F8947F
|
||||||
|
:103A6000E199FECF8091E4008537E9F4653409F4EB
|
||||||
|
:103A700047C060E08091E2009091E3000E94EB1E5D
|
||||||
|
:103A80008C010E94E21E812F99270E94E21E8091E4
|
||||||
|
:103A9000E2009091E30002969093E3008093E200AD
|
||||||
|
:103AA000229739F72DC08B3359F580E20E944B1FC6
|
||||||
|
:103AB0008091E3000E944B1F8091E2000E944B1F07
|
||||||
|
:103AC0008FEF0E944B1F0E94E21E88E20E944B1F54
|
||||||
|
:103AD0008091E3000E944B1F8091E2000E944B1FE7
|
||||||
|
:103AE0008FEF0E944B1F0E94E21E8091E200909196
|
||||||
|
:103AF000E30001969093E3008093E2002297A9F6F9
|
||||||
|
:103B0000FFBEDF91CF911F910F91FF900895CFE5F8
|
||||||
|
:103B1000D4E0DEBFCDBFF89401E005BF82E085BFF1
|
||||||
|
:103B2000A698AE9A60E087E190E00E94D81E9E9B26
|
||||||
|
:103B300008C0AE9805BF15BEE0916000F09161002D
|
||||||
|
:103B40000995BB9AC39A0E94401F0E94471C0E947D
|
||||||
|
:103B5000E61E813611F489E528C18134F9F40E940A
|
||||||
|
:103B6000E61E99279093E3008093E200182F002728
|
||||||
|
:103B70000E94E61E282F3327202B312B3093E300A1
|
||||||
|
:103B80002093E2008091E400853709F083C0220F82
|
||||||
|
:103B9000331F3093E3002093E2007CC0823689F427
|
||||||
|
:103BA00089E50E94E21E8091E400853729F480E0D7
|
||||||
|
:103BB0000E94E21E80E8F9C080E00E94E21E80E4DC
|
||||||
|
:103BC000F4C0823489F40E94E61E9927182F00273A
|
||||||
|
:103BD0000E94E61E9927082B192B0E94E61E682FCB
|
||||||
|
:103BE000C8010E94631CE1C0873689F40E94E61E6A
|
||||||
|
:103BF0009927182F00270E94E61E9927082B192BBA
|
||||||
|
:103C00000E94E61E682FC8010E94281DA0CF85369D
|
||||||
|
:103C1000B1F58091E4008537F9F41092E300109239
|
||||||
|
:103C2000E20043E020E030E0F90140935700E895DE
|
||||||
|
:103C300007B600FCFDCFC90180589F4F9C0158E397
|
||||||
|
:103C40008030950788F39093E3008093E20081E150
|
||||||
|
:103C500080935700E8951EC08B33E1F48CEA0E94F4
|
||||||
|
:103C60004B1F80E80E944B1F80E00E944B1F80E0AA
|
||||||
|
:103C70000E944B1F8CE893E20E94F51E0BC0853416
|
||||||
|
:103C800059F488E190E028E00FB6F894A89581BD3A
|
||||||
|
:103C90000FBE21BD8DE089C0803539F48091E400EC
|
||||||
|
:103CA0008B33C1F70E94511FF5CF8C3439F48091CA
|
||||||
|
:103CB000E4008B3379F70E946D1FECCF803711F44D
|
||||||
|
:103CC00083E573C0823711F48FEF6FC08E3459F4DF
|
||||||
|
:103CD0008091E400853711F488E967C08B3309F0DF
|
||||||
|
:103CE00036CF8EED62C08C3619F40E94E61ED2CF1C
|
||||||
|
:103CF000843741F485E70E94E21E8BE30E94E21EB6
|
||||||
|
:103D000080E053C0883731F40E94E61E823031F4DF
|
||||||
|
:103D1000C398C0CF893721F40E94E61EC39ABACF58
|
||||||
|
:103D2000843529F40E94E61E8093E400B3CF8335E6
|
||||||
|
:103D300019F40E944D1C0BCF863529F480E30E94B4
|
||||||
|
:103D4000E21E87E332C0833711F58091E4008537A6
|
||||||
|
:103D500041F483E00E94E21E84E90E94E21E8EE1AB
|
||||||
|
:103D600024C08B3309F0F3CE03E0015080E30E94BE
|
||||||
|
:103D70004B1F80E00E944B1F802F0E944B1F8FEF34
|
||||||
|
:103D80000E944B1F0E94E21E002379F7E0CE8D3483
|
||||||
|
:103D900041F488B398E0892788BB84E70E94E21E3B
|
||||||
|
:103DA00079CF8B3109F4D3CE8FE30E94E21ECFCEC0
|
||||||
|
:103DB0009C01832F992780BD29B988E18AB986E8BB
|
||||||
|
:103DC00080BD08955D9BFECF8CB908955F9BFECFAB
|
||||||
|
:103DD0008CB199270895FC0160FD60935700C89548
|
||||||
|
:103DE000802DE395C895902D0895CF93DF93CDB79F
|
||||||
|
:103DF000DEB722970FB6F894DEBF0FBECDBF039695
|
||||||
|
:103E000065E070E00E94831F9B0144275527DA017B
|
||||||
|
:103E1000C90163E0880F991FAA1FBB1F6A95D1F7DC
|
||||||
|
:103E2000821B930BA40BB50B9C0119821A8289810A
|
||||||
|
:103E30009A818217930750F489819A810196898328
|
||||||
|
:103E40009A8389819A8182179307B0F322960FB6DD
|
||||||
|
:103E5000F894DEBF0FBECDBFDF91CF910895D89803
|
||||||
|
:103E600088E092E50E94F51E0895D89A88E092E5D0
|
||||||
|
:103E70000E94F51E08950E94351F0E942F1F08956D
|
||||||
|
:103E8000C79A87B3806B87BBD09ABE9883E58DB9FC
|
||||||
|
:103E90000E94351F08958FB9779BFECF8FB1992768
|
||||||
|
:103EA0000895CF93C7980E943B1FC0E08CEA0E9400
|
||||||
|
:103EB0004B1F83E50E944B1F8FEF0E944B1F8335E2
|
||||||
|
:103EC00011F4C1E402C00E943B1F80E00E944B1F1E
|
||||||
|
:103ED000CF5FC03458F3CF9108950E943B1F0E94DA
|
||||||
|
:103EE000351F08950E94511F8CEA0E944B1F80E8E5
|
||||||
|
:103EF0000E944B1F80E00E944B1F80E00E944B1FDE
|
||||||
|
:103F00000E946D1F0895AA1BBB1B51E107C0AA1F89
|
||||||
|
:103F1000BB1FA617B70710F0A61BB70B881F991F6A
|
||||||
|
:0E3F20005A95A9F780959095BC01CD010895A2
|
||||||
|
:0400000300003800C1
|
||||||
|
:00000001FF
|
20
testavrdude/go.cmd
Normal file
20
testavrdude/go.cmd
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
@echo off
|
||||||
|
rem Use avrdude as programming-software with the AVRProg compatible bootloader
|
||||||
|
rem Martin Thomas, 2006
|
||||||
|
|
||||||
|
rem Verfiy that the bootloader is configured with #define DEVTYPE DEVTYPE_ISP
|
||||||
|
rem since it seems that avrdude does not work with "Boot" device-types and needs
|
||||||
|
rem ISP device-types (at least in version 5.1 as in WinAVR 4/06)
|
||||||
|
|
||||||
|
set HEXFILE=cansniffer.hex
|
||||||
|
set PROGRAMMER=avr109
|
||||||
|
set PORT=com2
|
||||||
|
set BAUD=19200
|
||||||
|
set PART=atmega32
|
||||||
|
|
||||||
|
rem * disable safemode - bootloader can not "restore" fuses anyway
|
||||||
|
set DIS_SAVE=-u
|
||||||
|
|
||||||
|
avrdude %DIS_SAVE% -p %PART% -P %PORT% -c %PROGRAMMER% -b %BAUD% -v -U flash:w:%HEXFILE%
|
||||||
|
|
||||||
|
rem pause
|
Loading…
Reference in New Issue
Block a user