--- /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/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"
+ ],
+ "java.project.sourcePaths": [
+ "src/units"
+ ]
+}
--- /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)
+$(shell mkdir -p sim/build >/dev/null)
+
+NAME=test_2024-07-23_nano-1284p
+SRC= $(wildcard src/*.c src/*.cpp src/*/*.c src/*/*.cpp)
+HDR= $(wildcard src/*.h src/*.hpp src/*/*.h src/*/*.hpp)
+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)
+
+DEVICE=atmega1284p
+AVRDUDE_DEVICE=m1284p
+
+CC= avr-g++
+CFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000 -c
+LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=12000000 -Wl,-u,vfprintf -lprintf_flt -lm
+
+CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=12000000 -g -c -c
+LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=12000000 -g -Wl,-u,vfprintf -lprintf_flt -lm
+
+
+all: dist/$(NAME).elf dist/$(NAME).s dist/$(NAME).hex sim/$(NAME).elf sim/$(NAME).s info
+
+info:
+ @avr-size --mcu=$(DEVICE) --format=avr dist/$(NAME).elf
+
+.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
+
+-include .depend
+
+# .depend solte auch auf Header Files achten!
+
+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)
+
+# ensure that __DATE__ and __TIME__ macros are up to date
+build/main.o: src/main.cpp $(SRC) $(HDR)
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) -o $@ $<
+
+build/%.o: src/%.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) -o $@ $<
+
+build/%.o: src/%.cpp
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) -o $@ $<
+
+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 $< > $@
+
+simuc: sim/$(NAME).elf
+ simuc --board nano-1284 $<
+
+gdb: sim/$(NAME).elf
+ avr-gdb $<
+
+
+flash: dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB0 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash0: dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB0 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash1: dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB1 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash2: dist/$(NAME).elf all
+ avrdude -c arduino -P /dev/ttyUSB2 -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+picocom:
+ # picocom sends CR for ENTER -> convert cr (\r) to lf (\n)
+ 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
+
+
+isp-1284p:
+ avrdude -c usbasp -p $(AVRDUDE_DEVICE)
+
+isp-flash-1284p: dist/$(NAME).elf all
+ avrdude -c usbasp -p $(AVRDUDE_DEVICE) -e -U flash:w:$<
+
+flash-1284p: dist/$(NAME).elf all
+ avrdude -c arduino -p $(AVRDUDE_DEVICE) -P /dev/ttyUSB0 -b 115200 -e -U flash:w:$<
+
+isp-fuse-1284p:
+ avrdude -c usbasp -p $(AVRDUDE_DEVICE) -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xFF:m -U lock: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 für Nano-1284
--- /dev/null
+../../nano-644/test_2024-07-23/src
\ No newline at end of file
#include "units/rtc8563.hpp"
#include "units/cc1101.hpp"
-
const char MAIN_CPP_DATE[] PROGMEM = __DATE__;
const char MAIN_CPP_TIME[] PROGMEM = __TIME__;
+#ifdef __AVR_ATmega328P__
+ const char MAIN_CPP_PART_NAME[] PROGMEM = "ATmega328P";
+#endif
+#ifdef __AVR_ATmega644P__
+ const char MAIN_CPP_PART_NAME[] PROGMEM = "ATmega644P";
+#endif
+#ifdef __AVR_ATmega1284P__
+ const char MAIN_CPP_PART_NAME[] PROGMEM = "ATmega1284P";
+#endif
+
+const char DIVIDER[] PROGMEM = "\n====================================\n ";
+const char LINEFEED[] PROGMEM = "\n";
extern "C" {
void __cxa_pure_virtual () {}
static FILE mystdout = { 0, 0, _FDEV_SETUP_WRITE , 0, 0, uart_putchar, NULL, 0 };
static FILE mystdin = { 0, 0, _FDEV_SETUP_READ , 0, 0, NULL, uart_getchar, 0 };
- #ifdef __AVR_ATmega644P__
+ #if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
static volatile uint16_t timerFlashGreenLed = 0;
static volatile uint16_t timerFlashRedLed = 0;
void flashRedLed (uint16_t ms) {
int main () {
- #ifdef __AVR_ATmega644P__
+ #if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// Nano-644 LEDs (Green, Orange, Red)
DDRC |= (1 << DDC4) | (1 << DDC3) | (1 << DDC2);
PORTC &= ~((1 << PORT4) | (1 << PORT3) | (1 << PORT2));
sei();
- #ifdef __AVR_ATmega644P__
+ #if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
TestUnit *unit[] = {
&led, &sw, &rgb, &seg7, &poti, &encoder, &r2r, &motor, &portExp, &lcd, &uart1, &modbus, &ieee485,
&i2cMaster, &i2cSlave, &i2cSparkfun, &rtc8563, &cc1101Send, &cc1101Receive
uint16_t i;
char s[4];
do {
- printf_P(PSTR("\n"));
- printf_P(PSTR("\n=================================\n"));
- printf_P(PSTR(" Version: "));
+ printf_P(LINEFEED);
+ printf_P(DIVIDER);
+ printf_P(MAIN_CPP_PART_NAME); printf_P(PSTR(" / "));
printf_P(MAIN_CPP_DATE); printf_P(PSTR(" / "));
printf_P(MAIN_CPP_TIME);
- printf_P(PSTR("\n=================================\n"));
- printf_P(PSTR("\n"));
+ printf_P(DIVIDER);
+ printf_P(LINEFEED);
printf_P(PSTR("Available units:\n\n"));
for (i = 0; i < sizeof(unit) / sizeof(unit[0]); i++) {
TestUnit *pu = unit[i];
printf_P(PSTR("%3x ... "), i);
printf_P(pu->getName());
- printf_P(PSTR("\n"));
+ printf_P(LINEFEED);
}
printf_P(PSTR("\nSelect unit: "));
rIndex = 0; wIndex = 0;
i2cSparkfun.tick1ms();
cc1101Send.tick1ms();
cc1101Receive.tick1ms();
- #ifdef __AVR_ATmega644P__
+ #if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
if (timerFlashRedLed > 0) {
if (--timerFlashRedLed < 128) {
PORTC &= ~(1 << PC2); // red LED
timer500ms++;
if (timer500ms >= 5000) {
- #ifdef __AVR_ATmega644P__
+ #if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
PORTC ^= (1 << PC3); // orange LED blinking
#endif
#ifdef __AVR_ATmega328P__
extern int waitAndReadKey (uint32_t ms);
extern uint64_t millis ();
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
extern "C" {
extern void flashRedLed (uint16_t ms);
extern void flashGreenLed (uint16_t ms);
#endif
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// Nano-644
// --------------------------------------------------------
PORTB &= ~(1 << PB0);
DDRB |= ( 1 << PB0);
- PRR &= (1 << PRSPI);
+ PRR0 &= (1 << PRSPI);
// nCs
PORTA |= (1 << PA4);
// B --______-----
// one step when: A = 0, B= 0->1
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// Nano-644
// ---------------------------------------------------------------
#endif
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// Nano-644
// ------------------------------------
#include "lcd.hpp"
#include "../main.hpp"
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// Nano-644
// ---------------------------------------------------------------
#include "led.hpp"
#include "../main.hpp"
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// Nano-644
// ---------------------------------------------------------------
void Modbus::handleRxByte (uint8_t b) {}
#endif
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// PB0 ... nRE .. Read enable
// PB1 ... DE .. Data enable
#include "motor.hpp"
#include "../main.hpp"
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// Nano-644
// ---------------------------------------------------------------
// GPA6 | IO16O1 (PA1) | L-Gelb | | GPB6 | IO16U1 (PC1) | O-Gelb |
// GPA7 | IO16O0 (PA0) | L-Rot | | GPB7 | IO16U0 (PC0) | O-Rot |
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// Nano-644
// --------------------------------------------------------
// PB7 ... SCK
void PortExp::init () {
- PRR &= (1 << PRSPI);
+ PRR0 &= (1 << PRSPI);
PORTA |= (1 << PA7);
DDRA |= (1 << PA7); // SPI nCS
// PORTB/DDRB must be configured before SPCR !!
#include "r2r.hpp"
#include "../main.hpp"
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// AVCC=3.3, POTI Vmax=3.3V
#define K 1.0
#endif
#include "rgb.hpp"
#include "../main.hpp"
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// Nano-644
// ---------------------------------------------------------------
int8_t Rtc8563::run (uint8_t subtest) { return -1; }
#endif
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
void Rtc8563::init () {
PORTC |= (1 << PC7); // nInt
#include "seg7.hpp"
#include "../main.hpp"
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// Nano-644
// ---------------------------------------------------------------
#include "switch.hpp"
#include "../main.hpp"
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// Nano-644
// ---------------------------------------------------------------
void Uart1::handleRxByte (uint8_t b) {}
#endif
-#ifdef __AVR_ATmega644P__
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
int uart1_putchar(char c, FILE *stream) {
if (c == '\n') {