From 22bb33d3e7059d92228eccfddffbb9895ef17339 Mon Sep 17 00:00:00 2001 From: Manfred Steiner Date: Sat, 7 Sep 2024 17:36:37 +0200 Subject: [PATCH 1/1] Projektvorlagen VSCode/AVR/Level-1 --- LICENSE | 21 ++ README.md | 23 ++ vscode-avr-c-cpp/arduino-nano-1/.gdb_history | 9 + vscode-avr-c-cpp/arduino-nano-1/.gdbinit | 2 + vscode-avr-c-cpp/arduino-nano-1/.gitignore | 4 + .../.vscode/c_cpp_properties.json | 18 ++ .../arduino-nano-1/.vscode/launch.json | 37 +++ .../arduino-nano-1/.vscode/settings.json | 26 +++ .../arduino-nano-1/.vscode/tasks.json | 23 ++ vscode-avr-c-cpp/arduino-nano-1/Makefile | 215 ++++++++++++++++++ vscode-avr-c-cpp/arduino-nano-1/README.md | 1 + vscode-avr-c-cpp/arduino-nano-1/src/main.c | 5 + vscode-avr-c-cpp/nano-1284-1/.gdb_history | 9 + vscode-avr-c-cpp/nano-1284-1/.gdbinit | 2 + vscode-avr-c-cpp/nano-1284-1/.gitignore | 4 + .../nano-1284-1/.vscode/c_cpp_properties.json | 18 ++ .../nano-1284-1/.vscode/launch.json | 37 +++ .../nano-1284-1/.vscode/settings.json | 26 +++ .../nano-1284-1/.vscode/tasks.json | 23 ++ vscode-avr-c-cpp/nano-1284-1/Makefile | 215 ++++++++++++++++++ vscode-avr-c-cpp/nano-1284-1/README.md | 1 + vscode-avr-c-cpp/nano-1284-1/src/main.c | 5 + vscode-avr-c-cpp/nano-644-1/.gdb_history | 9 + vscode-avr-c-cpp/nano-644-1/.gdbinit | 2 + vscode-avr-c-cpp/nano-644-1/.gitignore | 4 + .../nano-644-1/.vscode/c_cpp_properties.json | 18 ++ .../nano-644-1/.vscode/launch.json | 37 +++ .../nano-644-1/.vscode/settings.json | 26 +++ .../nano-644-1/.vscode/tasks.json | 23 ++ vscode-avr-c-cpp/nano-644-1/Makefile | 215 ++++++++++++++++++ vscode-avr-c-cpp/nano-644-1/README.md | 1 + vscode-avr-c-cpp/nano-644-1/src/main.c | 5 + vscode-avr-c-cpp/sure-1/.gdb_history | 9 + vscode-avr-c-cpp/sure-1/.gdbinit | 2 + vscode-avr-c-cpp/sure-1/.gitignore | 4 + .../sure-1/.vscode/c_cpp_properties.json | 18 ++ vscode-avr-c-cpp/sure-1/.vscode/launch.json | 37 +++ vscode-avr-c-cpp/sure-1/.vscode/settings.json | 26 +++ vscode-avr-c-cpp/sure-1/.vscode/tasks.json | 23 ++ vscode-avr-c-cpp/sure-1/Makefile | 215 ++++++++++++++++++ vscode-avr-c-cpp/sure-1/README.md | 1 + vscode-avr-c-cpp/sure-1/src/main.c | 5 + 42 files changed, 1404 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 vscode-avr-c-cpp/arduino-nano-1/.gdb_history create mode 100644 vscode-avr-c-cpp/arduino-nano-1/.gdbinit create mode 100644 vscode-avr-c-cpp/arduino-nano-1/.gitignore create mode 100644 vscode-avr-c-cpp/arduino-nano-1/.vscode/c_cpp_properties.json create mode 100644 vscode-avr-c-cpp/arduino-nano-1/.vscode/launch.json create mode 100644 vscode-avr-c-cpp/arduino-nano-1/.vscode/settings.json create mode 100644 vscode-avr-c-cpp/arduino-nano-1/.vscode/tasks.json create mode 100644 vscode-avr-c-cpp/arduino-nano-1/Makefile create mode 100644 vscode-avr-c-cpp/arduino-nano-1/README.md create mode 100644 vscode-avr-c-cpp/arduino-nano-1/src/main.c create mode 100644 vscode-avr-c-cpp/nano-1284-1/.gdb_history create mode 100644 vscode-avr-c-cpp/nano-1284-1/.gdbinit create mode 100644 vscode-avr-c-cpp/nano-1284-1/.gitignore create mode 100644 vscode-avr-c-cpp/nano-1284-1/.vscode/c_cpp_properties.json create mode 100644 vscode-avr-c-cpp/nano-1284-1/.vscode/launch.json create mode 100644 vscode-avr-c-cpp/nano-1284-1/.vscode/settings.json create mode 100644 vscode-avr-c-cpp/nano-1284-1/.vscode/tasks.json create mode 100644 vscode-avr-c-cpp/nano-1284-1/Makefile create mode 100644 vscode-avr-c-cpp/nano-1284-1/README.md create mode 100644 vscode-avr-c-cpp/nano-1284-1/src/main.c create mode 100644 vscode-avr-c-cpp/nano-644-1/.gdb_history create mode 100644 vscode-avr-c-cpp/nano-644-1/.gdbinit create mode 100644 vscode-avr-c-cpp/nano-644-1/.gitignore create mode 100644 vscode-avr-c-cpp/nano-644-1/.vscode/c_cpp_properties.json create mode 100644 vscode-avr-c-cpp/nano-644-1/.vscode/launch.json create mode 100644 vscode-avr-c-cpp/nano-644-1/.vscode/settings.json create mode 100644 vscode-avr-c-cpp/nano-644-1/.vscode/tasks.json create mode 100644 vscode-avr-c-cpp/nano-644-1/Makefile create mode 100644 vscode-avr-c-cpp/nano-644-1/README.md create mode 100644 vscode-avr-c-cpp/nano-644-1/src/main.c create mode 100644 vscode-avr-c-cpp/sure-1/.gdb_history create mode 100644 vscode-avr-c-cpp/sure-1/.gdbinit create mode 100644 vscode-avr-c-cpp/sure-1/.gitignore create mode 100644 vscode-avr-c-cpp/sure-1/.vscode/c_cpp_properties.json create mode 100644 vscode-avr-c-cpp/sure-1/.vscode/launch.json create mode 100644 vscode-avr-c-cpp/sure-1/.vscode/settings.json create mode 100644 vscode-avr-c-cpp/sure-1/.vscode/tasks.json create mode 100644 vscode-avr-c-cpp/sure-1/Makefile create mode 100644 vscode-avr-c-cpp/sure-1/README.md create mode 100644 vscode-avr-c-cpp/sure-1/src/main.c diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..35f41ef --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..90e060d --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# 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) + + + + diff --git a/vscode-avr-c-cpp/arduino-nano-1/.gdb_history b/vscode-avr-c-cpp/arduino-nano-1/.gdb_history new file mode 100644 index 0000000..3339046 --- /dev/null +++ b/vscode-avr-c-cpp/arduino-nano-1/.gdb_history @@ -0,0 +1,9 @@ +target remote :1234 +layout split +stepi +quit +target remote :1234 +layout split +stepi +b *main+9 +quit diff --git a/vscode-avr-c-cpp/arduino-nano-1/.gdbinit b/vscode-avr-c-cpp/arduino-nano-1/.gdbinit new file mode 100644 index 0000000..139597f --- /dev/null +++ b/vscode-avr-c-cpp/arduino-nano-1/.gdbinit @@ -0,0 +1,2 @@ + + diff --git a/vscode-avr-c-cpp/arduino-nano-1/.gitignore b/vscode-avr-c-cpp/arduino-nano-1/.gitignore new file mode 100644 index 0000000..a959910 --- /dev/null +++ b/vscode-avr-c-cpp/arduino-nano-1/.gitignore @@ -0,0 +1,4 @@ +.depend +**/build +**/dist +**/sim diff --git a/vscode-avr-c-cpp/arduino-nano-1/.vscode/c_cpp_properties.json b/vscode-avr-c-cpp/arduino-nano-1/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..93c17af --- /dev/null +++ b/vscode-avr-c-cpp/arduino-nano-1/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "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 +} diff --git a/vscode-avr-c-cpp/arduino-nano-1/.vscode/launch.json b/vscode-avr-c-cpp/arduino-nano-1/.vscode/launch.json new file mode 100644 index 0000000..f29cf2e --- /dev/null +++ b/vscode-avr-c-cpp/arduino-nano-1/.vscode/launch.json @@ -0,0 +1,37 @@ +{ + // 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" + } + ] +} diff --git a/vscode-avr-c-cpp/arduino-nano-1/.vscode/settings.json b/vscode-avr-c-cpp/arduino-nano-1/.vscode/settings.json new file mode 100644 index 0000000..b2e94c9 --- /dev/null +++ b/vscode-avr-c-cpp/arduino-nano-1/.vscode/settings.json @@ -0,0 +1,26 @@ +{ + "[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" + ] +} diff --git a/vscode-avr-c-cpp/arduino-nano-1/.vscode/tasks.json b/vscode-avr-c-cpp/arduino-nano-1/.vscode/tasks.json new file mode 100644 index 0000000..74fb1c7 --- /dev/null +++ b/vscode-avr-c-cpp/arduino-nano-1/.vscode/tasks.json @@ -0,0 +1,23 @@ +{ + // 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 diff --git a/vscode-avr-c-cpp/arduino-nano-1/Makefile b/vscode-avr-c-cpp/arduino-nano-1/Makefile new file mode 100644 index 0000000..0c7297b --- /dev/null +++ b/vscode-avr-c-cpp/arduino-nano-1/Makefile @@ -0,0 +1,215 @@ + +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" diff --git a/vscode-avr-c-cpp/arduino-nano-1/README.md b/vscode-avr-c-cpp/arduino-nano-1/README.md new file mode 100644 index 0000000..793bd3b --- /dev/null +++ b/vscode-avr-c-cpp/arduino-nano-1/README.md @@ -0,0 +1 @@ +# Programmvorlage Arduino Nano/Uno diff --git a/vscode-avr-c-cpp/arduino-nano-1/src/main.c b/vscode-avr-c-cpp/arduino-nano-1/src/main.c new file mode 100644 index 0000000..3b7bda2 --- /dev/null +++ b/vscode-avr-c-cpp/arduino-nano-1/src/main.c @@ -0,0 +1,5 @@ + +int main () { + return 0; +} + diff --git a/vscode-avr-c-cpp/nano-1284-1/.gdb_history b/vscode-avr-c-cpp/nano-1284-1/.gdb_history new file mode 100644 index 0000000..3339046 --- /dev/null +++ b/vscode-avr-c-cpp/nano-1284-1/.gdb_history @@ -0,0 +1,9 @@ +target remote :1234 +layout split +stepi +quit +target remote :1234 +layout split +stepi +b *main+9 +quit diff --git a/vscode-avr-c-cpp/nano-1284-1/.gdbinit b/vscode-avr-c-cpp/nano-1284-1/.gdbinit new file mode 100644 index 0000000..139597f --- /dev/null +++ b/vscode-avr-c-cpp/nano-1284-1/.gdbinit @@ -0,0 +1,2 @@ + + diff --git a/vscode-avr-c-cpp/nano-1284-1/.gitignore b/vscode-avr-c-cpp/nano-1284-1/.gitignore new file mode 100644 index 0000000..a959910 --- /dev/null +++ b/vscode-avr-c-cpp/nano-1284-1/.gitignore @@ -0,0 +1,4 @@ +.depend +**/build +**/dist +**/sim diff --git a/vscode-avr-c-cpp/nano-1284-1/.vscode/c_cpp_properties.json b/vscode-avr-c-cpp/nano-1284-1/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..dda83a0 --- /dev/null +++ b/vscode-avr-c-cpp/nano-1284-1/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "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 +} diff --git a/vscode-avr-c-cpp/nano-1284-1/.vscode/launch.json b/vscode-avr-c-cpp/nano-1284-1/.vscode/launch.json new file mode 100644 index 0000000..6dc7276 --- /dev/null +++ b/vscode-avr-c-cpp/nano-1284-1/.vscode/launch.json @@ -0,0 +1,37 @@ +{ + // 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" + } + ] +} diff --git a/vscode-avr-c-cpp/nano-1284-1/.vscode/settings.json b/vscode-avr-c-cpp/nano-1284-1/.vscode/settings.json new file mode 100644 index 0000000..b2e94c9 --- /dev/null +++ b/vscode-avr-c-cpp/nano-1284-1/.vscode/settings.json @@ -0,0 +1,26 @@ +{ + "[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" + ] +} diff --git a/vscode-avr-c-cpp/nano-1284-1/.vscode/tasks.json b/vscode-avr-c-cpp/nano-1284-1/.vscode/tasks.json new file mode 100644 index 0000000..74fb1c7 --- /dev/null +++ b/vscode-avr-c-cpp/nano-1284-1/.vscode/tasks.json @@ -0,0 +1,23 @@ +{ + // 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 diff --git a/vscode-avr-c-cpp/nano-1284-1/Makefile b/vscode-avr-c-cpp/nano-1284-1/Makefile new file mode 100644 index 0000000..bbe7b2e --- /dev/null +++ b/vscode-avr-c-cpp/nano-1284-1/Makefile @@ -0,0 +1,215 @@ + +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" diff --git a/vscode-avr-c-cpp/nano-1284-1/README.md b/vscode-avr-c-cpp/nano-1284-1/README.md new file mode 100644 index 0000000..8f32ccd --- /dev/null +++ b/vscode-avr-c-cpp/nano-1284-1/README.md @@ -0,0 +1 @@ +# Programmvorlage Nano-1284 diff --git a/vscode-avr-c-cpp/nano-1284-1/src/main.c b/vscode-avr-c-cpp/nano-1284-1/src/main.c new file mode 100644 index 0000000..3b7bda2 --- /dev/null +++ b/vscode-avr-c-cpp/nano-1284-1/src/main.c @@ -0,0 +1,5 @@ + +int main () { + return 0; +} + diff --git a/vscode-avr-c-cpp/nano-644-1/.gdb_history b/vscode-avr-c-cpp/nano-644-1/.gdb_history new file mode 100644 index 0000000..3339046 --- /dev/null +++ b/vscode-avr-c-cpp/nano-644-1/.gdb_history @@ -0,0 +1,9 @@ +target remote :1234 +layout split +stepi +quit +target remote :1234 +layout split +stepi +b *main+9 +quit diff --git a/vscode-avr-c-cpp/nano-644-1/.gdbinit b/vscode-avr-c-cpp/nano-644-1/.gdbinit new file mode 100644 index 0000000..139597f --- /dev/null +++ b/vscode-avr-c-cpp/nano-644-1/.gdbinit @@ -0,0 +1,2 @@ + + diff --git a/vscode-avr-c-cpp/nano-644-1/.gitignore b/vscode-avr-c-cpp/nano-644-1/.gitignore new file mode 100644 index 0000000..a959910 --- /dev/null +++ b/vscode-avr-c-cpp/nano-644-1/.gitignore @@ -0,0 +1,4 @@ +.depend +**/build +**/dist +**/sim diff --git a/vscode-avr-c-cpp/nano-644-1/.vscode/c_cpp_properties.json b/vscode-avr-c-cpp/nano-644-1/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..3a57c79 --- /dev/null +++ b/vscode-avr-c-cpp/nano-644-1/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "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 +} diff --git a/vscode-avr-c-cpp/nano-644-1/.vscode/launch.json b/vscode-avr-c-cpp/nano-644-1/.vscode/launch.json new file mode 100644 index 0000000..054054c --- /dev/null +++ b/vscode-avr-c-cpp/nano-644-1/.vscode/launch.json @@ -0,0 +1,37 @@ +{ + // 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" + } + ] +} diff --git a/vscode-avr-c-cpp/nano-644-1/.vscode/settings.json b/vscode-avr-c-cpp/nano-644-1/.vscode/settings.json new file mode 100644 index 0000000..b2e94c9 --- /dev/null +++ b/vscode-avr-c-cpp/nano-644-1/.vscode/settings.json @@ -0,0 +1,26 @@ +{ + "[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" + ] +} diff --git a/vscode-avr-c-cpp/nano-644-1/.vscode/tasks.json b/vscode-avr-c-cpp/nano-644-1/.vscode/tasks.json new file mode 100644 index 0000000..74fb1c7 --- /dev/null +++ b/vscode-avr-c-cpp/nano-644-1/.vscode/tasks.json @@ -0,0 +1,23 @@ +{ + // 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 diff --git a/vscode-avr-c-cpp/nano-644-1/Makefile b/vscode-avr-c-cpp/nano-644-1/Makefile new file mode 100644 index 0000000..be1c535 --- /dev/null +++ b/vscode-avr-c-cpp/nano-644-1/Makefile @@ -0,0 +1,215 @@ + +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" diff --git a/vscode-avr-c-cpp/nano-644-1/README.md b/vscode-avr-c-cpp/nano-644-1/README.md new file mode 100644 index 0000000..539e250 --- /dev/null +++ b/vscode-avr-c-cpp/nano-644-1/README.md @@ -0,0 +1 @@ +# Programmvorlage Nano-644 diff --git a/vscode-avr-c-cpp/nano-644-1/src/main.c b/vscode-avr-c-cpp/nano-644-1/src/main.c new file mode 100644 index 0000000..3b7bda2 --- /dev/null +++ b/vscode-avr-c-cpp/nano-644-1/src/main.c @@ -0,0 +1,5 @@ + +int main () { + return 0; +} + diff --git a/vscode-avr-c-cpp/sure-1/.gdb_history b/vscode-avr-c-cpp/sure-1/.gdb_history new file mode 100644 index 0000000..3339046 --- /dev/null +++ b/vscode-avr-c-cpp/sure-1/.gdb_history @@ -0,0 +1,9 @@ +target remote :1234 +layout split +stepi +quit +target remote :1234 +layout split +stepi +b *main+9 +quit diff --git a/vscode-avr-c-cpp/sure-1/.gdbinit b/vscode-avr-c-cpp/sure-1/.gdbinit new file mode 100644 index 0000000..139597f --- /dev/null +++ b/vscode-avr-c-cpp/sure-1/.gdbinit @@ -0,0 +1,2 @@ + + diff --git a/vscode-avr-c-cpp/sure-1/.gitignore b/vscode-avr-c-cpp/sure-1/.gitignore new file mode 100644 index 0000000..a959910 --- /dev/null +++ b/vscode-avr-c-cpp/sure-1/.gitignore @@ -0,0 +1,4 @@ +.depend +**/build +**/dist +**/sim diff --git a/vscode-avr-c-cpp/sure-1/.vscode/c_cpp_properties.json b/vscode-avr-c-cpp/sure-1/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..16fc080 --- /dev/null +++ b/vscode-avr-c-cpp/sure-1/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "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 +} diff --git a/vscode-avr-c-cpp/sure-1/.vscode/launch.json b/vscode-avr-c-cpp/sure-1/.vscode/launch.json new file mode 100644 index 0000000..ee08d3e --- /dev/null +++ b/vscode-avr-c-cpp/sure-1/.vscode/launch.json @@ -0,0 +1,37 @@ +{ + // 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" + } + ] +} diff --git a/vscode-avr-c-cpp/sure-1/.vscode/settings.json b/vscode-avr-c-cpp/sure-1/.vscode/settings.json new file mode 100644 index 0000000..b2e94c9 --- /dev/null +++ b/vscode-avr-c-cpp/sure-1/.vscode/settings.json @@ -0,0 +1,26 @@ +{ + "[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" + ] +} diff --git a/vscode-avr-c-cpp/sure-1/.vscode/tasks.json b/vscode-avr-c-cpp/sure-1/.vscode/tasks.json new file mode 100644 index 0000000..74fb1c7 --- /dev/null +++ b/vscode-avr-c-cpp/sure-1/.vscode/tasks.json @@ -0,0 +1,23 @@ +{ + // 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 diff --git a/vscode-avr-c-cpp/sure-1/Makefile b/vscode-avr-c-cpp/sure-1/Makefile new file mode 100644 index 0000000..dfa0814 --- /dev/null +++ b/vscode-avr-c-cpp/sure-1/Makefile @@ -0,0 +1,215 @@ + +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" diff --git a/vscode-avr-c-cpp/sure-1/README.md b/vscode-avr-c-cpp/sure-1/README.md new file mode 100644 index 0000000..e25ca59 --- /dev/null +++ b/vscode-avr-c-cpp/sure-1/README.md @@ -0,0 +1 @@ +# Programmvorlage Sure-Board (ATmega16) \ No newline at end of file diff --git a/vscode-avr-c-cpp/sure-1/src/main.c b/vscode-avr-c-cpp/sure-1/src/main.c new file mode 100644 index 0000000..3b7bda2 --- /dev/null +++ b/vscode-avr-c-cpp/sure-1/src/main.c @@ -0,0 +1,5 @@ + +int main () { + return 0; +} + -- 2.39.5