--- /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/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
+.PHONY: all info flash picocom clean
+$(shell mkdir -p dist >/dev/null)
+$(shell mkdir -p build >/dev/null)
+$(shell mkdir -p sim >/dev/null)
+
+NAME="test_2024-07-23_nano-644"
+SRC= $(wildcard src/*.c src/*.cpp)
+OBJ = $(SRC:src/%.c=build/%.o)
+OBJ_SIM = $(SRC:src/%.c=sim/%.o)
+
+DEVICE=atmega644p
+
+CC= avr-gcc
+CFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000 -c
+LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000
+
+CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=12000000 -g -c
+LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=12000000 -g
+
+
+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
+
+.depend: $(SRC)
+ $(CC) -MM $(SRC) > .depend
+
+-include $(DEPENDFILE)
+
+dist/$(NAME).elf: .depend $(OBJ)
+ $(CC) $(LFLAGS) -o $@ $(OBJ)
+
+dist/%.s: dist/%.elf
+ avr-objdump -d $< > $@
+
+dist/%.hex: dist/%.elf
+ avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
+
+sim/$(NAME).elf: .depend $(OBJ_SIM)
+ $(CC) $(LFLAGS_SIM) -o $@ $(OBJ_SIM)
+
+
+build/%.o: src/%.c
+ $(CC) $(CFLAGS) -o $@ $<
+
+sim/%.o: src/%.c
+ $(CC) $(CFLAGS_SIM) -o $@ $<
+
+sim/%.s: sim/%.elf
+ avr-objdump -d $< > $@
+
+simuc: sim/$(NAME).elf
+ simuc --board arduino $<
+
+gdb: sim/$(NAME).elf
+ avr-gdb $<
+
+isp-flash: dist/$(NAME).elf all
+ avrdude -c usbasp -p m644p -e -U flash:w:$<
+
+flash: dist/$(NAME).elf all
+ avrdude -c arduino -p m644p -P /dev/ttyUSB0 -b 115200 -e -U flash:w:$<
+
+
+picocom:
+ # picocom sends CR for ENTER -> convert cr (\r) to lf (\n)
+ picocom -b 115200 --omap crlf /dev/ttyUSB0
+
+fuse:
+ avrdude -c usbasp -p m644p -U lfuse:w:0xEE:m -U hfuse:w:0xD9:m -U efuse:w:0xFF:m
+
+clean:
+ @rm -r dist
+ @rm -r build
+ @rm -r sim
+ @find . -type f -name ".depend" -exec rm {} \;
+ @echo "clean done"
--- /dev/null
+# Testprogramm
--- /dev/null
+#include <avr/io.h>
+#include <util/delay.h>
+#include <stdio.h>
+#include <avr/interrupt.h>
+
+int uart_putchar(char c, FILE *stream) {
+ if (c == '\n') {
+ uart_putchar('\r', stream);
+ }
+ if (stream == stdout) {
+ loop_until_bit_is_set(UCSR0A, UDRE0);
+ UDR0 = c;
+ } else if (stream == stderr) {
+ loop_until_bit_is_set(UCSR1A, UDRE1);
+ UDR1 = c;
+ }
+ return 0;
+}
+
+static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
+static FILE mystderr = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
+
+int main () {
+
+ DDRC = 0x1C;
+ PORTC = 0x3C;
+
+ UCSR0A = (1 << U2X0);
+ UCSR0B = (1 << RXCIE0) | (1 << RXEN0) | (1 <<TXEN0);
+ UCSR0C = (1 << UCSZ01) | ( 1<< UCSZ00);
+ UBRR0H = 0;
+ UBRR0L = F_CPU / 8 / 115200 - 1;
+
+ UCSR1A = (1 << U2X0);
+ UCSR1B = (1 << RXCIE0) | (1 << RXEN0) | (1 <<TXEN0);
+ UCSR1C = (1 << UCSZ01) | ( 1<< UCSZ00);
+ UBRR1H = 0;
+ UBRR1L = F_CPU / 8 / 115200 - 1;
+
+ stdout = &mystdout;
+ stderr = &mystderr;
+
+ DDRD = 0xf0; // LED D4..D1
+ PORTD = 0;
+
+ DDRA = 0x00; // SW PA3..PA0
+ PORTA = 0x0f;
+
+ // DDRB = 0xff; // 7-Segment
+ // PORTB = 0xff;
+
+ DDRB = 0x07; // RGB-LED
+ PORTB = 0;
+
+ uint16_t cnt = 0;
+ while (1) {
+ _delay_ms(500);
+ PORTC ^= 0x1C;
+ printf("%04x: PINA=0x%02x PORTD=0x%02x \n", cnt++, PINA, PORTD);
+
+ PORTD ^= 0xf0;
+ for (uint8_t i = 0; i < 4; i++) {
+ uint8_t swPressed = (PINA & (1 << i)) == 0;
+ if (swPressed) {
+ fprintf(stderr, "SW%d pressed\n", i);
+ PORTD |= (1 << (i + 4));
+ }
+ }
+
+ for (uint8_t i = 0; i < 3; i++) {
+ uint8_t swPressed = (PINA & (1 << i)) == 0;
+ if (swPressed) {
+ PORTB |= (1 << i);
+ } else {
+ PORTB &= ~(1 << i);
+ }
+ }
+
+ }
+
+ // TCCR1B = (1 << WGM12) | (1 << CS11);
+ // OCR1A = 1500;
+ // TIMSK1 = (1 << OCIE1A);
+
+ // UCSR0A = (1 << U2X0);
+ // UCSR0B = (1 << RXCIE0) | (1 << RXEN0) | (1 <<TXEN0);
+ // UCSR0C = (1 << UCSZ01) | ( 1<< UCSZ00);
+ // UBRR0H = 0;
+ // UBRR0L = F_CPU / 8 / 115200 - 1;
+
+ // UCSR1A = (1 << U2X1);
+ // UCSR1B = (1 << RXCIE1) | (1 << RXEN1) | (1 <<TXEN1);
+ // UCSR1C = (1 << UCSZ11) | ( 1<< UCSZ10);
+ // UBRR1H = 0;
+ // UBRR1L = F_CPU / 8 / 115200 - 1;
+
+ // stdout = &mystdout;
+ // stderr = &mystderr;
+ // fromUart0[0] = 0;
+ // sei();
+
+ // uint16_t cnt = 0;
+ // while (1) {
+ // printf("%04x: Hello world%s %12s\r",
+ // cnt++,
+ // fromUart0,
+ // (PINC & (1 << PC5)) == 0 ? "SW2 pressed" : ""
+ // );
+ // if ((PINC & (1 << PC5)) == 0) {
+ // PORTC &= ~(1 << PC2);
+ // }
+ // _delay_ms(10);
+ // }
+}
+
+// ISR (USART0_RX_vect) {
+// PORTC ^= (1 << PC3);
+// uint8_t b = UDR0;
+// UDR1 = b;
+// fromUart0[0] = ' ';
+// fromUart0[4] = b;
+// }
+
+// ISR (USART1_RX_vect) {
+// uint8_t b = UDR1;
+// if (b == ' ') {
+// PORTC |= (1 << PC2);
+// }
+// }
+
+
+// ISR (TIMER1_COMPA_vect) {
+// static uint16_t timer = 0;
+// timer++;
+// if (timer >= 1000) {
+// PORTC ^= (1 << PC4);
+// timer = 0;
+// }
+// }
+