1
0
mirror of https://github.com/Optiboot/optiboot.git synced 2025-08-17 21:41:03 +03:00

Makefile now usable.

For example "make -f Makefile.mega0 drazzy3217"
Add LED_INVERT option to makefile option parser.
Clean up RSTPIN for chips with only two values.
Shave off a few bytes by writing PMUX instead of ORing, and using the default clock speed (20MHz/6) instead of turning off the divider.  (not that we need to save space yet.)
Implement something for the "do_spm" function.  This just writes "cmd" to NVMCTREL.CTRLA; I'm not sure whether an application can write to the page buffer to make that sufficient.  Needs testing.
This commit is contained in:
WestfW
2019-09-15 02:22:45 -07:00
parent 74efdb6699
commit c3344d7dfc
4 changed files with 48 additions and 20 deletions

View File

@@ -20,7 +20,8 @@ export
# defaults
MCU_TARGET = atmega4809
AVR_FREQ = 20000000
# default CPU frequency is the internal osc (16 or 20MHz) divided by 6
AVR_FREQ = 3333333
LDSECTIONS = -Wl,--section-start=.text=0 -Wl,--section-start=.postapp=0x200 \
-Wl,--section-start=.version=0x1fe
@@ -28,7 +29,7 @@ BAUD_RATE=115200
# If we have a PACKS directory specified, we should use it...
ifdef PACKS
PACK_OPT= -I $(PACKS)/include/ -B $(PACKS)/gcc/dev/$%
PACK_OPT= -I $(PACKS)/include/ -B $(PACKS)/gcc/dev/$*
endif
GCCROOT =
AVRDUDE_CONF =
@@ -54,7 +55,8 @@ OBJDUMP = $(GCCROOT)avr-objdump
SIZE = $(GCCROOT)avr-size
include parse_options.mk
.PRECIOUS: %.elf
.PRECIOUS: optiboot_%.elf
ifndef PRODUCTION
LISTING= $(OBJDUMP) -S
@@ -88,12 +90,9 @@ optiboot_%.hex: optiboot_%.elf
$(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex $< $@
optiboot_%.elf: optiboot_x.c FORCE
echo CPU_OPTIONS= $(CPU_OPTIONS)
echo LED_OPTIONS= $(LED_OPTIONS)
echo UART_OPTIONS=$(UART_OPTIONS)
$(CC) $(CFLAGS) $(CPU_OPTIONS) $(LED_OPTIONS) $(UART_OPTIONS) $(COMMON_OPTIONS) $(LDFLAGS) $(PACK_OPT) -mmcu=$* -o $@ $<
$(SIZE) $@
$(LISTING) $@ > optiboot_$*.lss
$(LISTING) $@ > optiboot_$*.lst
#---------------------------------------------------------------------------
@@ -105,20 +104,32 @@ optiboot_%.elf: optiboot_x.c FORCE
# appropriate specific options
#---------------------------------------------------------------------------
drazzy412:
$(MAKE) -f $(MF) optiboot_attiny412.hex UARTTX=A1 TIMEOUT=8 LED=A7
drazzy%2:
$(MAKE) -f $(MF) optiboot_attiny$*2.hex UARTTX=A1 TIMEOUT=8 LED=A7
drazzy402:
$(MAKE) -f $(MF) optiboot_attiny402.hex UARTTX=A1 TIMEOUT=8 LED=A7
drazzy%4:
$(MAKE) -f $(MF) optiboot_attiny$*4.hex UARTTX=B2 TIMEOUT=8 LED=A7
xplained416:
$(MAKE) -f $(MF) optiboot_attiny416.hex UARTTX=A1 TIMEOUT=8 LED=B5
drazzy%6:
$(MAKE) -f $(MF) optiboot_attiny$*6.hex UARTTX=B2 TIMEOUT=8 LED=A7
xplained4809:
drazzy%7:
$(MAKE) -f $(MF) optiboot_attiny$*7.hex UARTTX=B2 TIMEOUT=8 LED=A7
curiosity1607:
$(MAKE) -f $(MF) optiboot_attiny1607.hex UARTTX=B2 TIMEOUT=8 LED=B7 LED_INVERT=1
curiosity4809:
$(MAKE) -f $(MF) optiboot_atmega4809.hex UARTTX=B0 TIMEOUT=8 LED=F5 LED_INVERT=1
xplained416:
$(MAKE) -f $(MF) optiboot_attiny416.hex UARTTX=A1 TIMEOUT=8 LED=B5 LED_INVERT=1
xplained4809:
$(MAKE) -f $(MF) optiboot_atmega4809.hex UARTTX=C0 TIMEOUT=8 LED=B5 LED_INVERT=1
freeduino4809:
$(MAKE) -f $(MF) optiboot_atmega4809.hex UARTTX=B4 TIMEOUT=1 LED=D6 RESETPIN=1
freeduino4809chip:
$(MAKE) -f $(MF) optiboot_atmega4809.hex UARTTX=F4 TIMEOUT=1 LED=A7 RESETPIN=1

View File

@@ -149,7 +149,11 @@ FUSES = {
#ifdef RSTPIN
.SYSCFG0 = CRCSRC_NOCRC_gc | RSTPINCFG_RST_gc, /* RESET is enabled */
#else
# ifdef FUSE_RSTPINCFG_gm // group mask will be defined for triple-func pins
.SYSCFG0 = CRCSRC_NOCRC_gc | RSTPINCFG_UPDI_gc, /* RESET is not yet */
# else
.SYSCFG0 = CRCSRC_NOCRC_gc, /* RESET is not yet */
# endif
#endif
.SYSCFG1 = 0x06, /* startup 32ms */
.APPEND = 0, /* Application Code Section End */
@@ -375,12 +379,12 @@ int main (void) {
#endif // Fancy reset cause stuff
watchdogReset();
_PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, 0); // full speed clock
// _PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, 0); // full speed clock
MYUART_TXPORT.DIR |= MYUART_TXPIN; // set TX pin to output
MYUART_TXPORT.OUT |= MYUART_TXPIN; // and "1" as per datasheet
#if defined (MYUART_PMUX)
MYPMUX |= MYUART_PMUX; // alternate pinout to use
MYPMUX = MYUART_PMUX; // alternate pinout to use
#endif
MYUART.BAUD = BAUD_SETTING;
MYUART.DBGCTRL = 1; // run during debug
@@ -614,7 +618,9 @@ void watchdogConfig (uint8_t x) {
*/
static void do_nvmctrl(uint16_t address, uint8_t command, uint16_t data) __attribute__ ((used));
static void do_nvmctrl (uint16_t address, uint8_t command, uint16_t data) {
// Do spm stuff
_PROTECTED_WRITE(WDT.CTRLA, command);
while (NVMCTRL.STATUS & (NVMCTRL_FBUSY_bm|NVMCTRL_EEBUSY_bm))
; // wait for flash and EEPROM not busy, just in case.
}
#endif
@@ -686,6 +692,7 @@ void app()
ch = RSTCTRL.RSTFR;
RSTCTRL.RSTFR = ch; // reset causes
do_nvmctrl(0, NVMCTRL_CMD_PAGEBUFCLR_gc, 0); // reference this function!
__asm__ __volatile__ ("jmp 0"); // similar to running off end of memory
_PROTECTED_WRITE(RSTCTRL.SWRR, 1); // cause new reset
for (long i=0; i < 1000000; i++) {

View File

@@ -80,6 +80,14 @@ endif
dummy = FORCE
endif
HELPTEXT += "Option LED_INVERT=1 - Invert the 'on' state of the LED\n"
ifdef LED_INVERT=1
ifneq ($(LED_INVERT), 0)
LEDINV_CMD = -DLED_INVERT=1
endif
dummy = FORCE
endif
# UART options

View File

@@ -759,15 +759,17 @@
#endif // Tiny402/etc
/*
* 14pin and 20pin Tiny0, Tiny1
* The 14 and 20pin packages both conveniently have the UART on the
* 14, 20, and 24 pin Tiny0, Tiny1
* The 14, 20, and 24pin packages all conveniently have the UART on the
* same port pins, and the same pinmux structure!
*/
#if defined(__AVR_ATtiny1614__) || defined(__AVR_ATtiny1604__) || \
defined(__AVR_ATtiny814__) || defined(__AVR_ATtiny804__) || \
defined(__AVR_ATtiny1606__) || defined(__AVR_ATtiny806__) || \
defined(__AVR_ATtiny406__) || defined(__AVR_ATtiny3216__) || \
defined(__AVR_ATtiny816__) || defined(__AVR_ATtiny416__)
defined(__AVR_ATtiny816__) || defined(__AVR_ATtiny416__) || \
defined(__AVR_ATtiny1617__) || defined(__AVR_ATtiny3217__) || \
defined(__AVR_ATtiny1607__)
#define MYPMUX PORTMUX.CTRLB
# if (UARTTX == B2)
# ifndef USART0