diff --git a/README.md b/README.md index da8ca9f..340f243 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ The following microcontrollers can be used: ATtiny204, 214, 404, 414, 804, 814, ## If using the makefile (Linux/Mac) - Connect your [programmer](https://github.com/wagiminator/AVR-Programmer) to your PC and to the UPDI header on the board. Make sure the programmer works with 3.3V. -- Download [AVR 8-bit Toolchain](https://www.microchip.com/mplab/avr-support/avr-and-arm-toolchains-c-compilers) and extract the sub-folders (avr, bin, include, ...) to /software/tools/avr-gcc. To do this, you have to register for free with Microchip on the download site. +- Make sure you have installed the latest [avr-gcc toolchain](http://maxembedded.com/2015/06/setting-up-avr-gcc-toolchain-on-linux-and-mac-os-x/). - Open a terminal. - Navigate to the folder with the makefile and the sketch. - Run `DEVICE=attiny814 PROGRMR=serialupdi PORT=/dev/ttyUSB0 make install` to compile, burn the fuses and upload the firmware (change DEVICE, PROGRMR and PORT accordingly). diff --git a/software/tools/dfp/include/avr/iotn1604.h b/software/include/avr/iotn1604.h similarity index 100% rename from software/tools/dfp/include/avr/iotn1604.h rename to software/include/avr/iotn1604.h diff --git a/software/tools/dfp/include/avr/iotn1614.h b/software/include/avr/iotn1614.h similarity index 100% rename from software/tools/dfp/include/avr/iotn1614.h rename to software/include/avr/iotn1614.h diff --git a/software/tools/dfp/include/avr/iotn204.h b/software/include/avr/iotn204.h similarity index 100% rename from software/tools/dfp/include/avr/iotn204.h rename to software/include/avr/iotn204.h diff --git a/software/tools/dfp/include/avr/iotn214.h b/software/include/avr/iotn214.h similarity index 100% rename from software/tools/dfp/include/avr/iotn214.h rename to software/include/avr/iotn214.h diff --git a/software/tools/dfp/include/avr/iotn404.h b/software/include/avr/iotn404.h similarity index 100% rename from software/tools/dfp/include/avr/iotn404.h rename to software/include/avr/iotn404.h diff --git a/software/tools/dfp/include/avr/iotn414.h b/software/include/avr/iotn414.h similarity index 100% rename from software/tools/dfp/include/avr/iotn414.h rename to software/include/avr/iotn414.h diff --git a/software/tools/dfp/include/avr/iotn804.h b/software/include/avr/iotn804.h similarity index 100% rename from software/tools/dfp/include/avr/iotn804.h rename to software/include/avr/iotn804.h diff --git a/software/tools/dfp/include/avr/iotn814.h b/software/include/avr/iotn814.h similarity index 100% rename from software/tools/dfp/include/avr/iotn814.h rename to software/include/avr/iotn814.h diff --git a/software/tools/dfp/include/component-version.h b/software/include/component-version.h similarity index 100% rename from software/tools/dfp/include/component-version.h rename to software/include/component-version.h diff --git a/software/tools/dfp/gcc/dev/attiny1604/avrxmega3/crtattiny1604.o b/software/include/dev/attiny1604/avrxmega3/crtattiny1604.o similarity index 100% rename from software/tools/dfp/gcc/dev/attiny1604/avrxmega3/crtattiny1604.o rename to software/include/dev/attiny1604/avrxmega3/crtattiny1604.o diff --git a/software/tools/dfp/gcc/dev/attiny1604/avrxmega3/libattiny1604.a b/software/include/dev/attiny1604/avrxmega3/libattiny1604.a similarity index 100% rename from software/tools/dfp/gcc/dev/attiny1604/avrxmega3/libattiny1604.a rename to software/include/dev/attiny1604/avrxmega3/libattiny1604.a diff --git a/software/tools/dfp/gcc/dev/attiny1604/device-specs/specs-attiny1604 b/software/include/dev/attiny1604/device-specs/specs-attiny1604 similarity index 100% rename from software/tools/dfp/gcc/dev/attiny1604/device-specs/specs-attiny1604 rename to software/include/dev/attiny1604/device-specs/specs-attiny1604 diff --git a/software/tools/dfp/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o b/software/include/dev/attiny1614/avrxmega3/crtattiny1614.o similarity index 100% rename from software/tools/dfp/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o rename to software/include/dev/attiny1614/avrxmega3/crtattiny1614.o diff --git a/software/tools/dfp/gcc/dev/attiny1614/avrxmega3/libattiny1614.a b/software/include/dev/attiny1614/avrxmega3/libattiny1614.a similarity index 100% rename from software/tools/dfp/gcc/dev/attiny1614/avrxmega3/libattiny1614.a rename to software/include/dev/attiny1614/avrxmega3/libattiny1614.a diff --git a/software/tools/dfp/gcc/dev/attiny1614/device-specs/specs-attiny1614 b/software/include/dev/attiny1614/device-specs/specs-attiny1614 similarity index 100% rename from software/tools/dfp/gcc/dev/attiny1614/device-specs/specs-attiny1614 rename to software/include/dev/attiny1614/device-specs/specs-attiny1614 diff --git a/software/tools/dfp/gcc/dev/attiny204/avrxmega3/short-calls/crtattiny204.o b/software/include/dev/attiny204/avrxmega3/short-calls/crtattiny204.o similarity index 100% rename from software/tools/dfp/gcc/dev/attiny204/avrxmega3/short-calls/crtattiny204.o rename to software/include/dev/attiny204/avrxmega3/short-calls/crtattiny204.o diff --git a/software/tools/dfp/gcc/dev/attiny204/avrxmega3/short-calls/libattiny204.a b/software/include/dev/attiny204/avrxmega3/short-calls/libattiny204.a similarity index 100% rename from software/tools/dfp/gcc/dev/attiny204/avrxmega3/short-calls/libattiny204.a rename to software/include/dev/attiny204/avrxmega3/short-calls/libattiny204.a diff --git a/software/tools/dfp/gcc/dev/attiny204/device-specs/specs-attiny204 b/software/include/dev/attiny204/device-specs/specs-attiny204 similarity index 100% rename from software/tools/dfp/gcc/dev/attiny204/device-specs/specs-attiny204 rename to software/include/dev/attiny204/device-specs/specs-attiny204 diff --git a/software/tools/dfp/gcc/dev/attiny214/avrxmega3/short-calls/crtattiny214.o b/software/include/dev/attiny214/avrxmega3/short-calls/crtattiny214.o similarity index 100% rename from software/tools/dfp/gcc/dev/attiny214/avrxmega3/short-calls/crtattiny214.o rename to software/include/dev/attiny214/avrxmega3/short-calls/crtattiny214.o diff --git a/software/tools/dfp/gcc/dev/attiny214/avrxmega3/short-calls/libattiny214.a b/software/include/dev/attiny214/avrxmega3/short-calls/libattiny214.a similarity index 100% rename from software/tools/dfp/gcc/dev/attiny214/avrxmega3/short-calls/libattiny214.a rename to software/include/dev/attiny214/avrxmega3/short-calls/libattiny214.a diff --git a/software/tools/dfp/gcc/dev/attiny214/device-specs/specs-attiny214 b/software/include/dev/attiny214/device-specs/specs-attiny214 similarity index 100% rename from software/tools/dfp/gcc/dev/attiny214/device-specs/specs-attiny214 rename to software/include/dev/attiny214/device-specs/specs-attiny214 diff --git a/software/tools/dfp/gcc/dev/attiny404/avrxmega3/short-calls/crtattiny404.o b/software/include/dev/attiny404/avrxmega3/short-calls/crtattiny404.o similarity index 100% rename from software/tools/dfp/gcc/dev/attiny404/avrxmega3/short-calls/crtattiny404.o rename to software/include/dev/attiny404/avrxmega3/short-calls/crtattiny404.o diff --git a/software/tools/dfp/gcc/dev/attiny404/avrxmega3/short-calls/libattiny404.a b/software/include/dev/attiny404/avrxmega3/short-calls/libattiny404.a similarity index 100% rename from software/tools/dfp/gcc/dev/attiny404/avrxmega3/short-calls/libattiny404.a rename to software/include/dev/attiny404/avrxmega3/short-calls/libattiny404.a diff --git a/software/tools/dfp/gcc/dev/attiny404/device-specs/specs-attiny404 b/software/include/dev/attiny404/device-specs/specs-attiny404 similarity index 100% rename from software/tools/dfp/gcc/dev/attiny404/device-specs/specs-attiny404 rename to software/include/dev/attiny404/device-specs/specs-attiny404 diff --git a/software/tools/dfp/gcc/dev/attiny414/avrxmega3/short-calls/crtattiny414.o b/software/include/dev/attiny414/avrxmega3/short-calls/crtattiny414.o similarity index 100% rename from software/tools/dfp/gcc/dev/attiny414/avrxmega3/short-calls/crtattiny414.o rename to software/include/dev/attiny414/avrxmega3/short-calls/crtattiny414.o diff --git a/software/tools/dfp/gcc/dev/attiny414/avrxmega3/short-calls/libattiny414.a b/software/include/dev/attiny414/avrxmega3/short-calls/libattiny414.a similarity index 100% rename from software/tools/dfp/gcc/dev/attiny414/avrxmega3/short-calls/libattiny414.a rename to software/include/dev/attiny414/avrxmega3/short-calls/libattiny414.a diff --git a/software/tools/dfp/gcc/dev/attiny414/device-specs/specs-attiny414 b/software/include/dev/attiny414/device-specs/specs-attiny414 similarity index 100% rename from software/tools/dfp/gcc/dev/attiny414/device-specs/specs-attiny414 rename to software/include/dev/attiny414/device-specs/specs-attiny414 diff --git a/software/tools/dfp/gcc/dev/attiny804/avrxmega3/short-calls/crtattiny804.o b/software/include/dev/attiny804/avrxmega3/short-calls/crtattiny804.o similarity index 100% rename from software/tools/dfp/gcc/dev/attiny804/avrxmega3/short-calls/crtattiny804.o rename to software/include/dev/attiny804/avrxmega3/short-calls/crtattiny804.o diff --git a/software/tools/dfp/gcc/dev/attiny804/avrxmega3/short-calls/libattiny804.a b/software/include/dev/attiny804/avrxmega3/short-calls/libattiny804.a similarity index 100% rename from software/tools/dfp/gcc/dev/attiny804/avrxmega3/short-calls/libattiny804.a rename to software/include/dev/attiny804/avrxmega3/short-calls/libattiny804.a diff --git a/software/tools/dfp/gcc/dev/attiny804/device-specs/specs-attiny804 b/software/include/dev/attiny804/device-specs/specs-attiny804 similarity index 100% rename from software/tools/dfp/gcc/dev/attiny804/device-specs/specs-attiny804 rename to software/include/dev/attiny804/device-specs/specs-attiny804 diff --git a/software/tools/dfp/gcc/dev/attiny814/avrxmega3/short-calls/crtattiny814.o b/software/include/dev/attiny814/avrxmega3/short-calls/crtattiny814.o similarity index 100% rename from software/tools/dfp/gcc/dev/attiny814/avrxmega3/short-calls/crtattiny814.o rename to software/include/dev/attiny814/avrxmega3/short-calls/crtattiny814.o diff --git a/software/tools/dfp/gcc/dev/attiny814/avrxmega3/short-calls/libattiny814.a b/software/include/dev/attiny814/avrxmega3/short-calls/libattiny814.a similarity index 100% rename from software/tools/dfp/gcc/dev/attiny814/avrxmega3/short-calls/libattiny814.a rename to software/include/dev/attiny814/avrxmega3/short-calls/libattiny814.a diff --git a/software/tools/dfp/gcc/dev/attiny814/device-specs/specs-attiny814 b/software/include/dev/attiny814/device-specs/specs-attiny814 similarity index 100% rename from software/tools/dfp/gcc/dev/attiny814/device-specs/specs-attiny814 rename to software/include/dev/attiny814/device-specs/specs-attiny814 diff --git a/software/makefile b/software/makefile index 56cc3d5..0dbf9c3 100755 --- a/software/makefile +++ b/software/makefile @@ -1,18 +1,17 @@ +# =================================================================================== # Project: USB PD Adapter # Author: Stefan Wagner # Year: 2022 # URL: https://github.com/wagiminator -# -# Download AVR 8-bit Toolchain: -# https://www.microchip.com/mplab/avr-support/avr-and-arm-toolchains-c-compilers -# and extract to ./tools/avr-gcc +# =================================================================================== # Type "make help" in the command line. +# =================================================================================== # Input and Output File Names SKETCH = USB_PD_Adapter.ino TARGET = usb_pd_adapter -# Microcontroller Options +# Microcontroller Settings DEVICE ?= attiny814 CLOCK = 1000000 FUSE0 = 0x00 @@ -24,27 +23,27 @@ FUSE6 = 0x04 FUSE7 = 0x00 FUSE8 = 0x00 -# Programmer Options (serialupdi or jtag2updi) +# Programmer Settings PROGRMR ?= serialupdi PORT ?= /dev/ttyUSB0 -# Paths -GCCPATH = ./tools/avr-gcc -DFPPATH = ./tools/dfp -PYMPATH = ./tools/pymcuprog -ADCPATH = ./tools/avrdude +# Toolchain +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +AVRSIZE = avr-size +PYPROG = python3 -u ./tools/pymcuprog/prog.py -t uart -u $(PORT) -b 230400 -d $(DEVICE) +AVRDUDE = avrdude -C ./tools/avrdude/avrdude.conf -c $(PROGRMR) -P $(PORT) -p $(DEVICE) +CLEAN = rm -f *.lst *.obj *.cof *.list *.map *.eep.hex *.o *.s *.d -# Commands -DFPINCL = -B $(DFPPATH)/gcc/dev/$(DEVICE)/ -I $(DFPPATH)/include/ -COMPILE = $(GCCPATH)/bin/avr-gcc $(DFPINCL) -flto -Wall -Os -mmcu=$(DEVICE) -DF_CPU=$(CLOCK)UL -x c++ $(SKETCH) -PYPROG = python3 -u $(PYMPATH)/prog.py -t uart -u $(PORT) -b 230400 -d $(DEVICE) -AVRDUDE = avrdude -C $(ADCPATH)/avrdude.conf -c jtag2updi -P $(PORT) -p $(DEVICE) -CLEAN = rm -f *.lst *.obj *.cof *.list *.map *.eep.hex *.o *.s *.d +# Compiler Flags +CFLAGS = -w -flto -Os -mmcu=$(DEVICE) -DF_CPU=$(CLOCK) -x c++ +CFLAGS += -B include/dev/$(DEVICE) -I include # Symbolic Targets help: @echo "Use the following commands:" - @echo "make all compile and build $(TARGET).bin/.hex/.asm for $(DEVICE)" + @echo "make all compile and build $(TARGET).elf/.bin/.hex/.asm for $(DEVICE)" @echo "make hex compile and build $(TARGET).hex for $(DEVICE)" @echo "make asm compile and disassemble to $(TARGET).asm for $(DEVICE)" @echo "make bin compile and build $(TARGET).bin for $(DEVICE)" @@ -53,22 +52,32 @@ help: @echo "make install compile, upload and burn fuses for $(DEVICE)" @echo "make clean remove all build files" -all: buildbin buildhex buildasm removetemp size +all: buildelf buildbin buildhex buildasm removetemp size -bin: buildbin removetemp size +elf: buildelf removetemp size -hex: buildbin buildhex removetemp size removebin +bin: buildelf buildbin removetemp size removeelf -asm: buildbin buildasm removetemp size removebin +hex: buildelf buildhex removetemp size removeelf -install: fuses upload +asm: buildelf buildasm removetemp size removeelf -upload: hex - @echo "Uploading to $(DEVICE) ..." +flash: install + +install: hex + @echo "Installing $(TARGET).hex to $(DEVICE) using $(PROGRMR) ..." ifeq ($(PROGRMR),serialupdi) - @$(PYPROG) --fuses 2:$(FUSE2) 6:$(FUSE6) 8:$(FUSE8) -f $(TARGET).hex -a write + @$(PYPROG) --fuses 0:$(FUSE0) 1:$(FUSE1) 2:$(FUSE2) 4:$(FUSE4) 5:$(FUSE5) 6:$(FUSE6) 7:$(FUSE7) 8:$(FUSE8) -f $(TARGET).hex -a write else - @$(AVRDUDE) -U fuse2:w:$(FUSE2):m -U fuse6:w:$(FUSE6):m -U fuse8:w:$(FUSE8):m -U flash:w:$(TARGET).hex:i + @$(AVRDUDE) -Ufuse0:w:$(FUSE0):m -Ufuse1:w:$(FUSE1):m -Ufuse2:w:$(FUSE2):m -Ufuse4:w:$(FUSE4):m -Ufuse5:w:$(FUSE5):m -Ufuse6:w:$(FUSE6):m -Ufuse7:w:$(FUSE7):m -Ufuse8:w:$(FUSE8):m -U flash:w:$(TARGET).hex:i +endif + +upload: hex + @echo "Uploading $(TARGET).hex to $(DEVICE) using $(PROGRMR) ..." +ifeq ($(PROGRMR),serialupdi) + @$(PYPROG) -f $(TARGET).hex -a write +else + @$(AVRDUDE) -U flash:w:$(TARGET).hex:i endif fuses: @@ -82,28 +91,34 @@ endif clean: @echo "Cleaning all up ..." @$(CLEAN) - @rm -f $(TARGET).bin $(TARGET).hex $(TARGET).asm + @rm -f $(TARGET).elf $(TARGET).bin $(TARGET).hex $(TARGET).asm + +buildelf: + @echo "Compiling $(SKETCH) for $(DEVICE) @ $(CLOCK)Hz ..." + @$(CC) $(CFLAGS) $(SKETCH) -o $(TARGET).elf buildbin: - @echo "Building $(TARGET).bin for $(DEVICE) @ $(CLOCK)Hz ..." - @$(COMPILE) -o $(TARGET).bin + @echo "Building $(TARGET).bin ..." + @$(OBJCOPY) -O binary -R .eeprom $(TARGET).elf $(TARGET).bin buildhex: @echo "Building $(TARGET).hex ..." - @$(GCCPATH)/bin/avr-objcopy -O ihex -R .eeprom $(TARGET).bin $(TARGET).hex + @$(OBJCOPY) -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex buildasm: @echo "Disassembling to $(TARGET).asm ..." - @$(GCCPATH)/bin/avr-objdump -d $(TARGET).bin > $(TARGET).asm + @$(OBJDUMP) -d $(TARGET).elf > $(TARGET).asm size: - @echo "FLASH: $(shell $(GCCPATH)/bin/avr-size -d $(TARGET).bin | awk '/[0-9]/ {print $$1 + $$2}') bytes" - @echo "SRAM: $(shell $(GCCPATH)/bin/avr-size -d $(TARGET).bin | awk '/[0-9]/ {print $$2 + $$3}') bytes" + @echo "------------------" + @echo "FLASH: $(shell $(AVRSIZE) -d $(TARGET).elf | awk '/[0-9]/ {print $$1 + $$2}') bytes" + @echo "SRAM: $(shell $(AVRSIZE) -d $(TARGET).elf | awk '/[0-9]/ {print $$2 + $$3}') bytes" + @echo "------------------" removetemp: @echo "Removing temporary files ..." @$(CLEAN) -removebin: - @echo "Removing $(TARGET).bin ..." - @rm -f $(TARGET).bin +removeelf: + @echo "Removing $(TARGET).elf ..." + @rm -f $(TARGET).elf diff --git a/software/tools/avr-gcc/download.txt b/software/tools/avr-gcc/download.txt deleted file mode 100644 index efa5d96..0000000 --- a/software/tools/avr-gcc/download.txt +++ /dev/null @@ -1,4 +0,0 @@ -Download AVR 8-bit Toolchain: -https://www.microchip.com/mplab/avr-support/avr-and-arm-toolchains-c-compilers -To do this, you have to register for free with Microchip on the site. -Extract the sub-folders (avr, bin, include, ...) here. diff --git a/software/tools/dfp/readme.txt b/software/tools/dfp/readme.txt deleted file mode 100644 index cb4fc98..0000000 --- a/software/tools/dfp/readme.txt +++ /dev/null @@ -1,17 +0,0 @@ -Description: Atmel ATtiny Series Device Support (1.10.348) - -Source: http://packs.download.atmel.com/ - -Copyright (c) 2020 Microchip Technology Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the Licence at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License.