--- /dev/null
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Build",
+ // "request": "launch",
+ "type": "node-terminal",
+ "preLaunchTask": "build"
+ },{
+ "name": "Flash",
+ // "request": "launch",
+ "type": "node-terminal",
+ "preLaunchTask": "flash"
+ },{
+ "name": "Clean",
+ // "request": "launch",
+ "type": "node-terminal",
+ "preLaunchTask": "clean"
+ },{
+ // es muss mit simuc --board arduino dist/programm.elf der Simulator
+ // gestartet werden. Dessen gdb-stub öffnet auf localhost:1234 einen Port
+ "name": "Debug (simuc)",
+ "type": "cppdbg",
+ "request": "launch",
+ "program": "${workspaceFolder}/sim/atmega1284p.elf",
+ "cwd": "${workspaceFolder}",
+ "externalConsole": false,
+ "MIMode": "gdb",
+ "miDebuggerPath": "/usr/bin/avr-gdb",
+ "miDebuggerServerAddress": ":1234",
+ "preLaunchTask": "build"
+ }
+ ]
+}
--- /dev/null
+
+NAME=crumb128-1_at90can128
+DEVICE=at90can128
+AVRDUDE_DEVICE=c128
+#CPU_FREQUENCY=14745600
+CPU_FREQUENCY=16000000
+BAUDRATE=115200
+
+# --------------------------------------------------------------------------------
+
+.PHONY: all info flash picocom clean
+$(shell mkdir -p dist >/dev/null)
+$(shell mkdir -p build >/dev/null)
+$(shell mkdir -p sim >/dev/null)
+$(shell mkdir -p sim/build >/dev/null)
+
+SRC= $(wildcard src/*.c src/*.cpp src/*/*.c src/*/*.cpp)
+HDR= $(wildcard src/*.h src/*.hpp src/*/*.h src/*/*.hpp)
+MAINSRC= $(wildcard src/main.c src/main.cpp)
+OBJ_CPP = $(SRC:src/%.cpp=build/%.o)
+OBJ = $(OBJ_CPP:src/%.c=build/%.o)
+OBJ_SIM_CPP = $(SRC:src/%.cpp=sim/build/%.o)
+OBJ_SIM = $(OBJ_SIM_CPP:src/%.c=sim/build/%.o)
+
+CCP= avr-g++
+CC= avr-gcc
+
+CFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCE) -c
+CFLAGS +=
+LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCE)
+#LFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm
+
+CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCE) -g -c
+CFLAGS +=
+LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCE) -g
+#LFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm
+
+# --------------------------------------------------------------------------------
+# make targets
+
+all: dist/$(NAME).elf dist/$(NAME).s dist/$(NAME).hex sim/$(NAME).elf sim/$(NAME).s info
+
+info:
+ @echo
+ @avr-size --mcu=$(DEVICE) --format=avr dist/$(NAME).elf
+
+# --------------------------------------------------------------------------------
+# dependency make for hierarchical source file structure
+
+.depend: $(SRC) $(HDR)
+ $(CC) -mmcu=$(DEVICE) -MM $(SRC) | sed --regexp-extended 's/^(.*\.o)\: src\/(.*)(\.cpp|\.c) (.*)/build\/\2\.o\: src\/\2\3 \4/g' > .depend
+
+ifneq (clean,$(filter clean,$(MAKECMDGOALS)))
+-include .depend
+endif
+
+# --------------------------------------------------------------------------------
+# elf, hex and assembler file creation
+
+dist/$(NAME).elf: .depend $(OBJ)
+ $(CC) $(LFLAGS) -o $@ $(OBJ)
+
+dist/%.hex: dist/%.elf
+ avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
+
+dist/%.s: dist/%.elf
+ avr-objdump -d $< > $@
+
+# --------------------------------------------------------------------------------
+# check if the macros __DATE__ or __TIME__ are used in src/main.cpp or src/main.c
+
+DATE_USED=
+ifneq ($(shell cat $(MAINSRC) | grep __DATE__),)
+ DATE_USED=true
+endif
+TIME_USED=
+ifneq ($(shell cat $(MAINSRC) | grep __TIME__),)
+ TIME_USED=true
+endif
+
+ifeq (true, $(filter true, $(DATE_USED) $(TIME_USED)))
+build/main.o: $(MAIN_SRC) $(SRC) $(HDR)
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) -o $@ $<
+endif
+
+# --------------------------------------------------------------------------------
+
+build/%.o: src/%.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) -o $@ $<
+
+build/%.o: src/%.cpp
+ @mkdir -p $(dir $@)
+ $(CCP) $(CFLAGS) -o $@ $<
+
+# --------------------------------------------------------------------------------
+# simulation/debugging with gdb or simuc
+
+sim/$(NAME).elf: .depend $(OBJ_SIM)
+ $(CC) $(LFLAGS_SIM) -o $@ $(OBJ_SIM)
+ @ln -sf $(NAME).elf sim/$(DEVICE).elf
+
+sim/build/%.o: src/%.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS_SIM) -o $@ $<
+
+sim/build/%.o: src/%.cpp
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS_SIM) -o $@ $<
+
+sim/%.s: sim/%.elf
+ avr-objdump -d $< > $@
+
+ifeq (m16, $(AVRDUDE_DEVICE))
+simuc: sim/$(NAME).elf
+ simuc --board sure $<
+endif
+
+ifeq (m328p, $(AVRDUDE_DEVICE))
+simuc: sim/$(NAME).elf
+ simuc --board arduino $<
+endif
+
+ifeq (m644p, $(AVRDUDE_DEVICE))
+simuc: sim/$(NAME).elf
+ simuc --board nano-644 $<
+endif
+
+ifeq (m1284p, $(AVRDUDE_DEVICE))
+simuc: sim/$(NAME).elf
+ simuc --board nano-1284 $<
+endif
+
+ifeq (c128, $(AVRDUDE_DEVICE))
+simuc: sim/$(NAME).elf
+ simuc --board crumb-128 $<
+endif
+
+gdb: sim/$(NAME).elf
+ avr-gdb $<
+
+# -------------------------------------------------------------
+# flash to target with arduino bootloader in bootloader-section
+
+flash: dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB0 -b $(BAUDRATE) -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash0: dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB0 -b $(BAUDRATE) -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash1: dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB1 -b $(BAUDRATE) -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash2: dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB2 -b $(BAUDRATE) -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash-read:
+ avrdude -c arduino -P /dev/ttyUSB0 -b $(BAUDRATE) -p $(AVRDUDE_DEVICE) -U flash:r:/tmp/flash.bin
+
+flash-disassemble: flash-read
+ avr-objdump -b binary -D -m avr5 /tmp/flash.bin > /tmp/flash.s
+ less /tmp/flash.s
+
+flash-hexdump: flash-read
+ hexdump -C /tmp/flash.bin | less
+
+# ----------------------------------------------
+# flash to target with fischl programming device
+
+isp-flash:
+ avrdude -c usbasp -p $(AVRDUDE_DEVICE) -U lock:r:-:h
+ avrdude -c usbasp -p $(AVRDUDE_DEVICE)
+
+isp-flash-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c usbasp -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+isp-read-flash-$(AVRDUDE_DEVICE):
+ avrdude -c usbasp -p m32$(AVRDUDE_DEVICE)8p -U flash:r:/tmp/flash-arduino-atmega328p__$(shell date +"%Y-%m-%d_%H%M%S")
+
+ifeq (m16, $(AVRDUDE_DEVICE))
+isp-fuse-$(AVRDUDE_DEVICE):
+ avrdude -c usbasp -p $(AVRDUDE_DEVICE) -U lfuse:w:0x18:m -U hfuse:w:0xD8:m -U lock:w:0xEF:m
+endif
+ifeq (m328p, $(AVRDUDE_DEVICE))
+isp-fuse-$(AVRDUDE_DEVICE):
+ avrdude -c usbasp -p $(AVRDUDE_DEVICE) -U lfuse:w:0xEF:m -U hfuse:w:0xD8:m -U efuse:w:0xFD:m -U lock:w:0xEF:m
+endif
+ifeq (m644p, $(AVRDUDE_DEVICE))
+isp-fuse-$(AVRDUDE_DEVICE):
+ avrdude -c usbasp -p $(AVRDUDE_DEVICE) -U lfuse:w:0xEF:m -U hfuse:w:0xD8:m -U efuse:w:0xFD:m -U lock:w:0xEF:m
+endif
+ifeq (m1284p, $(AVRDUDE_DEVICE))
+isp-fuse-$(AVRDUDE_DEVICE):
+ avrdude -c usbasp -p $(AVRDUDE_DEVICE) -U lfuse:w:0xEF:m -U hfuse:w:0xD8:m -U efuse:w:0xFD:m -U lock:w:0xEF:m
+endif
+ifeq (c128, $(AVRDUDE_DEVICE))
+isp-fuse-$(AVRDUDE_DEVICE):
+ avrdude -c usbasp -p $(AVRDUDE_DEVICE) -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xF1:m -U lock:w:0xFF:m
+endif
+
+
+# --------------------------------------------------------
+# picocom sends CR for ENTER -> convert cr (\r) to lf (\n)
+
+picocom:
+ picocom -b $(BAUDRATE) --omap crlf --raise-dtr /dev/ttyUSB0
+
+picocom0:
+ picocom -b $(BAUDRATE) --omap crlf --raise-dtr /dev/ttyUSB0
+
+picocom1:
+ picocom -b $(BAUDRATE) --omap crlf --raise-dtr /dev/ttyUSB1
+
+picocom2:
+ picocom -b $(BAUDRATE) --omap crlf --raise-dtr /dev/ttyUSB2
+
+# --------------------------------------------------------
+
+help:
+ @echo
+ @echo "Possible targets are:"
+ @echo " clean"
+ @echo " all help info"
+ @echo " flash flash0 flash1 flash2 flash-read flash-disassemble flash-hexdump"
+ @echo " isp-$(AVRDUDE_DEVICE) isp-flash-$(AVRDUDE_DEVICE) isp-fuse-$(AVRDUDE_DEVICE)"
+ @echo " picocom picocom0 picocom1 picocom2"
+ @echo " gdb simuc"
+ @echo
+
+# --------------------------------------------------------
+
+clean:
+ @rm -r dist
+ @rm -r build
+ @rm -r sim
+ @find . -type f -name ".depend" -exec rm {} \;
+ @echo "clean done"