--- /dev/null
+MIT License
+
+Copyright (c) 2024 Manfred Steiner (sx@htl-kaindorf.at)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
--- /dev/null
+# Programmvorlagen
+
+## Downloads
+
+* Leeres AVR C/C++ Projekt für VSCode:
+ * [Arduino Nano/Uno](https://git.htl-mechatronik.at/public/?p=project-template.git;a=download;f=vscode-avr-c-cpp/arduino-nano-1;hb=HEAD)
+ * [Nano-1284](https://git.htl-mechatronik.at/public/?p=project-template.git;a=download;f=vscode-avr-c-cpp/nano-1284-1;hb=HEAD)
+ * [Nano-644](https://git.htl-mechatronik.at/public/?p=project-template.git;a=download;f=vscode-avr-c-cpp/nano-644-1;hb=HEAD)
+ * [Sure Board](https://git.htl-mechatronik.at/public/?p=project-template.git;a=download;f=vscode-avr-c-cpp/sure-1;hb=HEAD)
+
+-------------------------------
+
+## Projektverzeichnisse
+
+* Level-1: Leeres AVR C/C++ Projekt für VSCode:
+ * [Arduino Nano/Uno](https://git.htl-mechatronik.at/public/?p=project-template.git;a=tree;f=vscode-avr-c-cpp/arduino-nano-1;hb=HEAD)
+ * [Nano-1284](https://git.htl-mechatronik.at/public/?p=project-template.git;a=tree;f=vscode-avr-c-cpp/nano-1284-1;hb=HEAD)
+ * [Nano-644](https://git.htl-mechatronik.at/public/?p=project-template.git;a=tree;f=vscode-avr-c-cpp/nano-644-1;hb=HEAD)
+ * [Sure Board](https://git.htl-mechatronik.at/public/?p=project-template.git;a=tree;f=vscode-avr-c-cpp/sure-1;hb=HEAD)
+
+
+
+
--- /dev/null
+target remote :1234
+layout split
+stepi
+quit
+target remote :1234
+layout split
+stepi
+b *main+9
+quit
--- /dev/null
+.depend
+**/build
+**/dist
+**/sim
--- /dev/null
+{
+ "configurations": [
+ {
+ "name": "Linux AVR",
+ "includePath": [
+ "/usr/lib/avr/include/**",
+ "/usr/lib/gcc/avr/**"
+ ],
+ "defines": [],
+ "compilerPath": "/usr/bin/avr-gcc",
+ "compilerArgs": [ "-mmcu=atmega328p", "-DF_CPU=16000000", "-Os" ],
+ "cStandard": "gnu11",
+ "cppStandard": "gnu++11",
+ "intelliSenseMode": "linux-gcc-x64"
+ }
+ ],
+ "version": 4
+}
--- /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/atmega328p.elf",
+ "cwd": "${workspaceFolder}",
+ "externalConsole": false,
+ "MIMode": "gdb",
+ "miDebuggerPath": "/usr/bin/avr-gdb",
+ "miDebuggerServerAddress": ":1234",
+ "preLaunchTask": "build"
+ }
+ ]
+}
--- /dev/null
+{
+ "[c]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "[cpp]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "[h]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "[hpp]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "cSpell.words": [],
+ "cSpell.ignorePaths": [
+ "**/*.json", "**/*.c", "**/*.h", "**/*.cpp", "**/*.hpp", "**/Makefile"
+ ]
+}
--- /dev/null
+{
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
+ // for the documentation about the tasks.json format
+ "version": "2.0.0",
+ "tasks": [{
+ "label": "build",
+ "type": "shell",
+ "command": "make",
+ "problemMatcher":[
+ "$gcc"
+ ]
+ },{
+ "label": "clean",
+ "type": "shell",
+ "command": "make",
+ "args": [ "clean" ],
+ },{
+ "label": "flash",
+ "type": "shell",
+ "command": "make",
+ "args": [ "flash" ],
+ }]
+}
\ No newline at end of file
--- /dev/null
+
+NAME=arduino-nano-1_atmega328p
+DEVICE= atmega328p
+AVRDUDE_DEVICE= m328p
+CPU_FREQUENCE= 16000000
+
+# --------------------------------------------------------------------------------
+
+.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)
+
+CC= avr-g++
+
+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 $@)
+ $(CC) $(CFLAGS) -o $@ $<
+
+# --------------------------------------------------------------------------------
+# simulation/debugging with gdb or simuc
+
+sim/$(NAME).elf: .depend $(OBJ_SIM)
+ $(CC) $(LFLAGS_SIM) -o $@ $(OBJ_SIM)
+ @ln -s $(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
+
+gdb: sim/$(NAME).elf
+ avr-gdb $<
+
+# -------------------------------------------------------------
+# flash to target with arduino bootloader in bootloader-section
+
+flash-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB0 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash0-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB0 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash1-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB1 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash2-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB2 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+# ----------------------------------------------
+# flash to target with fischl programming device
+
+isp-$(AVRDUDE_DEVICE):
+ 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
+
+# --------------------------------------------------------
+# picocom sends CR for ENTER -> convert cr (\r) to lf (\n)
+
+picocom:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB0
+
+picocom0:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB0
+
+picocom1:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB1
+
+picocom2:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB2
+
+# --------------------------------------------------------
+
+help:
+ @echo
+ @echo "Possible targets are:"
+ @echo " clean"
+ @echo " all help info"
+ @echo " flash-$(AVRDUDE_DEVICE) flash0-$(AVRDUDE_DEVICE) flash1-$(AVRDUDE_DEVICE) flash2-$(AVRDUDE_DEVICE)"
+ @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"
--- /dev/null
+# Programmvorlage Arduino Nano/Uno
--- /dev/null
+
+int main () {
+ return 0;
+}
+
--- /dev/null
+target remote :1234
+layout split
+stepi
+quit
+target remote :1234
+layout split
+stepi
+b *main+9
+quit
--- /dev/null
+.depend
+**/build
+**/dist
+**/sim
--- /dev/null
+{
+ "configurations": [
+ {
+ "name": "Linux AVR",
+ "includePath": [
+ "/usr/lib/avr/include/**",
+ "/usr/lib/gcc/avr/**"
+ ],
+ "defines": [],
+ "compilerPath": "/usr/bin/avr-gcc",
+ "compilerArgs": [ "-mmcu=atmega1284p", "-DF_CPU=12000000", "-Os" ],
+ "cStandard": "gnu11",
+ "cppStandard": "gnu++11",
+ "intelliSenseMode": "linux-gcc-x64"
+ }
+ ],
+ "version": 4
+}
--- /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
+{
+ "[c]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "[cpp]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "[h]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "[hpp]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "cSpell.words": [],
+ "cSpell.ignorePaths": [
+ "**/*.json", "**/*.c", "**/*.h", "**/*.cpp", "**/*.hpp", "**/Makefile"
+ ]
+}
--- /dev/null
+{
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
+ // for the documentation about the tasks.json format
+ "version": "2.0.0",
+ "tasks": [{
+ "label": "build",
+ "type": "shell",
+ "command": "make",
+ "problemMatcher":[
+ "$gcc"
+ ]
+ },{
+ "label": "clean",
+ "type": "shell",
+ "command": "make",
+ "args": [ "clean" ],
+ },{
+ "label": "flash",
+ "type": "shell",
+ "command": "make",
+ "args": [ "flash" ],
+ }]
+}
\ No newline at end of file
--- /dev/null
+
+NAME=nano-1284-1_atmega1284p
+DEVICE= atmega1284p
+AVRDUDE_DEVICE= m1284p
+CPU_FREQUENCE= 12000000
+
+# --------------------------------------------------------------------------------
+
+.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)
+
+CC= avr-g++
+
+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 $@)
+ $(CC) $(CFLAGS) -o $@ $<
+
+# --------------------------------------------------------------------------------
+# simulation/debugging with gdb or simuc
+
+sim/$(NAME).elf: .depend $(OBJ_SIM)
+ $(CC) $(LFLAGS_SIM) -o $@ $(OBJ_SIM)
+ @ln -s $(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
+
+gdb: sim/$(NAME).elf
+ avr-gdb $<
+
+# -------------------------------------------------------------
+# flash to target with arduino bootloader in bootloader-section
+
+flash-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB0 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash0-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB0 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash1-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB1 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash2-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB2 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+# ----------------------------------------------
+# flash to target with fischl programming device
+
+isp-$(AVRDUDE_DEVICE):
+ 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
+
+# --------------------------------------------------------
+# picocom sends CR for ENTER -> convert cr (\r) to lf (\n)
+
+picocom:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB0
+
+picocom0:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB0
+
+picocom1:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB1
+
+picocom2:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB2
+
+# --------------------------------------------------------
+
+help:
+ @echo
+ @echo "Possible targets are:"
+ @echo " clean"
+ @echo " all help info"
+ @echo " flash-$(AVRDUDE_DEVICE) flash0-$(AVRDUDE_DEVICE) flash1-$(AVRDUDE_DEVICE) flash2-$(AVRDUDE_DEVICE)"
+ @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"
--- /dev/null
+# Programmvorlage Nano-1284
--- /dev/null
+
+int main () {
+ return 0;
+}
+
--- /dev/null
+target remote :1234
+layout split
+stepi
+quit
+target remote :1234
+layout split
+stepi
+b *main+9
+quit
--- /dev/null
+.depend
+**/build
+**/dist
+**/sim
--- /dev/null
+{
+ "configurations": [
+ {
+ "name": "Linux AVR",
+ "includePath": [
+ "/usr/lib/avr/include/**",
+ "/usr/lib/gcc/avr/**"
+ ],
+ "defines": [],
+ "compilerPath": "/usr/bin/avr-gcc",
+ "compilerArgs": [ "-mmcu=atmega644p", "-DF_CPU=12000000", "-Os" ],
+ "cStandard": "gnu11",
+ "cppStandard": "gnu++11",
+ "intelliSenseMode": "linux-gcc-x64"
+ }
+ ],
+ "version": 4
+}
--- /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/atmega644p.elf",
+ "cwd": "${workspaceFolder}",
+ "externalConsole": false,
+ "MIMode": "gdb",
+ "miDebuggerPath": "/usr/bin/avr-gdb",
+ "miDebuggerServerAddress": ":1234",
+ "preLaunchTask": "build"
+ }
+ ]
+}
--- /dev/null
+{
+ "[c]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "[cpp]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "[h]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "[hpp]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "cSpell.words": [],
+ "cSpell.ignorePaths": [
+ "**/*.json", "**/*.c", "**/*.h", "**/*.cpp", "**/*.hpp", "**/Makefile"
+ ]
+}
--- /dev/null
+{
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
+ // for the documentation about the tasks.json format
+ "version": "2.0.0",
+ "tasks": [{
+ "label": "build",
+ "type": "shell",
+ "command": "make",
+ "problemMatcher":[
+ "$gcc"
+ ]
+ },{
+ "label": "clean",
+ "type": "shell",
+ "command": "make",
+ "args": [ "clean" ],
+ },{
+ "label": "flash",
+ "type": "shell",
+ "command": "make",
+ "args": [ "flash" ],
+ }]
+}
\ No newline at end of file
--- /dev/null
+
+NAME=nano-644-1_atmega644p
+DEVICE= atmega644p
+AVRDUDE_DEVICE= m644p
+CPU_FREQUENCE= 12000000
+
+# --------------------------------------------------------------------------------
+
+.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)
+
+CC= avr-g++
+
+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 $@)
+ $(CC) $(CFLAGS) -o $@ $<
+
+# --------------------------------------------------------------------------------
+# simulation/debugging with gdb or simuc
+
+sim/$(NAME).elf: .depend $(OBJ_SIM)
+ $(CC) $(LFLAGS_SIM) -o $@ $(OBJ_SIM)
+ @ln -s $(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
+
+gdb: sim/$(NAME).elf
+ avr-gdb $<
+
+# -------------------------------------------------------------
+# flash to target with arduino bootloader in bootloader-section
+
+flash-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB0 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash0-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB0 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash1-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB1 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash2-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB2 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+# ----------------------------------------------
+# flash to target with fischl programming device
+
+isp-$(AVRDUDE_DEVICE):
+ 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
+
+# --------------------------------------------------------
+# picocom sends CR for ENTER -> convert cr (\r) to lf (\n)
+
+picocom:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB0
+
+picocom0:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB0
+
+picocom1:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB1
+
+picocom2:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB2
+
+# --------------------------------------------------------
+
+help:
+ @echo
+ @echo "Possible targets are:"
+ @echo " clean"
+ @echo " all help info"
+ @echo " flash-$(AVRDUDE_DEVICE) flash0-$(AVRDUDE_DEVICE) flash1-$(AVRDUDE_DEVICE) flash2-$(AVRDUDE_DEVICE)"
+ @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"
--- /dev/null
+# Programmvorlage Nano-644
--- /dev/null
+
+int main () {
+ return 0;
+}
+
--- /dev/null
+target remote :1234
+layout split
+stepi
+quit
+target remote :1234
+layout split
+stepi
+b *main+9
+quit
--- /dev/null
+.depend
+**/build
+**/dist
+**/sim
--- /dev/null
+{
+ "configurations": [
+ {
+ "name": "Linux AVR",
+ "includePath": [
+ "/usr/lib/avr/include/**",
+ "/usr/lib/gcc/avr/**"
+ ],
+ "defines": [],
+ "compilerPath": "/usr/bin/avr-gcc",
+ "compilerArgs": [ "-mmcu=atmega16", "-DF_CPU=12000000", "-Os" ],
+ "cStandard": "gnu11",
+ "cppStandard": "gnu++11",
+ "intelliSenseMode": "linux-gcc-x64"
+ }
+ ],
+ "version": 4
+}
--- /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/atmega16.elf",
+ "cwd": "${workspaceFolder}",
+ "externalConsole": false,
+ "MIMode": "gdb",
+ "miDebuggerPath": "/usr/bin/avr-gdb",
+ "miDebuggerServerAddress": ":1234",
+ "preLaunchTask": "build"
+ }
+ ]
+}
--- /dev/null
+{
+ "[c]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "[cpp]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "[h]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "[hpp]": {
+ "editor.insertSpaces": true,
+ "editor.tabSize": 3,
+ "editor.detectIndentation": false
+ },
+ "cSpell.words": [],
+ "cSpell.ignorePaths": [
+ "**/*.json", "**/*.c", "**/*.h", "**/*.cpp", "**/*.hpp", "**/Makefile"
+ ]
+}
--- /dev/null
+{
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
+ // for the documentation about the tasks.json format
+ "version": "2.0.0",
+ "tasks": [{
+ "label": "build",
+ "type": "shell",
+ "command": "make",
+ "problemMatcher":[
+ "$gcc"
+ ]
+ },{
+ "label": "clean",
+ "type": "shell",
+ "command": "make",
+ "args": [ "clean" ],
+ },{
+ "label": "flash",
+ "type": "shell",
+ "command": "make",
+ "args": [ "flash" ],
+ }]
+}
\ No newline at end of file
--- /dev/null
+
+NAME=sure-1_atmega16p
+DEVICE= atmega16
+AVRDUDE_DEVICE= m16
+CPU_FREQUENCE= 12000000
+
+# --------------------------------------------------------------------------------
+
+.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)
+
+CC= avr-g++
+
+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 $@)
+ $(CC) $(CFLAGS) -o $@ $<
+
+# --------------------------------------------------------------------------------
+# simulation/debugging with gdb or simuc
+
+sim/$(NAME).elf: .depend $(OBJ_SIM)
+ $(CC) $(LFLAGS_SIM) -o $@ $(OBJ_SIM)
+ @ln -s $(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
+
+gdb: sim/$(NAME).elf
+ avr-gdb $<
+
+# -------------------------------------------------------------
+# flash to target with arduino bootloader in bootloader-section
+
+flash-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB0 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash0-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB0 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash1-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB1 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash2-$(AVRDUDE_DEVICE): dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB2 -b 115200 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+# ----------------------------------------------
+# flash to target with fischl programming device
+
+isp-$(AVRDUDE_DEVICE):
+ 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
+
+# --------------------------------------------------------
+# picocom sends CR for ENTER -> convert cr (\r) to lf (\n)
+
+picocom:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB0
+
+picocom0:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB0
+
+picocom1:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB1
+
+picocom2:
+ picocom -b 115200 --omap crlf --raise-dtr /dev/ttyUSB2
+
+# --------------------------------------------------------
+
+help:
+ @echo
+ @echo "Possible targets are:"
+ @echo " clean"
+ @echo " all help info"
+ @echo " flash-$(AVRDUDE_DEVICE) flash0-$(AVRDUDE_DEVICE) flash1-$(AVRDUDE_DEVICE) flash2-$(AVRDUDE_DEVICE)"
+ @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"
--- /dev/null
+# Programmvorlage Sure-Board (ATmega16)
\ No newline at end of file
--- /dev/null
+
+int main () {
+ return 0;
+}
+