From 9f983148328bbd40d8057f95802f211c96045283 Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Sun, 12 Oct 2014 11:13:30 +0200 Subject: [PATCH] add new hardware --- Makefile | 20 +++++-- ispprog.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 154 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 8685c62..938ffc6 100644 --- a/Makefile +++ b/Makefile @@ -7,24 +7,34 @@ SIZE := avr-size TARGET = ispprog SOURCE = $(wildcard *.c) -# select MCU -MCU = atmega16 +#CONFIG = ispprog +CONFIG = ispprog2 AVRDUDE_PROG := -c butterfly -b 19200 -P /dev/ttyUSB0 #AVRDUDE_PROG := -c dragon_isp -P usb # --------------------------------------------------------------------------- -ifeq ($(MCU), atmega16) -# (ext. crystal) +ifeq ($(CONFIG), ispprog) +# (7.3728MHz ext. crystal) AVRDUDE_MCU=m16 AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xda:m + +MCU=atmega16 +endif + +ifeq ($(CONFIG), ispprog2) +# (8MHz int. osc, 2.7V BOD) +AVRDUDE_MCU=m328p -F +AVRDUDE_FUSES=lfuse:w:0xe2:m hfuse:w:0xdc:m efuse:w:0x02:m + +MCU = atmega328p endif # --------------------------------------------------------------------------- CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections -CFLAGS += -Wa,-adhlns=$(*F).lst +CFLAGS += -Wa,-adhlns=$(*F).lst -DCONFIG_$(CONFIG)=1 LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections # --------------------------------------------------------------------------- diff --git a/ispprog.c b/ispprog.c index 8ae5048..b370c51 100644 --- a/ispprog.c +++ b/ispprog.c @@ -27,12 +27,13 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x)) +/* *********************************************************************** */ +#if defined(CONFIG_ispprog) /* * using ATmega16 @7.3728MHz: * Fuse H: 0xDA (512 words bootloader, jtag disabled) * Fuse L: 0xFF (ext. Crystal) */ - #define F_CPU 7372800 #define BAUDRATE 115200 #define TIMER_RELOAD (0xFF - 72) /* 10ms @7.3728MHz */ @@ -44,6 +45,72 @@ #define ISP_SCK PORTB7 /* to target */ #define RESET_IN PORTD3 /* high active */ +#define ISP_INACTIVE() { /* ISP_SCK, ISP_MOSI and ISP_RESET are inputs */ \ + DDRB &= ~((1< #define UART_CALC_BAUDRATE(baudRate) (((uint32_t)F_CPU) / (((uint32_t)baudRate)*16) -1) @@ -255,8 +322,13 @@ static void nvram_start_write(void) uint16_t crc = 0x0000; uint8_t *tmp = (uint8_t *)&nvram_data; +#if defined(__AVR_ATmega16__) if (EECR & (1<>8) & 0xFF; UBRRL = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF); @@ -1022,6 +1131,15 @@ int main(void) /* enable usart with 8n1 */ UCSRB = (1<>8) & 0xFF; + UBRR0L = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF); + + /* enable usart with 8n1 */ + UCSR0B = (1<