From 3a2102a9e028adef150e23d9e83331f6b02c437c Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Tue, 11 Oct 2022 07:56:22 +0200 Subject: [PATCH 01/18] clean setup for Raspberry Pico --- _Boards/RaspberryPi/Pico/MFBoards.h | 59 +++++ .../Pico/raspberry_pico.board.json | 213 ++++++++++++++++++ platformio.ini | 37 ++- src/MF_Modules/MFEEPROM.cpp | 10 + 4 files changed, 315 insertions(+), 4 deletions(-) create mode 100644 _Boards/RaspberryPi/Pico/MFBoards.h create mode 100644 _Boards/RaspberryPi/Pico/raspberry_pico.board.json diff --git a/_Boards/RaspberryPi/Pico/MFBoards.h b/_Boards/RaspberryPi/Pico/MFBoards.h new file mode 100644 index 00000000..040465c0 --- /dev/null +++ b/_Boards/RaspberryPi/Pico/MFBoards.h @@ -0,0 +1,59 @@ +#ifndef MFBoardMicro_h +#define MFBoardMicro_h + +#ifndef MF_SEGMENT_SUPPORT +#define MF_SEGMENT_SUPPORT 1 +#endif +#ifndef MF_LCD_SUPPORT +#define MF_LCD_SUPPORT 1 +#endif +#ifndef MF_STEPPER_SUPPORT +#define MF_STEPPER_SUPPORT 1 +#endif +#ifndef MF_SERVO_SUPPORT +#define MF_SERVO_SUPPORT 1 +#endif +#ifndef MF_ANALOG_SUPPORT +#define MF_ANALOG_SUPPORT 1 +#endif +#ifndef MF_OUTPUT_SHIFTER_SUPPORT +#define MF_OUTPUT_SHIFTER_SUPPORT 1 +#endif +#ifndef MF_INPUT_SHIFTER_SUPPORT +#define MF_INPUT_SHIFTER_SUPPORT 1 +#endif +#ifndef MF_MUX_SUPPORT +#define MF_MUX_SUPPORT 1 +#endif +#ifndef MF_DIGIN_MUX_SUPPORT +#define MF_MUX_SUPPORT 1 +#define MF_DIGIN_MUX_SUPPORT 1 +#endif + +#define MAX_OUTPUTS 15 +#define MAX_BUTTONS 26 +#define MAX_LEDSEGMENTS 2 +#define MAX_ENCODERS 12 +#define MAX_STEPPERS 4 +#define MAX_MFSERVOS 4 +#define MAX_MFLCD_I2C 2 +#define MAX_ANALOG_INPUTS 3 +#define MAX_OUTPUT_SHIFTERS 4 +#define MAX_INPUT_SHIFTERS 4 +#define MAX_DIGIN_MUX 2 + +#define STEPS 64 +#define STEPPER_SPEED 400 // 300 already worked, 467, too? +#define STEPPER_ACCEL 800 + +#define MOBIFLIGHT_TYPE "MobiFlight RaspiPico" +#define MOBIFLIGHT_SERIAL "0987654321" +#define MOBIFLIGHT_NAME "MobiFlight RaspiPico" +#define EEPROM_SIZE 4096 // EEPROMSizeRaspberryPico +#define MEMLEN_CONFIG 1496 // MUST be less than EEPROM_SIZE!! MEM_OFFSET_CONFIG + MEM_LEN_CONFIG <= EEPROM_SIZE, see: eeprom_write_block (MEM_OFFSET_CONFIG, configBuffer, MEM_LEN_CONFIG); +#define MEMLEN_NAMES_BUFFER 1000 // max. size for configBuffer, contains only names from inputs +#define MF_MAX_DEVICEMEM 2000 // max. memory size for devices + +#define RANDOM_SEED_INPUT A0 // better to have randomSeed(analogRead(RANDOM_SEED_INPUT)); in generateSerial(), "0" is not valid for all HW platforms + +#endif diff --git a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json new file mode 100644 index 00000000..93464f99 --- /dev/null +++ b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json @@ -0,0 +1,213 @@ +{ + "$schema": "./mfboard.schema.json", + "AvrDudeSettings": { + "Device": "RaspiPico", + "BaudRate": "115200", + "Programmer": "arduino", + "FirmwareBaseName": "mobiflight_raspberrypico", + "Timeout": 15000 + }, + "Connection": { + "ConnectionDelay": 1250, + "DelayAfterFirmwareUpdate": 1250, + "DtrEnable": true, + "EEPROMSize": 1496, + "ExtraConnectionRetry": false, + "ForceResetOnFirmwareUpdate": true, + "MessageSize": 64 + }, + "HardwareIds": ["^VID_2E8A&PID_000A"], + "Info": { + "CanInstallFirmware": true, + "FriendlyName": "RaspiPico", + "LatestFirmwareVersion": "2.2.2", + "MobiFlightType": "MobiFlight RaspiPico" + }, + "ModuleLimits": { + "MaxAnalogInputs": 16, + "MaxInputShifters": 4, + "MaxButtons": 68, + "MaxEncoders": 20, + "MaxLcdI2C": 2, + "MaxLedSegments": 4, + "MaxOutputs": 40, + "MaxServos": 10, + "MaxShifters": 4, + "MaxSteppers": 10, + "MaxInputMultiplexer": 2 + }, + "Pins": [ + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 0 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 1 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 2 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 3 + }, + { + "isAnalog": false, + "isI2C": true, + "isPWM": true, + "Pin": 4 + }, + { + "isAnalog": false, + "isI2C": true, + "isPWM": true, + "Pin": 5 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 6 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 7 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 8 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 9 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 10 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 11 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 12 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 13 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 14 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 15 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 16 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 17 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 18 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 19 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 18 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 19 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 20 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 21 + }, + { + "isAnalog": false, + "isI2C": false, + "isPWM": true, + "Pin": 22 + }, + { + "isAnalog": true, + "isI2C": false, + "isPWM": true, + "Name": "A0", + "Pin": 26 + }, + { + "isAnalog": true, + "isI2C": false, + "isPWM": true, + "Name": "A1", + "Pin": 27 + }, + { + "isAnalog": true, + "isI2C": false, + "isPWM": true, + "Name": "A2", + "Pin": 28 + } + ] + } + \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index f55287a7..364ccbaa 100644 --- a/platformio.ini +++ b/platformio.ini @@ -19,7 +19,6 @@ ; Common build settings across all devices [env] lib_deps = - arduino-libraries/Servo @ 1.1.8 https://github.com/MobiFlight/LedControl#1.1.0 waspinator/AccelStepper @ 1.61 https://github.com/MobiFlight/LiquidCrystal_I2C#v1.1.4 @@ -61,7 +60,8 @@ build_src_filter = ${env.build_src_filter} +<../_Boards/Atmel> lib_deps = - ${env.lib_deps} + ${env.lib_deps} + arduino-libraries/Servo @ 1.1.8 monitor_speed = 115200 extra_scripts = ${env.extra_scripts} @@ -78,7 +78,8 @@ build_src_filter = ${env.build_src_filter} +<../_Boards/Atmel> lib_deps = - ${env.lib_deps} + ${env.lib_deps} + arduino-libraries/Servo @ 1.1.8 monitor_speed = 115200 extra_scripts = ${env.extra_scripts} @@ -96,7 +97,35 @@ build_src_filter = ${env.build_src_filter} +<../_Boards/Atmel> lib_deps = - ${env.lib_deps} + ${env.lib_deps} + arduino-libraries/Servo @ 1.1.8 monitor_speed = 115200 extra_scripts = ${env.extra_scripts} + +; Build settings for the Raspberry Pico original +[env:raspberrypico] +platform = https://github.com/maxgerhardt/platform-raspberrypi.git +board = pico +framework = arduino +board_build.core = earlephilhower ; select new core +board_build.filesystem_size = 0M ; configure filesystem size. Default 0 Mbyte. +;lib_ldf_mode = chain+ +upload_protocol = mbed +build_flags = + ${env.build_flags} + -DUSE_INTERRUPT + -I./_Boards/RaspberryPi/Pico + -fpermissive +build_unflags = + -Wdeprecated-declarations +; -Werror=return-type +build_src_filter = + ${env.build_src_filter} + +<../_Boards/RaspberryPi> +lib_deps = + ${env.lib_deps} +monitor_speed = 115200 +extra_scripts = + ${env.extra_scripts} + diff --git a/src/MF_Modules/MFEEPROM.cpp b/src/MF_Modules/MFEEPROM.cpp index d1f1b4bc..201bc950 100644 --- a/src/MF_Modules/MFEEPROM.cpp +++ b/src/MF_Modules/MFEEPROM.cpp @@ -7,11 +7,15 @@ #include #include "MFEEPROM.h" #include +#include "MFBoards.h" MFEEPROM::MFEEPROM() {} void MFEEPROM::init(void) { +#if defined(ARDUINO_ARCH_RP2040) + EEPROM.begin(EEPROM_SIZE); +#endif _eepromLength = EEPROM.length(); } @@ -35,6 +39,9 @@ bool MFEEPROM::write_block(uint16_t adr, char data[], uint16_t len) for (uint16_t i = 0; i < len; i++) { EEPROM.put(adr + i, data[i]); } +#if defined(ARDUINO_ARCH_RP2040) + EEPROM.commit(); +#endif return true; } @@ -48,6 +55,9 @@ bool MFEEPROM::write_byte(uint16_t adr, char data) { if (adr >= _eepromLength) return false; EEPROM.put(adr, data); +#if defined(ARDUINO_ARCH_RP2040) + EEPROM.commit(); +#endif return true; } From 6ab3c00f5fa632f9c2a76fba10ec998fedaac3be Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Wed, 12 Oct 2022 08:58:26 +0200 Subject: [PATCH 02/18] =?UTF-8?q?increase=20servo=20range=20to=20+/-=2090?= =?UTF-8?q?=C2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MF_Servo/MFServo.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/MF_Servo/MFServo.cpp b/src/MF_Servo/MFServo.cpp index 55f3e7e7..c46a15ce 100644 --- a/src/MF_Servo/MFServo.cpp +++ b/src/MF_Servo/MFServo.cpp @@ -12,7 +12,11 @@ void MFServo::moveTo(int absolute) if (_targetPos != newValue) { _targetPos = newValue; if (!_initialized) { +#if defined(ARDUINO_ARCH_RP2040) + _servo.attach(_pin, 544, 2400); +#else _servo.attach(_pin); +#endif _initialized = true; } } From 128ba0745e4efd217cfb5931c509799cb587176e Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Wed, 19 Oct 2022 15:17:52 +0200 Subject: [PATCH 03/18] correct size for allocateMemory for Pico --- src/allocateMem.cpp | 16 ++++++++++++++-- src/allocateMem.h | 10 ++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/allocateMem.cpp b/src/allocateMem.cpp index 419517b9..f7a6df17 100644 --- a/src/allocateMem.cpp +++ b/src/allocateMem.cpp @@ -6,10 +6,22 @@ #include "mobiflight.h" -char deviceBuffer[MF_MAX_DEVICEMEM] = {0}; +#if defined (ARDUINO_ARCH_AVR) +uint8_t deviceBuffer[MF_MAX_DEVICEMEM] = {0}; +#elif defined(ARDUINO_ARCH_RP2040) +std::size_t deviceBuffer[MF_MAX_DEVICEMEM] = {0}; +#else +std::size_t deviceBuffer[MF_MAX_DEVICEMEM] = {0}; +#endif uint16_t nextPointer = 0; -char *allocateMemory(uint8_t size) +#if defined (ARDUINO_ARCH_AVR) +uint8_t *allocateMemory(uint8_t size) +#elif defined(ARDUINO_ARCH_RP2040) +std::size_t *allocateMemory(uint8_t size) +#else +std::size_t *allocateMemory(uint8_t size) +#endif { uint16_t actualPointer = nextPointer; nextPointer = actualPointer + size; diff --git a/src/allocateMem.h b/src/allocateMem.h index 2a98c15d..b887ebc8 100644 --- a/src/allocateMem.h +++ b/src/allocateMem.h @@ -8,9 +8,15 @@ #include -extern char deviceBuffer[]; +//extern char deviceBuffer[]; -char *allocateMemory(uint8_t size); +#if defined (ARDUINO_ARCH_AVR) +uint8_t *allocateMemory(uint8_t size); +#elif defined(ARDUINO_ARCH_RP2040) +std::size_t *allocateMemory(uint8_t size); +#else +std::size_t *allocateMemory(uint8_t size); +#endif void ClearMemory(); uint16_t GetAvailableMemory(); bool FitInMemory(uint8_t size); From 3a55cc7164e2a975b79a43efd2d20db6341781cb Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Fri, 21 Oct 2022 10:27:26 +0200 Subject: [PATCH 04/18] double pins in json file --- _Boards/RaspberryPi/Pico/raspberry_pico.board.json | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json index 93464f99..0f69ee4f 100644 --- a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json +++ b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json @@ -157,18 +157,6 @@ "isPWM": true, "Pin": 19 }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 18 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 19 - }, { "isAnalog": false, "isI2C": false, From f97d93a97474c6588745fa5b110a4d0b355a7c36 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Wed, 2 Nov 2022 10:36:36 +0100 Subject: [PATCH 05/18] flash via USB drive and not AVR dude --- _Boards/RaspberryPi/Pico/raspberry_pico.board.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json index 0f69ee4f..1e3d343d 100644 --- a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json +++ b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json @@ -1,11 +1,10 @@ { "$schema": "./mfboard.schema.json", - "AvrDudeSettings": { - "Device": "RaspiPico", - "BaudRate": "115200", - "Programmer": "arduino", + "UsbDriveSettings": { + "VolumeLabel": "RPI-RP2", + "VerificationFileName": "INFO_UF2.TXT", "FirmwareBaseName": "mobiflight_raspberrypico", - "Timeout": 15000 + "FirmwareExtension": "uf2" }, "Connection": { "ConnectionDelay": 1250, From b8379096eb771c063c68cd6c56064fe0bf8e9697 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Tue, 13 Dec 2022 07:07:33 +0100 Subject: [PATCH 06/18] just check for AVR arch for pointer size --- src/allocateMem.cpp | 3 +-- src/allocateMem.h | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/allocateMem.cpp b/src/allocateMem.cpp index f7a6df17..7837dcaa 100644 --- a/src/allocateMem.cpp +++ b/src/allocateMem.cpp @@ -8,11 +8,10 @@ #if defined (ARDUINO_ARCH_AVR) uint8_t deviceBuffer[MF_MAX_DEVICEMEM] = {0}; -#elif defined(ARDUINO_ARCH_RP2040) -std::size_t deviceBuffer[MF_MAX_DEVICEMEM] = {0}; #else std::size_t deviceBuffer[MF_MAX_DEVICEMEM] = {0}; #endif + uint16_t nextPointer = 0; #if defined (ARDUINO_ARCH_AVR) diff --git a/src/allocateMem.h b/src/allocateMem.h index b887ebc8..e9d6f857 100644 --- a/src/allocateMem.h +++ b/src/allocateMem.h @@ -8,15 +8,12 @@ #include -//extern char deviceBuffer[]; - #if defined (ARDUINO_ARCH_AVR) uint8_t *allocateMemory(uint8_t size); -#elif defined(ARDUINO_ARCH_RP2040) -std::size_t *allocateMemory(uint8_t size); #else std::size_t *allocateMemory(uint8_t size); #endif + void ClearMemory(); uint16_t GetAvailableMemory(); bool FitInMemory(uint8_t size); From 1392db0f65c53da09783089159c4914ccdb8cfe6 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Wed, 14 Dec 2022 08:23:23 +0100 Subject: [PATCH 07/18] correct number of devices --- _Boards/RaspberryPi/Pico/MFBoards.h | 10 +++++----- .../RaspberryPi/Pico/raspberry_pico.board.json | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/_Boards/RaspberryPi/Pico/MFBoards.h b/_Boards/RaspberryPi/Pico/MFBoards.h index 040465c0..d7cc6629 100644 --- a/_Boards/RaspberryPi/Pico/MFBoards.h +++ b/_Boards/RaspberryPi/Pico/MFBoards.h @@ -30,12 +30,12 @@ #define MF_DIGIN_MUX_SUPPORT 1 #endif -#define MAX_OUTPUTS 15 +#define MAX_OUTPUTS 26 #define MAX_BUTTONS 26 -#define MAX_LEDSEGMENTS 2 -#define MAX_ENCODERS 12 -#define MAX_STEPPERS 4 -#define MAX_MFSERVOS 4 +#define MAX_LEDSEGMENTS 4 +#define MAX_ENCODERS 8 +#define MAX_STEPPERS 6 +#define MAX_MFSERVOS 8 #define MAX_MFLCD_I2C 2 #define MAX_ANALOG_INPUTS 3 #define MAX_OUTPUT_SHIFTERS 4 diff --git a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json index 1e3d343d..2bf14eb0 100644 --- a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json +++ b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json @@ -13,26 +13,26 @@ "EEPROMSize": 1496, "ExtraConnectionRetry": false, "ForceResetOnFirmwareUpdate": true, - "MessageSize": 64 + "MessageSize": 96 }, "HardwareIds": ["^VID_2E8A&PID_000A"], "Info": { "CanInstallFirmware": true, "FriendlyName": "RaspiPico", - "LatestFirmwareVersion": "2.2.2", + "LatestFirmwareVersion": "2.3.0", "MobiFlightType": "MobiFlight RaspiPico" }, "ModuleLimits": { - "MaxAnalogInputs": 16, + "MaxAnalogInputs": 3, "MaxInputShifters": 4, - "MaxButtons": 68, - "MaxEncoders": 20, + "MaxButtons": 26, + "MaxEncoders": 8, "MaxLcdI2C": 2, "MaxLedSegments": 4, - "MaxOutputs": 40, - "MaxServos": 10, + "MaxOutputs": 26, + "MaxServos": 8, "MaxShifters": 4, - "MaxSteppers": 10, + "MaxSteppers": 6, "MaxInputMultiplexer": 2 }, "Pins": [ @@ -64,12 +64,14 @@ "isAnalog": false, "isI2C": true, "isPWM": true, + "Name": "4/I2C", "Pin": 4 }, { "isAnalog": false, "isI2C": true, "isPWM": true, + "Name": "5/I2C", "Pin": 5 }, { From 3490c510a771c18c47f14ec2a71ee44518cb411c Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Wed, 14 Dec 2022 08:52:29 +0100 Subject: [PATCH 08/18] clean up Pico environmnet --- platformio.ini | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/platformio.ini b/platformio.ini index 2670d13f..cc65be32 100644 --- a/platformio.ini +++ b/platformio.ini @@ -135,12 +135,9 @@ build_flags = -DUSE_INTERRUPT -I./_Boards/RaspberryPi/Pico -fpermissive -build_unflags = - -Wdeprecated-declarations -; -Werror=return-type build_src_filter = - ${env.build_src_filter} - +<../_Boards/RaspberryPi> + ${env.build_src_filter} + +<../_Boards/RaspberryPi> lib_deps = ${env.lib_deps} monitor_speed = 115200 From 3b2ba0914571f463fbe34f0cbafff1ce33390961 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Wed, 14 Dec 2022 11:24:31 +0100 Subject: [PATCH 09/18] add reset file name in .json file --- _Boards/RaspberryPi/Pico/raspberry_pico.board.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json index 2bf14eb0..b99f1425 100644 --- a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json +++ b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json @@ -4,7 +4,8 @@ "VolumeLabel": "RPI-RP2", "VerificationFileName": "INFO_UF2.TXT", "FirmwareBaseName": "mobiflight_raspberrypico", - "FirmwareExtension": "uf2" + "FirmwareExtension": "uf2", + "ResetFirmwareFile": "reset.arduino_raspberrypico_1_0_3.uf2" }, "Connection": { "ConnectionDelay": 1250, From 9d2d9bd7c4e65e08d2d95089caeb9962c121dc10 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Wed, 14 Dec 2022 11:33:22 +0100 Subject: [PATCH 10/18] add comment for debugging w/ picoprobe --- platformio.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index cc65be32..e96bba3f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -129,7 +129,8 @@ framework = arduino board_build.core = earlephilhower ; select new core board_build.filesystem_size = 0M ; configure filesystem size. Default 0 Mbyte. lib_ldf_mode = chain+ -upload_protocol = mbed +upload_protocol = mbed ; for debugging upoading can be changed to picoprobe +;debug_tool = picoprobe ; and uncomment this for debugging w/ picoprobe build_flags = ${env.build_flags} -DUSE_INTERRUPT From 13471ad232cbc9548bb26484e6f03bd6de8e4a58 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Fri, 16 Dec 2022 09:28:47 +0100 Subject: [PATCH 11/18] increase max. DigInMux from 2 to 4 --- _Boards/RaspberryPi/Pico/MFBoards.h | 2 +- _Boards/RaspberryPi/Pico/raspberry_pico.board.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_Boards/RaspberryPi/Pico/MFBoards.h b/_Boards/RaspberryPi/Pico/MFBoards.h index d7cc6629..d8aa7ce3 100644 --- a/_Boards/RaspberryPi/Pico/MFBoards.h +++ b/_Boards/RaspberryPi/Pico/MFBoards.h @@ -40,7 +40,7 @@ #define MAX_ANALOG_INPUTS 3 #define MAX_OUTPUT_SHIFTERS 4 #define MAX_INPUT_SHIFTERS 4 -#define MAX_DIGIN_MUX 2 +#define MAX_DIGIN_MUX 4 #define STEPS 64 #define STEPPER_SPEED 400 // 300 already worked, 467, too? diff --git a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json index b99f1425..328103b1 100644 --- a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json +++ b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json @@ -34,7 +34,7 @@ "MaxServos": 8, "MaxShifters": 4, "MaxSteppers": 6, - "MaxInputMultiplexer": 2 + "MaxInputMultiplexer": 4 }, "Pins": [ { From 68566b954f41142ece761041fc8c009b6b0c85a7 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Mon, 19 Dec 2022 08:10:41 +0100 Subject: [PATCH 12/18] use unique ID instead of random number --- _Boards/RaspberryPi/Pico/MFBoards.h | 2 -- src/Config.cpp | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/_Boards/RaspberryPi/Pico/MFBoards.h b/_Boards/RaspberryPi/Pico/MFBoards.h index d8aa7ce3..211cb266 100644 --- a/_Boards/RaspberryPi/Pico/MFBoards.h +++ b/_Boards/RaspberryPi/Pico/MFBoards.h @@ -54,6 +54,4 @@ #define MEMLEN_NAMES_BUFFER 1000 // max. size for configBuffer, contains only names from inputs #define MF_MAX_DEVICEMEM 2000 // max. memory size for devices -#define RANDOM_SEED_INPUT A0 // better to have randomSeed(analogRead(RANDOM_SEED_INPUT)); in generateSerial(), "0" is not valid for all HW platforms - #endif diff --git a/src/Config.cpp b/src/Config.cpp index f20e1d18..8eb22afd 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -52,7 +52,15 @@ extern MFMuxDriver MUX; const uint8_t MEM_OFFSET_NAME = 0; const uint8_t MEM_LEN_NAME = 48; const uint8_t MEM_OFFSET_SERIAL = MEM_OFFSET_NAME + MEM_LEN_NAME; +#if defined (ARDUINO_ARCH_AVR) const uint8_t MEM_LEN_SERIAL = 11; +#else if defined (ARDIUNO_ARCH_RP2040) +// Pico has a unique 64-bit device identifier which is retrieved from the external NOR flash device at boot. +// These 8 bytes are transferred to characters, so 16 bytes are required +// Additionally 3 bytes for "SN-" and one byte for the NULL terminator is required +// On first start up only "SN" is written to the EEPROM to check first start up of the firmware +const uint8_t MEM_LEN_SERIAL = PICO_UNIQUE_BOARD_ID_SIZE_BYTES * 2 + 1 + 3; +#endif const uint8_t MEM_OFFSET_CONFIG = MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL; char serial[MEM_LEN_SERIAL] = MOBIFLIGHT_SERIAL; @@ -440,10 +448,16 @@ void generateSerial(bool force) MFeeprom.read_block(MEM_OFFSET_SERIAL, serial, MEM_LEN_SERIAL); if (!force && serial[0] == 'S' && serial[1] == 'N') return; +#if defined (ARDUINO_ARCH_AVR) randomSeed(analogRead(RANDOM_SEED_INPUT)); sprintf(serial, "SN-%03x-", (unsigned int)random(4095)); sprintf(&serial[7], "%03x", (unsigned int)random(4095)); MFeeprom.write_block(MEM_OFFSET_SERIAL, serial, MEM_LEN_SERIAL); +#else if defined (ARDIUNO_ARCH_RP2040) + sprintf(serial, "SN-"); + pico_get_unique_board_id_string(&serial[3], MEM_LEN_SERIAL - 3); + MFeeprom.write_block(MEM_OFFSET_SERIAL, "SN", 2); +#endif if (!force) { MFeeprom.write_byte(MEM_OFFSET_CONFIG, 0x00); // First byte of config to 0x00 to ensure to start 1st time with empty config, but not if forced from the connector to generate a new one } From 96799c0c4f5b4386856059eeefe2aa35d2d0892c Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Mon, 19 Dec 2022 08:52:43 +0100 Subject: [PATCH 13/18] uniqueID instead of serial number for Pico --- src/Config.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index 8eb22afd..38bab37e 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -52,9 +52,9 @@ extern MFMuxDriver MUX; const uint8_t MEM_OFFSET_NAME = 0; const uint8_t MEM_LEN_NAME = 48; const uint8_t MEM_OFFSET_SERIAL = MEM_OFFSET_NAME + MEM_LEN_NAME; -#if defined (ARDUINO_ARCH_AVR) +#if defined(ARDUINO_ARCH_AVR) const uint8_t MEM_LEN_SERIAL = 11; -#else if defined (ARDIUNO_ARCH_RP2040) +#elif defined(ARDUINO_ARCH_RP2040) // Pico has a unique 64-bit device identifier which is retrieved from the external NOR flash device at boot. // These 8 bytes are transferred to characters, so 16 bytes are required // Additionally 3 bytes for "SN-" and one byte for the NULL terminator is required @@ -445,17 +445,19 @@ bool getStatusConfig() // ************************************************************ void generateSerial(bool force) { +#if defined(ARDUINO_ARCH_AVR) MFeeprom.read_block(MEM_OFFSET_SERIAL, serial, MEM_LEN_SERIAL); if (!force && serial[0] == 'S' && serial[1] == 'N') return; -#if defined (ARDUINO_ARCH_AVR) randomSeed(analogRead(RANDOM_SEED_INPUT)); sprintf(serial, "SN-%03x-", (unsigned int)random(4095)); sprintf(&serial[7], "%03x", (unsigned int)random(4095)); MFeeprom.write_block(MEM_OFFSET_SERIAL, serial, MEM_LEN_SERIAL); -#else if defined (ARDIUNO_ARCH_RP2040) +#elif defined(ARDUINO_ARCH_RP2040) sprintf(serial, "SN-"); pico_get_unique_board_id_string(&serial[3], MEM_LEN_SERIAL - 3); + if (!force && MFeeprom.read_byte(MEM_OFFSET_SERIAL) == 'S' && MFeeprom.read_byte(MEM_OFFSET_SERIAL + 1) == 'N') + return; MFeeprom.write_block(MEM_OFFSET_SERIAL, "SN", 2); #endif if (!force) { From 422fdcf29a1b02cb7d80d2d1c988dfa3b4f81f0d Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Tue, 20 Dec 2022 08:33:08 +0100 Subject: [PATCH 14/18] size of allocateMemory acc. definition in .h file --- src/allocateMem.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/allocateMem.cpp b/src/allocateMem.cpp index 7837dcaa..0b3912ce 100644 --- a/src/allocateMem.cpp +++ b/src/allocateMem.cpp @@ -16,8 +16,6 @@ uint16_t nextPointer = 0; #if defined (ARDUINO_ARCH_AVR) uint8_t *allocateMemory(uint8_t size) -#elif defined(ARDUINO_ARCH_RP2040) -std::size_t *allocateMemory(uint8_t size) #else std::size_t *allocateMemory(uint8_t size) #endif From b326d69f50c3a89b70ed1ba9f01e520617ba4eb1 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Tue, 20 Dec 2022 14:42:00 +0100 Subject: [PATCH 15/18] delete .json file, bundling servoLib for Atmels --- .../Pico/raspberry_pico.board.json | 203 ------------------ platformio.ini | 14 +- 2 files changed, 10 insertions(+), 207 deletions(-) delete mode 100644 _Boards/RaspberryPi/Pico/raspberry_pico.board.json diff --git a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json b/_Boards/RaspberryPi/Pico/raspberry_pico.board.json deleted file mode 100644 index 328103b1..00000000 --- a/_Boards/RaspberryPi/Pico/raspberry_pico.board.json +++ /dev/null @@ -1,203 +0,0 @@ -{ - "$schema": "./mfboard.schema.json", - "UsbDriveSettings": { - "VolumeLabel": "RPI-RP2", - "VerificationFileName": "INFO_UF2.TXT", - "FirmwareBaseName": "mobiflight_raspberrypico", - "FirmwareExtension": "uf2", - "ResetFirmwareFile": "reset.arduino_raspberrypico_1_0_3.uf2" - }, - "Connection": { - "ConnectionDelay": 1250, - "DelayAfterFirmwareUpdate": 1250, - "DtrEnable": true, - "EEPROMSize": 1496, - "ExtraConnectionRetry": false, - "ForceResetOnFirmwareUpdate": true, - "MessageSize": 96 - }, - "HardwareIds": ["^VID_2E8A&PID_000A"], - "Info": { - "CanInstallFirmware": true, - "FriendlyName": "RaspiPico", - "LatestFirmwareVersion": "2.3.0", - "MobiFlightType": "MobiFlight RaspiPico" - }, - "ModuleLimits": { - "MaxAnalogInputs": 3, - "MaxInputShifters": 4, - "MaxButtons": 26, - "MaxEncoders": 8, - "MaxLcdI2C": 2, - "MaxLedSegments": 4, - "MaxOutputs": 26, - "MaxServos": 8, - "MaxShifters": 4, - "MaxSteppers": 6, - "MaxInputMultiplexer": 4 - }, - "Pins": [ - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 0 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 1 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 2 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 3 - }, - { - "isAnalog": false, - "isI2C": true, - "isPWM": true, - "Name": "4/I2C", - "Pin": 4 - }, - { - "isAnalog": false, - "isI2C": true, - "isPWM": true, - "Name": "5/I2C", - "Pin": 5 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 6 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 7 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 8 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 9 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 10 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 11 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 12 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 13 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 14 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 15 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 16 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 17 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 18 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 19 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 20 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 21 - }, - { - "isAnalog": false, - "isI2C": false, - "isPWM": true, - "Pin": 22 - }, - { - "isAnalog": true, - "isI2C": false, - "isPWM": true, - "Name": "A0", - "Pin": 26 - }, - { - "isAnalog": true, - "isI2C": false, - "isPWM": true, - "Name": "A1", - "Pin": 27 - }, - { - "isAnalog": true, - "isI2C": false, - "isPWM": true, - "Name": "A2", - "Pin": 28 - } - ] - } - \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index e96bba3f..dfcc4b86 100644 --- a/platformio.ini +++ b/platformio.ini @@ -23,6 +23,8 @@ lib_deps = waspinator/AccelStepper @ 1.61 https://github.com/MobiFlight/LiquidCrystal_I2C#v1.1.4 https://github.com/MobiFlight/Arduino-CmdMessenger#4.2.1 +lib_deps_Atmel = + arduino-libraries/Servo @ 1.1.8 build_flags = -DMF_REDUCE_FUNCT_LEDCONTROL -DMAXCALLBACKS=30 @@ -61,7 +63,8 @@ build_src_filter = +<../_Boards/Atmel> lib_deps = ${env.lib_deps} - arduino-libraries/Servo @ 1.1.8 + ${env.lib_deps_Atmel} + ;arduino-libraries/Servo @ 1.1.8 monitor_speed = 115200 extra_scripts = ${env.extra_scripts} @@ -79,7 +82,8 @@ build_src_filter = +<../_Boards/Atmel> lib_deps = ${env.lib_deps} - arduino-libraries/Servo @ 1.1.8 + ${env.lib_deps_Atmel} + ;arduino-libraries/Servo @ 1.1.8 monitor_speed = 115200 extra_scripts = ${env.extra_scripts} @@ -98,7 +102,8 @@ build_src_filter = +<../_Boards/Atmel> lib_deps = ${env.lib_deps} - arduino-libraries/Servo @ 1.1.8 + ${env.lib_deps_Atmel} + ;arduino-libraries/Servo @ 1.1.8 monitor_speed = 115200 extra_scripts = ${env.extra_scripts} @@ -116,7 +121,8 @@ build_src_filter = +<../_Boards/Atmel> lib_deps = ${env.lib_deps} - arduino-libraries/Servo @ 1.1.8 + ${env.lib_deps_Atmel} + ;arduino-libraries/Servo @ 1.1.8 monitor_speed = 115200 extra_scripts = ${env.extra_scripts} From 10366636b8f887e57a2e6f18de3450b9c4656102 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Tue, 20 Dec 2022 14:46:33 +0100 Subject: [PATCH 16/18] delete commented libs --- platformio.ini | 4 ---- 1 file changed, 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index dfcc4b86..57b4c4eb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -64,7 +64,6 @@ build_src_filter = lib_deps = ${env.lib_deps} ${env.lib_deps_Atmel} - ;arduino-libraries/Servo @ 1.1.8 monitor_speed = 115200 extra_scripts = ${env.extra_scripts} @@ -83,7 +82,6 @@ build_src_filter = lib_deps = ${env.lib_deps} ${env.lib_deps_Atmel} - ;arduino-libraries/Servo @ 1.1.8 monitor_speed = 115200 extra_scripts = ${env.extra_scripts} @@ -103,7 +101,6 @@ build_src_filter = lib_deps = ${env.lib_deps} ${env.lib_deps_Atmel} - ;arduino-libraries/Servo @ 1.1.8 monitor_speed = 115200 extra_scripts = ${env.extra_scripts} @@ -122,7 +119,6 @@ build_src_filter = lib_deps = ${env.lib_deps} ${env.lib_deps_Atmel} - ;arduino-libraries/Servo @ 1.1.8 monitor_speed = 115200 extra_scripts = ${env.extra_scripts} From 4c4c9e910f43b2883caf4d76d9cb0c8789772a3a Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Mon, 26 Dec 2022 08:06:52 +0100 Subject: [PATCH 17/18] keep backwards compatibility for UniqueID on Pico --- src/Config.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index 38bab37e..dce4f02d 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -52,18 +52,17 @@ extern MFMuxDriver MUX; const uint8_t MEM_OFFSET_NAME = 0; const uint8_t MEM_LEN_NAME = 48; const uint8_t MEM_OFFSET_SERIAL = MEM_OFFSET_NAME + MEM_LEN_NAME; -#if defined(ARDUINO_ARCH_AVR) const uint8_t MEM_LEN_SERIAL = 11; +const uint8_t MEM_OFFSET_CONFIG = MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL; +#if defined(ARDUINO_ARCH_AVR) +char serial[MEM_LEN_SERIAL] = MOBIFLIGHT_SERIAL; #elif defined(ARDUINO_ARCH_RP2040) // Pico has a unique 64-bit device identifier which is retrieved from the external NOR flash device at boot. // These 8 bytes are transferred to characters, so 16 bytes are required // Additionally 3 bytes for "SN-" and one byte for the NULL terminator is required // On first start up only "SN" is written to the EEPROM to check first start up of the firmware -const uint8_t MEM_LEN_SERIAL = PICO_UNIQUE_BOARD_ID_SIZE_BYTES * 2 + 1 + 3; +char serial[PICO_UNIQUE_BOARD_ID_SIZE_BYTES * 2 + 1 + 3] = MOBIFLIGHT_SERIAL; #endif -const uint8_t MEM_OFFSET_CONFIG = MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL; - -char serial[MEM_LEN_SERIAL] = MOBIFLIGHT_SERIAL; char name[MEM_LEN_NAME] = MOBIFLIGHT_NAME; const int MEM_LEN_CONFIG = MEMLEN_CONFIG; char nameBuffer[MEM_LEN_CONFIG] = ""; From 905849de06036488dfa592c644591cc8924608a6 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Thu, 29 Dec 2022 11:31:14 +0100 Subject: [PATCH 18/18] generate serial w/ ArduinoUniqueID library --- platformio.ini | 1 + src/Config.cpp | 50 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/platformio.ini b/platformio.ini index 57b4c4eb..f975a3b8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -23,6 +23,7 @@ lib_deps = waspinator/AccelStepper @ 1.61 https://github.com/MobiFlight/LiquidCrystal_I2C#v1.1.4 https://github.com/MobiFlight/Arduino-CmdMessenger#4.2.1 + ricaun/ArduinoUniqueID @ ^1.3.0 lib_deps_Atmel = arduino-libraries/Servo @ 1.1.8 build_flags = diff --git a/src/Config.cpp b/src/Config.cpp index dce4f02d..7ad59439 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -6,11 +6,10 @@ #include "mobiflight.h" #include "MFEEPROM.h" - #include "Button.h" #include "Encoder.h" #include "Output.h" - +#include "ArduinoUniqueID.h" #if MF_ANALOG_SUPPORT == 1 #include "Analog.h" #endif @@ -444,23 +443,42 @@ bool getStatusConfig() // ************************************************************ void generateSerial(bool force) { + if (force) { #if defined(ARDUINO_ARCH_AVR) - MFeeprom.read_block(MEM_OFFSET_SERIAL, serial, MEM_LEN_SERIAL); - if (!force && serial[0] == 'S' && serial[1] == 'N') + // A serial number is forced to generated from the user + // It is very likely that the reason is a double serial number as the UniqueID for AVR's must not be Unique + // so generate one acc. the old style and use millis() for seed + randomSeed(millis()); + sprintf(serial, "SN-%03x-", (unsigned int)random(4095)); + sprintf(&serial[7], "%03x", (unsigned int)random(4095)); + MFeeprom.write_block(MEM_OFFSET_SERIAL, serial, MEM_LEN_SERIAL); +#endif return; - randomSeed(analogRead(RANDOM_SEED_INPUT)); - sprintf(serial, "SN-%03x-", (unsigned int)random(4095)); - sprintf(&serial[7], "%03x", (unsigned int)random(4095)); - MFeeprom.write_block(MEM_OFFSET_SERIAL, serial, MEM_LEN_SERIAL); -#elif defined(ARDUINO_ARCH_RP2040) - sprintf(serial, "SN-"); - pico_get_unique_board_id_string(&serial[3], MEM_LEN_SERIAL - 3); - if (!force && MFeeprom.read_byte(MEM_OFFSET_SERIAL) == 'S' && MFeeprom.read_byte(MEM_OFFSET_SERIAL + 1) == 'N') + } + + if (MFeeprom.read_byte(MEM_OFFSET_SERIAL) == 'S' && MFeeprom.read_byte(MEM_OFFSET_SERIAL + 1) == 'N') { + // A serial number according old style is already generated and saved to the eeprom + // So keep it to avoid a connector message with orphaned board + MFeeprom.read_block(MEM_OFFSET_SERIAL, serial, MEM_LEN_SERIAL); return; - MFeeprom.write_block(MEM_OFFSET_SERIAL, "SN", 2); -#endif - if (!force) { - MFeeprom.write_byte(MEM_OFFSET_CONFIG, 0x00); // First byte of config to 0x00 to ensure to start 1st time with empty config, but not if forced from the connector to generate a new one + } + + // Read the uniqueID and use it as serial numnber + sprintf(serial, "SN-"); + for (size_t i = 0; i < UniqueIDsize; i++) { + if (UniqueID[i] < 0x10) { + sprintf(&serial[3 + i * 2], "0%X", UniqueID[i]); + } else { + sprintf(&serial[3 + i * 2], "%X", UniqueID[i]); + } + } + + if (MFeeprom.read_byte(MEM_OFFSET_SERIAL) != 'I' && MFeeprom.read_byte(MEM_OFFSET_SERIAL + 1) != 'D') { + // Coming here it's the first start up of the board and no serial number or UniqueID is available + // mark this in the eeprom that a UniqueID is used on first start up + MFeeprom.write_block(MEM_OFFSET_SERIAL, "ID", 2); + // Set first byte of config to 0x00 to ensure with empty config on 1st start up + MFeeprom.write_byte(MEM_OFFSET_CONFIG, 0x00); } }