From 9e1a9fffc5f6a15d0ceb3214d9f8e109481f2863 Mon Sep 17 00:00:00 2001 From: David Voswinkel Date: Mon, 20 Jul 2009 23:12:01 +0200 Subject: [PATCH] port to atmega644 and reconfigure watchdog --- avr/bootloader/Makefile | 13 +++++---- avr/bootloader/avr.mk | 8 +++--- avr/bootloader/bootloader.c | 53 ++++++++++++++++++++++++------------- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/avr/bootloader/Makefile b/avr/bootloader/Makefile index 3953158..ec188a2 100644 --- a/avr/bootloader/Makefile +++ b/avr/bootloader/Makefile @@ -1,7 +1,7 @@ # microcontroller and project specific settings TARGET = bootloader -F_CPU = 20000000UL +F_CPU = 20000000 MCU = atmega644 SRC = bootloader.c @@ -11,7 +11,7 @@ OBJECTS += $(patsubst %.S,%.o,${ASRC}) HEADERS += $(shell echo *.h) # CFLAGS += -Werror LDFLAGS += -L/usr/local/avr/avr/lib -CFLAGS += -Iusbdrv -I. +CFLAGS += -Iusbdrv -I. -Os CFLAGS += -DHARDWARE_REV=$(HARDWARE_REV) ASFLAGS += -x assembler-with-cpp ASFLAGS += -Iusbdrv -I. @@ -37,8 +37,11 @@ else ifeq ($(MCU),atmega88) BOOT_SECTION_START = 0x1800 else ifeq ($(MCU),atmega644) # atmega88 with 1024 words bootloader: - # bootloader section starts at 0x7e00 (word-address) == 0xFC00 (byte-address) - BOOT_SECTION_START = 0xFC00 + # bootloader section starts at 0x7c00 (word-address) == 0xF800 (byte-address) + + # atmega88 with 2024 words bootloader: + # bootloader section starts at 0x7800 (word-address) == 0xF000 (byte-address) + BOOT_SECTION_START = 0xf000 endif LDFLAGS += -Wl,--section-start=.text=$(BOOT_SECTION_START) @@ -54,7 +57,7 @@ all: $(TARGET).hex $(TARGET).lss @echo "$(TARGET) compiled for: $(MCU)" @echo -n "size is: " @$(SIZE) -A $(TARGET).hex | grep "\.sec1" | tr -s " " | cut -d" " -f2 - @echo "max size:2048 bytes" + @echo "max size:4096 bytes" @echo "===============================" $(TARGET): $(OBJECTS) $(TARGET).o diff --git a/avr/bootloader/avr.mk b/avr/bootloader/avr.mk index 4413d66..de2aec8 100644 --- a/avr/bootloader/avr.mk +++ b/avr/bootloader/avr.mk @@ -1,5 +1,5 @@ # Programmer used for In System Programming -ISP_PROG = usbap +ISP_PROG = usbasp # device the ISP programmer is connected to ISP_DEV = /dev/tty.PL2303-00002126 # Programmer used for serial programming (using the bootloader) @@ -39,7 +39,7 @@ endif -AVRDUDE_FLAGS += -p $(AVRDUDE_MCU) -b $(AVRDUDE_BAUDRATE) +AVRDUDE_FLAGS += -p $(AVRDUDE_MCU) # flags for the compiler CFLAGS += -g -Os -finline-limit=800 -mmcu=$(MCU) -DF_CPU=$(F_CPU) -std=gnu99 @@ -76,8 +76,8 @@ interactive-serial: .PHONY: all clean interactive-isp interactive-serial launch-bootloader -program-isp-%: %.hex - $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -P $(ISP_DEV) -U flash:w:$< +flash: bootloader.hex + $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -U flash:w:$< program-isp-eeprom-%: %.eep.hex $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -P $(ISP_DEV) -U eeprom:w:$< diff --git a/avr/bootloader/bootloader.c b/avr/bootloader/bootloader.c index 7372b94..949b2cd 100644 --- a/avr/bootloader/bootloader.c +++ b/avr/bootloader/bootloader.c @@ -64,8 +64,8 @@ (LED_DIR &=~ (1 << LED_PIN))); } #define DLED_OFF {((LED_PORT &=~ (1 << LED_PIN)),\ (LED_DIR |= (1 << LED_PIN))); } -#define DLED_TGL {((LED_PORT ^= (1 << LED_PIN)),\ - (LED_DIR |= (1 << LED_PIN)));} +#define DLED_TGL {((LED_PORT &=~ (1 << LED_PIN)),\ + (LED_DIR ^= (1 << LED_PIN)));} @@ -318,8 +318,8 @@ void leave_bootloader(void) /* disconnect usb */ usbDeviceDisconnect(); - for (uint8_t i = 0; i < 38; i++) - _delay_loop_2(0); /* 0 means 0x10000, 38*1/f*0x10000 =~ 498ms */ + for (uint8_t i = 0; i < 50; i++) + _delay_ms(10); /* 0 means 0x10000, 38*1/f*0x10000 =~ 498ms */ /* enable watchdog to soft-reset the uC for clean startup of new application */ wdt_enable(WDTO_15MS); @@ -334,36 +334,46 @@ int __attribute__ ((noreturn,OS_main)) main(void) { /* start bootloader */ - /* init LED-Pin */ - PORTB = 0; - #ifdef DEBUG_UART /* init uart (115200 baud, at 20mhz) */ UBRR0L = 10; UCSR0C = _BV(UCSZ00) | _BV(UCSZ01); UCSR0B = _BV(TXEN0); - putc('b'); #endif + putc('a'); + wdt_disable(); + uint8_t reset = MCUSR; + reset=0; + uint16_t delay =0; + timeout = TIMEOUT; + /* if power-on reset, quit bootloader via watchdog reset */ if (reset & _BV(PORF)){ + putc('p'); MCUSR = 0; leave_bootloader(); } /* if watchdog reset, disable watchdog and jump to app */ else if(reset & _BV(WDRF)){ + MCUSR = 0; + //WDTCSR |= (1<