Commit b0e26a9e9aca0f6831d4e63355f0b36ff95aeedd
receivedMon, 22. Jul 2024, 18:59:28 (by user sx)
Mon, 22 Jul 2024 16:59:28 +0000 (18:59 +0200)
authorManfred Steiner <sx@htl-kaindorf.at>
Mon, 22 Jul 2024 16:59:20 +0000 (18:59 +0200)
committerManfred Steiner <sx@htl-kaindorf.at>
Mon, 22 Jul 2024 16:59:20 +0000 (18:59 +0200)
14 files changed:
software/gdb-stub/.gdbinit-gdbstub
software/gdb-stub/Makefile
software/gdb-stub/src/blgdb.h
software/gdb-stub/src/bootloader.cpp
software/test-2024-07-22/.gdb_history [new file with mode: 0644]
software/test-2024-07-22/.gdbinit [new file with mode: 0644]
software/test-2024-07-22/.gitignore [new file with mode: 0644]
software/test-2024-07-22/.vscode/c_cpp_properties.json [new file with mode: 0644]
software/test-2024-07-22/.vscode/launch.json [new file with mode: 0644]
software/test-2024-07-22/.vscode/settings.json [new file with mode: 0644]
software/test-2024-07-22/.vscode/tasks.json [new file with mode: 0644]
software/test-2024-07-22/Makefile [new file with mode: 0644]
software/test-2024-07-22/README.md [new file with mode: 0644]
software/test-2024-07-22/src/main.c [new file with mode: 0644]

index 838e6f332d57870545500b3996bbab43dccc36b5..0f63869c96afc065e6f8ef6bbd2bcfcc0f6444a7 100644 (file)
@@ -5,5 +5,8 @@ focus cmd
 #br gdb.cpp:296
 #br gdb.cpp:317
 #br gdb.cpp:325
-br bootloader.cpp:150
+#br *0x40
+#br *0xe040
+#br *0xe0d6
+#br bootloader.cpp:150
 
index f7d4a6790470dfeed4f843c0cfee2fed010e09cb..a595000fce02707cc99bd52d7de9d81e85e4267c 100644 (file)
@@ -13,7 +13,7 @@ SECTION_BOOTLOADER = 0xE004
 ## Intel Hex file production flags
 HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature
 
-CFLAGS = -g -DF_CPU=12000000L -Og -Wall -gdwarf-2
+CFLAGS = -g -DF_CPU=12000000L -Os -Wall -gdwarf-2
 LFLAGS = -gdwarf-2
 LFLAGS += -Wl,-Tldscripts/ldscript_atmega644p.x
 
index 7437c8ec3380238850c04b19625cb2ef44d8c9f2..7c9f946d1131deea20d660ec56f72da02e396c36 100644 (file)
 
 
 
-#define blgdb_init()                 asm volatile ( "jmp 0xe002" )
-#define blgdb_main()                 asm volatile ( "call 0xe004 \n  ret \n" )
-#define blgdb_stop()                 asm volatile ( "call 0xe006 \n  ret \n" )
-#define blgdb_handleUartIsrByte(b)   asm volatile ( "jmp 0xe008" )
-#define blgdb_printWelcomeMessage()  asm volatile ( "jmp 0xe00a" )
-#define blgdb_putchar(c)             ( (*(( void (*)(uint8_t) ) (0xe00c / 2) )) (c) )
-#define blgdb_puts(s)                ( (*(( void (*)(const char *) ) (0xe00e / 2) )) (s) );
-#define blgdb_putUint8Hex(value)     ( (*(( void (*)(uint8_t) ) (0xe010 / 2) )) (value) )
-#define blgdb_memputc(p)             ( (*(( void (*)(PGM_P) ) (0xe012 / 2) )) (p) )
-#define blgdb_memputs(p)             ( (*(( void (*)(PGM_P) ) (0xe014 / 2) )) (p) )
-#define blgdb_serve500msTimer()      asm volatile ( "jmp 0xe016" )
+#define blgdb_init()                 asm volatile ( "jmp 0xe082" )
+#define blgdb_main()                 asm volatile ( "call 0xe084 \n  ret \n" )
+#define blgdb_stop()                 asm volatile ( "call 0xe086 \n  ret \n" )
+#define blgdb_handleUartIsrByte(b)   asm volatile ( "jmp 0xe088" )
+#define blgdb_printWelcomeMessage()  asm volatile ( "jmp 0xe08a" )
+#define blgdb_putchar(c)             ( (*(( void (*)(uint8_t) ) (0xe08c / 2) )) (c) )
+#define blgdb_puts(s)                ( (*(( void (*)(const char *) ) (0xe08e / 2) )) (s) );
+#define blgdb_putUint8Hex(value)     ( (*(( void (*)(uint8_t) ) (0xe090 / 2) )) (value) )
+#define blgdb_memputc(p)             ( (*(( void (*)(PGM_P) ) (0xe092 / 2) )) (p) )
+#define blgdb_memputs(p)             ( (*(( void (*)(PGM_P) ) (0xe094 / 2) )) (p) )
+#define blgdb_serve500msTimer()      asm volatile ( "jmp 0xe096" )
 
 namespace blgdb {
 
index b6462990c8bffb9b1d10a0ab5ea0c6cf42396a59..260b1f4a156876a679b88f72f9d1930ed8a7e1ec 100644 (file)
@@ -39,6 +39,43 @@ namespace bootloader {
 
        void __attribute__ ((naked)) bootloaderStart () {
                asm volatile (
+                       "__bootloader_vector_table:         \n"
+                       "jmp __bootloader_start_from_reset  \n" //; 0xa6 <__ctors_end>
+                       "jmp _bad_interrupt                 \n" // 0xe004  vector  2 (INT0)
+                       "jmp _bad_interrupt                 \n" // 0xe008  vector  3 (INT1)
+                       "jmp _bad_interrupt                 \n" // 0xe00c  vector  4 (INT2)
+                       "jmp _bad_interrupt                 \n" // 0xe010  vector  5 (PCINT0)
+                       "jmp _bad_interrupt                 \n" // 0xe014  vector  6 (PCINT1)
+                       "jmp _bad_interrupt                 \n" // 0xe018  vector  7 (PCINT2)
+                       "jmp _bad_interrupt                 \n" // 0xe01c  vector  8 (PCINT3)
+                       "jmp _bad_interrupt                 \n" // 0xe020  vector  9 (WDT)
+                       "jmp _bad_interrupt                 \n" // 0xe024  vector 10 (TIMER2_COMPA)
+                       "jmp _bad_interrupt                 \n" // 0xe028  vector 11 (TIMER2_COMPB)
+                       "jmp _bad_interrupt                 \n" // 0xe02c  vector 12 (TIMER2_OVF)
+                       "jmp _bad_interrupt                 \n" // 0xe030  vector 13 (TIMER1_CAPT)
+                       "jmp _bad_interrupt                 \n" // 0xe034  vector 14 (TIMER1_COMPA)
+                       "jmp _bad_interrupt                 \n" // 0xe038  vector 15 (TIMER1_COMPB)
+                       "jmp _bad_interrupt                 \n" // 0xe03c  vector 16 (TIMER1_OVF)
+                       "jmp _bad_interrupt                 \n" // 0xe040  vector 17 (TIMER0_COMPA)
+                       "jmp _bad_interrupt                 \n" // 0xe044  vector 18 (TIMER0_COMPB)
+                       "jmp _bad_interrupt                 \n" // 0xe048  vector 19 (TIMER0_OVF)
+                       "jmp _bad_interrupt                 \n" // 0xe04c  vector 20 (SPI_STC)
+                       "jmp _bad_interrupt                 \n" // 0xe050  vector 21 (USART0_RX)
+                       "jmp _bad_interrupt                 \n" // 0xe054  vector 22 (USART0_UDRE)
+                       "jmp _bad_interrupt                 \n" // 0xe058  vector 23 (USART0_TX)
+                       "jmp _bad_interrupt                 \n" // 0xe05c  vector 24 (ANALOG_COMP)
+                       "jmp _bad_interrupt                 \n" // 0xe060  vector 25 (ADC)
+                       "jmp _bad_interrupt                 \n" // 0xe064  vector 26 (EE_READY)
+                       "jmp _bad_interrupt                 \n" // 0xe068  vector 27 (TWI)
+                       "jmp _bad_interrupt                 \n" // 0xe06c  vector 28 (SPM_READY)
+                       "jmp __vector_jmpTableIsrUsart1     \n" // 0xe070  vector 29 (USART1_RX)
+                       "jmp _bad_interrupt                 \n" // 0xe074  vector 30 (USART1_UDRE)
+                       "jmp _bad_interrupt                 \n" // 0xe078  vector 31 (USART1_TX)
+
+                       "_bad_interrupt:"
+                               "cli \n"
+                               "rjmp _bad_interrupt \n"
+
                        "__bootloader_start:                \n"
                        "rjmp __bootloader_start_from_reset \n"  // 0xe000
                        "rjmp __bootloader_start_from_app   \n"  // 0xe002
@@ -85,6 +122,8 @@ namespace bootloader {
                        "out  0x3d, r28   \n"  // SPL = 0xFF
                        "nop              \n"
                );
+               MCUCR = ( 1 << IVCE);
+               MCUCR = ( 1 << IVSEL); // switch interrupt vector table to bootloader
 
                bootloaderStartFromReset2();
                bootloaderLoop();
@@ -149,7 +188,8 @@ namespace bootloader {
                                main();
                        #else
                                cli();
-                               setLedGreen(1); setLedOrange(0); setLedRed(0);
+                               PORTC = 0;
+                               DDRC = 0;
                                UCSR0A = 0;
                                UCSR0B = 0;
                                UCSR0C = 0;
@@ -162,6 +202,8 @@ namespace bootloader {
                                UBRR1H = 0;
                                TCCR1A = 0;
                                TCCR1B = 0;
+                               MCUCR = (1 << IVCE);
+                               MCUCR = 0; // interrupt vector table to application area
 
                                asm volatile (
                                        "jmp 0x0000" // start application
diff --git a/software/test-2024-07-22/.gdb_history b/software/test-2024-07-22/.gdb_history
new file mode 100644 (file)
index 0000000..3339046
--- /dev/null
@@ -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/test-2024-07-22/.gdbinit b/software/test-2024-07-22/.gdbinit
new file mode 100644 (file)
index 0000000..a8c4b59
--- /dev/null
@@ -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/test-2024-07-22/.gitignore b/software/test-2024-07-22/.gitignore
new file mode 100644 (file)
index 0000000..a959910
--- /dev/null
@@ -0,0 +1,4 @@
+.depend
+**/build
+**/dist
+**/sim
diff --git a/software/test-2024-07-22/.vscode/c_cpp_properties.json b/software/test-2024-07-22/.vscode/c_cpp_properties.json
new file mode 100644 (file)
index 0000000..3a57c79
--- /dev/null
@@ -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/test-2024-07-22/.vscode/launch.json b/software/test-2024-07-22/.vscode/launch.json
new file mode 100644 (file)
index 0000000..f29cf2e
--- /dev/null
@@ -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/test-2024-07-22/.vscode/settings.json b/software/test-2024-07-22/.vscode/settings.json
new file mode 100644 (file)
index 0000000..4448dde
--- /dev/null
@@ -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/test-2024-07-22/.vscode/tasks.json b/software/test-2024-07-22/.vscode/tasks.json
new file mode 100644 (file)
index 0000000..74fb1c7
--- /dev/null
@@ -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/test-2024-07-22/Makefile b/software/test-2024-07-22/Makefile
new file mode 100644 (file)
index 0000000..3f31bab
--- /dev/null
@@ -0,0 +1,77 @@
+.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-nano-644"
+SRC= $(wildcard src/*.c) 
+OBJ = $(SRC:src/%.c=build/%.o)
+OBJ_SIM = $(SRC:src/%.c=sim/%.o)
+
+CC= avr-gcc
+CFLAGS= -Wall -mmcu=atmega644p -Os -DF_CPU=12000000 -c
+LFLAGS= -Wall -mmcu=atmega644p -Os -DF_CPU=12000000
+
+CFLAGS_SIM= -Wall -mmcu=atmega644p -O0 -DF_CPU=12000000 -g -c
+LFLAGS_SIM= -Wall -mmcu=atmega644p -O0 -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=atmega644p --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"
diff --git a/software/test-2024-07-22/README.md b/software/test-2024-07-22/README.md
new file mode 100644 (file)
index 0000000..589f7aa
--- /dev/null
@@ -0,0 +1 @@
+# Testprogramm Erstinbetriebnahme
diff --git a/software/test-2024-07-22/src/main.c b/software/test-2024-07-22/src/main.c
new file mode 100644 (file)
index 0000000..f6f65c7
--- /dev/null
@@ -0,0 +1,98 @@
+#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);
+   }
+   loop_until_bit_is_set(UCSR0A, UDRE0);
+   UDR0 = 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;
+   stdout = &mystdout;
+   stderr = &mystderr;
+
+
+   uint16_t cnt = 0;
+   while (1) {
+      _delay_ms(500);
+      PORTC ^= 0x1C;
+      printf("%04x: Hello world\n", cnt++);
+   }
+
+   // 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;
+//    }
+// }
+