From 245f7939a2c160a5df9fb93e2d55f22408cfc2b1 Mon Sep 17 00:00:00 2001 From: Manfred Steiner Date: Fri, 8 Nov 2024 18:00:08 +0100 Subject: [PATCH] Inbetriebnahme Nano-1284(V2a), Problem-Fix unit CC1101, Makefile fix --- .../.vscode/c_cpp_properties.json | 4 +-- software/test-software/nano-1284/Makefile | 8 ++--- software/test-software/nano-328/Makefile | 8 ++--- software/test-software/nano-644/Makefile | 8 ++--- software/test-software/src/main.cpp | 31 +++++++++++-------- software/test-software/src/units/cc1101.cpp | 23 ++++++++++---- software/test-software/src/units/cc1101.hpp | 5 +-- 7 files changed, 52 insertions(+), 35 deletions(-) diff --git a/software/test-software/.vscode/c_cpp_properties.json b/software/test-software/.vscode/c_cpp_properties.json index 3a57c79..87fd0ec 100644 --- a/software/test-software/.vscode/c_cpp_properties.json +++ b/software/test-software/.vscode/c_cpp_properties.json @@ -7,8 +7,8 @@ "/usr/lib/gcc/avr/**" ], "defines": [], - "compilerPath": "/usr/bin/avr-gcc", - "compilerArgs": [ "-mmcu=atmega644p", "-DF_CPU=12000000", "-Os" ], + "compilerPath": "/usr/bin/avr-g++", + "compilerArgs": [ "-mmcu=atmega1284p", "-DF_CPU=12000000", "-Os" ], "cStandard": "gnu11", "cppStandard": "gnu++11", "intelliSenseMode": "linux-gcc-x64" diff --git a/software/test-software/nano-1284/Makefile b/software/test-software/nano-1284/Makefile index 8485c67..5edd2d2 100644 --- a/software/test-software/nano-1284/Makefile +++ b/software/test-software/nano-1284/Makefile @@ -27,12 +27,12 @@ OBJ_SIM = $(OBJ_SIM_CPP:src/%.c=sim/build/%.o) CC= avr-g++ CFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -DBAUD_RATE=$(BAUDRATE) -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c -#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,-u,vfprintf -lprintf_flt -lm -LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS) +LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS) -Wl,-u,vfprintf -lprintf_flt -lm +#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS) CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -DBAUD_RATE=$(BAUDRATE) -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c -#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,-u,vfprintf -lprintf_flt -lm -LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS) +LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS) -Wl,-u,vfprintf -lprintf_flt -lm +#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS) # -------------------------------------------------------------------------------- # make targets diff --git a/software/test-software/nano-328/Makefile b/software/test-software/nano-328/Makefile index be62fec..e0fb4c6 100644 --- a/software/test-software/nano-328/Makefile +++ b/software/test-software/nano-328/Makefile @@ -27,12 +27,12 @@ OBJ_SIM = $(OBJ_SIM_CPP:src/%.c=sim/build/%.o) CC= avr-g++ CFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -DBAUD_RATE=$(BAUDRATE) -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c -#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,-u,vfprintf -lprintf_flt -lm -LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS) +LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS) -Wl,-u,vfprintf -lprintf_flt -lm +#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS) CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -DBAUD_RATE=$(BAUDRATE) -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c -#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,-u,vfprintf -lprintf_flt -lm -LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS) +LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS) -Wl,-u,vfprintf -lprintf_flt -lm +#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS) # -------------------------------------------------------------------------------- # make targets diff --git a/software/test-software/nano-644/Makefile b/software/test-software/nano-644/Makefile index 75c25e3..6d0033e 100644 --- a/software/test-software/nano-644/Makefile +++ b/software/test-software/nano-644/Makefile @@ -27,12 +27,12 @@ OBJ_SIM = $(OBJ_SIM_CPP:src/%.c=sim/build/%.o) CC= avr-g++ CFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -DBAUD_RATE=$(BAUDRATE) -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c -#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,-u,vfprintf -lprintf_flt -lm -LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS) +LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS) -Wl,-u,vfprintf -lprintf_flt -lm +#LFLAGS= -Wall -mmcu=$(DEVICE) -Os -DF_CPU=$(CPU_FREQUENCY) -Wl,--section-start=.text=$(START_ADDRESS) CFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -DBAUD_RATE=$(BAUDRATE) -DDOUBLE_SPEED -DNUM_LED_FLASHES=4 '-DMAX_TIME_COUNT=F_CPU>>4' -c -#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,-u,vfprintf -lprintf_flt -lm -LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS) +LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS) -Wl,-u,vfprintf -lprintf_flt -lm +#LFLAGS_SIM= -Wall -mmcu=$(DEVICE) -Og -DF_CPU=$(CPU_FREQUENCY) -g -Wl,--section-start=.text=$(START_ADDRESS) # -------------------------------------------------------------------------------- # make targets diff --git a/software/test-software/src/main.cpp b/software/test-software/src/main.cpp index 2a7faec..4f0fbb0 100644 --- a/software/test-software/src/main.cpp +++ b/software/test-software/src/main.cpp @@ -205,12 +205,13 @@ uint8_t detectHardwareVersion () { if (hardwareVersion < 1 || hardwareVersion > 2) { #ifdef __AVR_ATmega644P__ - printf_P(PSTR("\nInvalid Hardware-Version: ADC7H = %d (ATmega644P, 3.3V)\n"), ADCH); + printf_P(PSTR("\nInvalid Nano-X-Base Hardware-Version: ADC7H = %d (ATmega644P, 3.3V)\n"), ADCH); #elif __AVR_ATmega1284P__ - printf_P(PSTR("\nInvalid Hardware-Version: ADC7H = %d (ATmega1284P, 3.3V)\n"), ADCH); + printf_P(PSTR("\nInvalid Nano-X-Base Hardware-Version: ADC7H = %d (ATmega1284P, 3.3V)\n"), ADCH); #elif __AVR_ATmega328P__ - printf_P(PSTR("\nInvalid Hardware-Version: ADC7H = %d (ATmega328P, 5V)\n"), ADCH); + printf_P(PSTR("\nInvalid Nano-X-Base Hardware-Version: ADC7H = %d (ATmega328P, 5V)\n"), ADCH); #endif + hardwareVersion = 0; } else { // const char *pHw; memcpy_P(&pHw, PSTR_HARDWARE + hardwareVersion - 1, sizeof(const char *)); printf_P(PSTR("\n\nHardware %S detected (ADC7H=0x%02X)"), hardwareVersionPStr(hardwareVersion), ADCH); @@ -279,21 +280,26 @@ int main () { sei(); + detectHardwareVersion(); + + uint8_t units; #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 + &uart1, &i2cMaster, &i2cSlave, &i2cSparkfun, &rtc8563, &cc1101Send, &cc1101Receive, + &led, &sw, &rgb, &seg7, &poti, &encoder, &r2r, &motor, &portExp, &lcd, &modbus, &ieee485 }; + units = hardwareVersion == 0 ? 7 : sizeof(unit) / sizeof(unit[0]); #endif #ifdef __AVR_ATmega328P__ TestUnit *unit[] = { - &led, &sw, &rgb, &seg7, &poti, &encoder, &r2r, &motor, &portExp, &lcd, - &i2cMaster, &i2cSlave, &i2cSparkfun + &i2cMaster, &i2cSlave, &i2cSparkfun, + &led, &sw, &rgb, &seg7, &poti, &encoder, &r2r, &motor, &portExp, &lcd }; + units = hardwareVersion == 0 ? 3 : sizeof(unit) / sizeof(unit[0]); #endif - detectHardwareVersion(); + while (1) { uint16_t i; @@ -306,15 +312,14 @@ int main () { printf_P(MAIN_CPP_TIME); printf_P(PSTR_DIVIDER); if (hardwareVersion >= 1 && hardwareVersion <= 2) { - printf_P(PSTR("Hardware: %S"), hardwareVersionPStr(hardwareVersion)); + printf_P(PSTR("Nano-X-Base: %S"), hardwareVersionPStr(hardwareVersion)); } else { - printf_P(PSTR("ERROR: Invalid Hardware (%d)"), hardwareVersion); - for(;;); + printf_P(PSTR("No Nano-X-Base detected")); } printf_P(PSTR_DIVIDER); printf_P(PSTR_LINEFEED); printf_P(PSTR("Available units:\n\n")); - for (i = 0; i < sizeof(unit) / sizeof(unit[0]); i++) { + for (i = 0; i < units; i++) { TestUnit *pu = unit[i]; printf_P(PSTR("%3x ... "), i); printf_P(pu->getName()); @@ -323,7 +328,7 @@ int main () { printf_P(PSTR("\nSelect unit: ")); rIndex = 0; wIndex = 0; fgets(s, sizeof(s), stdin); - } while (sscanf(s, "%x", &i) != 1 || i < 0 || i >= sizeof(unit) / sizeof(unit[0]) ); + } while (sscanf(s, "%x", &i) != 1 || i < 0 || i >= units ); TestUnit *pu = unit[i]; printf_P(PSTR("\n\n[")); printf_P(pu->getName()); printf_P(PSTR("]: ")); diff --git a/software/test-software/src/units/cc1101.cpp b/software/test-software/src/units/cc1101.cpp index aebe713..039c94d 100644 --- a/software/test-software/src/units/cc1101.cpp +++ b/software/test-software/src/units/cc1101.cpp @@ -283,6 +283,9 @@ int8_t Cc1101::run (uint8_t subtest) { + if (!initDone) { + return -1; + } switch (mode) { case Send: return runSend(subtest); case Receive: return runReceive(subtest); @@ -320,16 +323,19 @@ void Cc1101::init () { + // trigger for debugging + PORTB &= ~(1 << PB0); + DDRB |= ( 1 << PB0); + #ifdef __AVR_ATmega1284P__ // Nano-1284 + triggerOn(); DDRC |= (1 << PC6); PORTC |= (1 << PC6); // modem voltage 3.3V ON + _delay_us(100); + triggerOff(); #endif - // trigger for debugging - PORTB &= ~(1 << PB0); - DDRB |= ( 1 << PB0); - PRR0 &= (1 << PRSPI); // nCs @@ -364,6 +370,7 @@ return; } printf_P(PSTR("OK")); + initDone = true; debugPrint.byte = 0xff; // print all printRegisters(); @@ -387,13 +394,19 @@ DDRC &= ~(1 << PC6); PORTC &= ~(1 << PC6); // modem voltage 3.3V OFF #endif + + initDone = false; } void Cc1101::setChipEnableLow () { + triggerOn(); PORTA &= ~(1 << PA4); + // _delay_us(20); // measurement shows -> delay not needed } void Cc1101::setChipEnableHigh () { + triggerOff(); + _delay_us(40); // measurement shows -> delay needed before(!) signal rises high PORTA |= (1 << PA4); } @@ -707,8 +720,6 @@ ok &= waitForMisoLow(); ok &= strobe(SRES); ok &= waitForMisoLow(); - - return ok; } diff --git a/software/test-software/src/units/cc1101.hpp b/software/test-software/src/units/cc1101.hpp index a861f09..3a51ccc 100644 --- a/software/test-software/src/units/cc1101.hpp +++ b/software/test-software/src/units/cc1101.hpp @@ -32,7 +32,7 @@ class Cc1101 : public TestUnit { } status; public: - Cc1101 (Cc1101Mode mode) { timer = 0; this->mode = mode; status.dword = 0; } + Cc1101 (Cc1101Mode mode) { timer = 0; this->mode = mode; status.dword = 0; initDone = false; } virtual void init (); virtual void cleanup (); virtual int8_t run (uint8_t subtest); @@ -77,8 +77,9 @@ class Cc1101 : public TestUnit { private: + bool initDone; Cc1101Mode mode; - uint8_t timer; + volatile uint8_t timer; union { DebugPrint_t print; uint8_t byte; -- 2.39.5