port to atmega644 and reconfigure watchdog
This commit is contained in:
parent
8bee3f786f
commit
9e1a9fffc5
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
# microcontroller and project specific settings
|
# microcontroller and project specific settings
|
||||||
TARGET = bootloader
|
TARGET = bootloader
|
||||||
F_CPU = 20000000UL
|
F_CPU = 20000000
|
||||||
MCU = atmega644
|
MCU = atmega644
|
||||||
|
|
||||||
SRC = bootloader.c
|
SRC = bootloader.c
|
||||||
@ -11,7 +11,7 @@ OBJECTS += $(patsubst %.S,%.o,${ASRC})
|
|||||||
HEADERS += $(shell echo *.h)
|
HEADERS += $(shell echo *.h)
|
||||||
# CFLAGS += -Werror
|
# CFLAGS += -Werror
|
||||||
LDFLAGS += -L/usr/local/avr/avr/lib
|
LDFLAGS += -L/usr/local/avr/avr/lib
|
||||||
CFLAGS += -Iusbdrv -I.
|
CFLAGS += -Iusbdrv -I. -Os
|
||||||
CFLAGS += -DHARDWARE_REV=$(HARDWARE_REV)
|
CFLAGS += -DHARDWARE_REV=$(HARDWARE_REV)
|
||||||
ASFLAGS += -x assembler-with-cpp
|
ASFLAGS += -x assembler-with-cpp
|
||||||
ASFLAGS += -Iusbdrv -I.
|
ASFLAGS += -Iusbdrv -I.
|
||||||
@ -37,8 +37,11 @@ else ifeq ($(MCU),atmega88)
|
|||||||
BOOT_SECTION_START = 0x1800
|
BOOT_SECTION_START = 0x1800
|
||||||
else ifeq ($(MCU),atmega644)
|
else ifeq ($(MCU),atmega644)
|
||||||
# atmega88 with 1024 words bootloader:
|
# atmega88 with 1024 words bootloader:
|
||||||
# bootloader section starts at 0x7e00 (word-address) == 0xFC00 (byte-address)
|
# bootloader section starts at 0x7c00 (word-address) == 0xF800 (byte-address)
|
||||||
BOOT_SECTION_START = 0xFC00
|
|
||||||
|
# atmega88 with 2024 words bootloader:
|
||||||
|
# bootloader section starts at 0x7800 (word-address) == 0xF000 (byte-address)
|
||||||
|
BOOT_SECTION_START = 0xf000
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LDFLAGS += -Wl,--section-start=.text=$(BOOT_SECTION_START)
|
LDFLAGS += -Wl,--section-start=.text=$(BOOT_SECTION_START)
|
||||||
@ -54,7 +57,7 @@ all: $(TARGET).hex $(TARGET).lss
|
|||||||
@echo "$(TARGET) compiled for: $(MCU)"
|
@echo "$(TARGET) compiled for: $(MCU)"
|
||||||
@echo -n "size is: "
|
@echo -n "size is: "
|
||||||
@$(SIZE) -A $(TARGET).hex | grep "\.sec1" | tr -s " " | cut -d" " -f2
|
@$(SIZE) -A $(TARGET).hex | grep "\.sec1" | tr -s " " | cut -d" " -f2
|
||||||
@echo "max size:2048 bytes"
|
@echo "max size:4096 bytes"
|
||||||
@echo "==============================="
|
@echo "==============================="
|
||||||
|
|
||||||
$(TARGET): $(OBJECTS) $(TARGET).o
|
$(TARGET): $(OBJECTS) $(TARGET).o
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
# Programmer used for In System Programming
|
# Programmer used for In System Programming
|
||||||
ISP_PROG = usbap
|
ISP_PROG = usbasp
|
||||||
# device the ISP programmer is connected to
|
# device the ISP programmer is connected to
|
||||||
ISP_DEV = /dev/tty.PL2303-00002126
|
ISP_DEV = /dev/tty.PL2303-00002126
|
||||||
# Programmer used for serial programming (using the bootloader)
|
# 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
|
# flags for the compiler
|
||||||
CFLAGS += -g -Os -finline-limit=800 -mmcu=$(MCU) -DF_CPU=$(F_CPU) -std=gnu99
|
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
|
.PHONY: all clean interactive-isp interactive-serial launch-bootloader
|
||||||
|
|
||||||
program-isp-%: %.hex
|
flash: bootloader.hex
|
||||||
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -P $(ISP_DEV) -U flash:w:$<
|
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -U flash:w:$<
|
||||||
|
|
||||||
program-isp-eeprom-%: %.eep.hex
|
program-isp-eeprom-%: %.eep.hex
|
||||||
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -P $(ISP_DEV) -U eeprom:w:$<
|
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -P $(ISP_DEV) -U eeprom:w:$<
|
||||||
|
|||||||
@ -64,8 +64,8 @@
|
|||||||
(LED_DIR &=~ (1 << LED_PIN))); }
|
(LED_DIR &=~ (1 << LED_PIN))); }
|
||||||
#define DLED_OFF {((LED_PORT &=~ (1 << LED_PIN)),\
|
#define DLED_OFF {((LED_PORT &=~ (1 << LED_PIN)),\
|
||||||
(LED_DIR |= (1 << LED_PIN))); }
|
(LED_DIR |= (1 << LED_PIN))); }
|
||||||
#define DLED_TGL {((LED_PORT ^= (1 << LED_PIN)),\
|
#define DLED_TGL {((LED_PORT &=~ (1 << LED_PIN)),\
|
||||||
(LED_DIR |= (1 << LED_PIN)));}
|
(LED_DIR ^= (1 << LED_PIN)));}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -318,8 +318,8 @@ void leave_bootloader(void)
|
|||||||
|
|
||||||
/* disconnect usb */
|
/* disconnect usb */
|
||||||
usbDeviceDisconnect();
|
usbDeviceDisconnect();
|
||||||
for (uint8_t i = 0; i < 38; i++)
|
for (uint8_t i = 0; i < 50; i++)
|
||||||
_delay_loop_2(0); /* 0 means 0x10000, 38*1/f*0x10000 =~ 498ms */
|
_delay_ms(10); /* 0 means 0x10000, 38*1/f*0x10000 =~ 498ms */
|
||||||
|
|
||||||
/* enable watchdog to soft-reset the uC for clean startup of new application */
|
/* enable watchdog to soft-reset the uC for clean startup of new application */
|
||||||
wdt_enable(WDTO_15MS);
|
wdt_enable(WDTO_15MS);
|
||||||
@ -334,36 +334,46 @@ int __attribute__ ((noreturn,OS_main)) main(void)
|
|||||||
{
|
{
|
||||||
/* start bootloader */
|
/* start bootloader */
|
||||||
|
|
||||||
/* init LED-Pin */
|
|
||||||
PORTB = 0;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG_UART
|
#ifdef DEBUG_UART
|
||||||
/* init uart (115200 baud, at 20mhz) */
|
/* init uart (115200 baud, at 20mhz) */
|
||||||
UBRR0L = 10;
|
UBRR0L = 10;
|
||||||
UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
|
UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
|
||||||
UCSR0B = _BV(TXEN0);
|
UCSR0B = _BV(TXEN0);
|
||||||
putc('b');
|
|
||||||
#endif
|
#endif
|
||||||
|
putc('a');
|
||||||
|
|
||||||
|
wdt_disable();
|
||||||
|
|
||||||
uint8_t reset = MCUSR;
|
uint8_t reset = MCUSR;
|
||||||
|
reset=0;
|
||||||
|
uint16_t delay =0;
|
||||||
|
timeout = TIMEOUT;
|
||||||
|
|
||||||
|
|
||||||
/* if power-on reset, quit bootloader via watchdog reset */
|
/* if power-on reset, quit bootloader via watchdog reset */
|
||||||
if (reset & _BV(PORF)){
|
if (reset & _BV(PORF)){
|
||||||
|
putc('p');
|
||||||
MCUSR = 0;
|
MCUSR = 0;
|
||||||
leave_bootloader();
|
leave_bootloader();
|
||||||
}
|
}
|
||||||
/* if watchdog reset, disable watchdog and jump to app */
|
/* if watchdog reset, disable watchdog and jump to app */
|
||||||
else if(reset & _BV(WDRF)){
|
else if(reset & _BV(WDRF)){
|
||||||
|
|
||||||
MCUSR = 0;
|
MCUSR = 0;
|
||||||
|
//WDTCSR |= (1<<WDCE);
|
||||||
|
//WDTCSR &= ~((1<<WDIE) | (1<<WDE));
|
||||||
wdt_disable();
|
wdt_disable();
|
||||||
|
putc('r');
|
||||||
|
while(1);
|
||||||
jump_to_app();
|
jump_to_app();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while(1);
|
||||||
|
|
||||||
/* else: enter programming mode */
|
/* else: enter programming mode */
|
||||||
|
|
||||||
|
putc('u');
|
||||||
|
|
||||||
|
|
||||||
/* clear external reset flags */
|
/* clear external reset flags */
|
||||||
MCUSR = 0;
|
MCUSR = 0;
|
||||||
@ -372,40 +382,45 @@ int __attribute__ ((noreturn,OS_main)) main(void)
|
|||||||
request_exit = 0;
|
request_exit = 0;
|
||||||
|
|
||||||
/* move interrupts to boot section */
|
/* move interrupts to boot section */
|
||||||
|
|
||||||
MCUCR = (1 << IVCE);
|
MCUCR = (1 << IVCE);
|
||||||
MCUCR = (1 << IVSEL);
|
MCUCR = (1 << IVSEL);
|
||||||
|
|
||||||
/* enable interrupts */
|
cli();
|
||||||
sei();
|
|
||||||
|
|
||||||
/* initialize usb pins */
|
/* initialize usb pins */
|
||||||
usbInit();
|
usbInit();
|
||||||
|
|
||||||
/* disconnect for ~500ms, so that the host re-enumerates this device */
|
/* disconnect for ~500ms, so that the host re-enumerates this device */
|
||||||
|
putc('d');
|
||||||
usbDeviceDisconnect();
|
usbDeviceDisconnect();
|
||||||
for (uint8_t i = 0; i < 38; i++)
|
for (uint8_t i = 0; i < 50; i++)
|
||||||
_delay_loop_2(0); /* 0 means 0x10000, 38*1/f*0x10000 =~ 498ms */
|
_delay_ms(10); /* 0 means 0x10000, 38*1/f*0x10000 =~ 498ms */
|
||||||
usbDeviceConnect();
|
usbDeviceConnect();
|
||||||
|
putc('c');
|
||||||
uint16_t delay;
|
|
||||||
timeout = TIMEOUT;
|
/* enable interrupts */
|
||||||
|
sei();
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
//wdt_reset();
|
||||||
usbPoll();
|
usbPoll();
|
||||||
delay++;
|
delay++;
|
||||||
|
|
||||||
/* do some led blinking, so that it is visible that the bootloader is still running */
|
/* do some led blinking, so that it is visible that the bootloader is still running */
|
||||||
if (delay == 0) {
|
if (delay == 0) {
|
||||||
|
putc('p');
|
||||||
DLED_TGL;
|
DLED_TGL;
|
||||||
if (timeout < 255)
|
if (timeout < 255)
|
||||||
timeout--;
|
timeout--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request_exit || timeout == 0) {
|
if (request_exit || timeout == 0) {
|
||||||
_delay_loop_2(0);
|
putc('e');
|
||||||
|
_delay_ms(10);
|
||||||
leave_bootloader();
|
leave_bootloader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
putc('l');
|
||||||
|
|
||||||
leave_bootloader();
|
leave_bootloader();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user