diff --git a/Makefile.32u4 b/Makefile.32u4 new file mode 100644 index 0000000..944e2f2 --- /dev/null +++ b/Makefile.32u4 @@ -0,0 +1,64 @@ +CC=avr-gcc +AS=$(CC) +LD=$(CC) + +include Makefile.inc + +PROGNAME=gcn64usb +OBJDIR=objs-$(PROGNAME) +CPU=atmega32u4 +CFLAGS=-Wall -mmcu=$(CPU) -DF_CPU=16000000L -Os -DUART1_STDOUT -DVERSIONSTR=$(VERSIONSTR) -DVERSIONSTR_SHORT=$(VERSIONSTR_SHORT) -DVERSIONBCD=$(VERSIONBCD) -std=gnu99 +LDFLAGS=-mmcu=$(CPU) -Wl,-Map=$(PROGNAME).map +HEXFILE=$(PROGNAME).hex + +all: $(HEXFILE) + +clean: + rm -f $(PROGNAME).elf $(PROGNAME).hex $(PROGNAME).map $(OBJS) + +gcn64txrx0.o: gcn64txrx.S + $(CC) $(CFLAGS) -c $< -o $@ -DSUFFIX=0 -DGCN64_DATA_BIT=0 + +gcn64txrx1.o: gcn64txrx.S + $(CC) $(CFLAGS) -c $< -o $@ -DSUFFIX=1 -DGCN64_DATA_BIT=2 + +gcn64txrx2.o: gcn64txrx.S + $(CC) $(CFLAGS) -c $< -o $@ -DSUFFIX=2 -DGCN64_DATA_BIT=1 + +gcn64txrx3.o: gcn64txrx.S + $(CC) $(CFLAGS) -c $< -o $@ -DSUFFIX=3 -DGCN64_DATA_BIT=3 + +%.o: %.S + $(CC) $(CFLAGS) -c $< -o $@ + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +%.o: %.c %.h + $(CC) $(CFLAGS) -c $< -o $@ + +$(PROGNAME).elf: $(OBJS) + $(LD) $(OBJS) $(LDFLAGS) -o $(PROGNAME).elf + +$(PROGNAME).hex: $(PROGNAME).elf + avr-objcopy -j .data -j .text -O ihex $(PROGNAME).elf $(PROGNAME).hex + avr-size $(PROGNAME).elf -C --mcu=$(CPU) + +fuse: + +flash: $(HEXFILE) + - ./scripts/enter_bootloader.sh + ./scripts/wait_then_flash.sh $(CPU) $(HEXFILE) + +justflash: $(HEXFILE) + ./scripts/wait_then_flash.sh $(CPU) $(HEXFILE) + +chip_erase: + dfu-programmer $(CPU) erase + +reset: + dfu-programmer $(CPU) reset + +restart: + - ./scripts/enter_bootloader.sh + ./scripts/start.sh $(CPU) diff --git a/README.md b/README.md index ff8d76a..7634fae 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ The project is released under the General Public License version 3. You will need a working avr-gcc toolchain with avr-libc and standard utilities such as make. Just type 'make' and it should build just fine. Under Linux at least. +If you are compiling for a custom board or Arduino running on an ATmega32u4, then run 'make -f Makefile.32u4' instead. ## Programming the firmware diff --git a/bootloader.c b/bootloader.c index 923bbaa..3e4a40c 100644 --- a/bootloader.c +++ b/bootloader.c @@ -26,7 +26,7 @@ void enterBootLoader(void) usb_shutdown(); _delay_ms(10); -#if defined(__AVR_ATmega32U2__) +#if defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega32U4__) // ATmega32u2 : 0x3800 asm volatile( "cli \n" diff --git a/changelog.txt b/changelog.txt index a4c854b..cfef9ce 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,5 @@ - Future ideas / TODO - Add very basic N64 mouse support (detect and treat it like a controller) - - Add support for Atmega32u4 MCU - March 5, 2021 : Version 3.6.1 - Alter timing so the brawler64 wireless gamepad will work. Those will now