From 1816c05268324b40c02c8af935afd81d78c3d9b3 Mon Sep 17 00:00:00 2001 From: Manfred Steiner Date: Sat, 13 Jul 2024 17:33:29 +0200 Subject: [PATCH] software/uart1-to-uart0 --- software/uart1-to-uart0/.gdb_history | 9 +++ software/uart1-to-uart0/.gdbinit | 5 ++ software/uart1-to-uart0/.gitignore | 4 + .../.vscode/c_cpp_properties.json | 18 +++++ software/uart1-to-uart0/.vscode/launch.json | 37 +++++++++ software/uart1-to-uart0/.vscode/settings.json | 19 +++++ software/uart1-to-uart0/.vscode/tasks.json | 23 ++++++ software/uart1-to-uart0/Makefile | 75 +++++++++++++++++++ software/uart1-to-uart0/README.md | 7 ++ software/uart1-to-uart0/src/main.c | 72 ++++++++++++++++++ 10 files changed, 269 insertions(+) create mode 100644 software/uart1-to-uart0/.gdb_history create mode 100644 software/uart1-to-uart0/.gdbinit create mode 100644 software/uart1-to-uart0/.gitignore create mode 100644 software/uart1-to-uart0/.vscode/c_cpp_properties.json create mode 100644 software/uart1-to-uart0/.vscode/launch.json create mode 100644 software/uart1-to-uart0/.vscode/settings.json create mode 100644 software/uart1-to-uart0/.vscode/tasks.json create mode 100644 software/uart1-to-uart0/Makefile create mode 100644 software/uart1-to-uart0/README.md create mode 100644 software/uart1-to-uart0/src/main.c diff --git a/software/uart1-to-uart0/.gdb_history b/software/uart1-to-uart0/.gdb_history new file mode 100644 index 0000000..3339046 --- /dev/null +++ b/software/uart1-to-uart0/.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/software/uart1-to-uart0/.gdbinit b/software/uart1-to-uart0/.gdbinit new file mode 100644 index 0000000..a8c4b59 --- /dev/null +++ b/software/uart1-to-uart0/.gdbinit @@ -0,0 +1,5 @@ +set history save on +set history size 1000 +set history remove-duplicates 2 +set history filename .gdb_history + diff --git a/software/uart1-to-uart0/.gitignore b/software/uart1-to-uart0/.gitignore new file mode 100644 index 0000000..a959910 --- /dev/null +++ b/software/uart1-to-uart0/.gitignore @@ -0,0 +1,4 @@ +.depend +**/build +**/dist +**/sim diff --git a/software/uart1-to-uart0/.vscode/c_cpp_properties.json b/software/uart1-to-uart0/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..3a57c79 --- /dev/null +++ b/software/uart1-to-uart0/.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/software/uart1-to-uart0/.vscode/launch.json b/software/uart1-to-uart0/.vscode/launch.json new file mode 100644 index 0000000..f29cf2e --- /dev/null +++ b/software/uart1-to-uart0/.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/software/uart1-to-uart0/.vscode/settings.json b/software/uart1-to-uart0/.vscode/settings.json new file mode 100644 index 0000000..4448dde --- /dev/null +++ b/software/uart1-to-uart0/.vscode/settings.json @@ -0,0 +1,19 @@ +{ + "[c]": { + "editor.insertSpaces": true, + "editor.tabSize": 3, + "editor.detectIndentation": false + }, + "[h]": { + "editor.insertSpaces": true, + "editor.tabSize": 3, + "editor.detectIndentation": false + }, + "cSpell.words": [], + "cSpell.ignorePaths": [ + "**/*.json", "**/*.c", "**/*.h", "**/Makefile" + ], + "files.associations": { + "delay.h": "c" + } +} diff --git a/software/uart1-to-uart0/.vscode/tasks.json b/software/uart1-to-uart0/.vscode/tasks.json new file mode 100644 index 0000000..74fb1c7 --- /dev/null +++ b/software/uart1-to-uart0/.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/software/uart1-to-uart0/Makefile b/software/uart1-to-uart0/Makefile new file mode 100644 index 0000000..0f20c88 --- /dev/null +++ b/software/uart1-to-uart0/Makefile @@ -0,0 +1,75 @@ +.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="uart1-to-uart0" +SRC= $(wildcard src/*.c) +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=atmega644p -Og -DF_CPU=12000000 -g -c +LFLAGS_SIM= -Wall -mmcu=atmega644p -Og -DF_CPU=12000000 -g + + +all: dist/$(NAME).elf dist/$(NAME).s sim/$(NAME).elf sim/$(NAME).s info + +info: + @echo + @avr-size --mcu=atmega644p --format=avr dist/$(NAME).elf + +.depend: $(SRC) + $(CC) -mmcu=$(DEVICE) -MM $(SRC) > .depend + +-include $(DEPENDFILE) + +dist/$(NAME).elf: .depend $(OBJ) + $(CC) $(LFLAGS) -o $@ $(OBJ) + +dist/%.s: dist/%.elf + avr-objdump -d $< > $@ + +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" diff --git a/software/uart1-to-uart0/README.md b/software/uart1-to-uart0/README.md new file mode 100644 index 0000000..f0d45f5 --- /dev/null +++ b/software/uart1-to-uart0/README.md @@ -0,0 +1,7 @@ +# uart1-to-uart0 + +Dieses Programm leitet die über die UART1 Schnittstelle eintreffenden Bytes auf die UART0 Schnittstelle um. + +UART Modus: 115200/8N1 + + diff --git a/software/uart1-to-uart0/src/main.c b/software/uart1-to-uart0/src/main.c new file mode 100644 index 0000000..9f7379b --- /dev/null +++ b/software/uart1-to-uart0/src/main.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +int uart_putchar(char c, FILE *stream) { + if (c == '\n') { + uart_putchar('\r', stream); + } + loop_until_bit_is_set(UCSR0A, UDRE0); + if (stream == stdout) { + UDR0 = c; + } else { + 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 = 0; + + TCCR1B = (1 << WGM12) | (1 << CS11); + OCR1A = 1500; + TIMSK1 = (1 << OCIE1A); + + UCSR0A = (1 << U2X0); + UCSR0B = (1 << RXCIE0) | (1 << RXEN0) | (1 < UART0 ready\n"); + + while (1) { + } +} + +ISR (USART0_RX_vect) { + PORTC ^= (1 << PC3); + uint8_t b = UDR0; +} + +ISR (USART1_RX_vect) { + PORTC ^= (1 << PC2); + uint8_t b = UDR1; + UDR0 = b; +} + + +ISR (TIMER1_COMPA_vect) { + static uint16_t timer = 0; + timer++; + if (timer >= 1000) { + PORTC ^= (1 << PC4); + timer = 0; + } +} + -- 2.39.5