From 57aa1457e0d4ed0016f2cee1937a4564b2de9c80 Mon Sep 17 00:00:00 2001 From: pmantoine Date: Sun, 23 Oct 2022 17:49:39 +0800 Subject: [PATCH 1/3] GETFLASHW hack for SAMD/STM32 --- FSH.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/FSH.h b/FSH.h index 850311e..ea54554 100644 --- a/FSH.h +++ b/FSH.h @@ -1,5 +1,5 @@ /* - * © 2022 Paul M Antoine + * © 2022 Paul M. Antoine * © 2021 Neil McKechnie * © 2021 Harald Barth * © 2021 Fred Decker @@ -48,10 +48,10 @@ typedef char FSH; #define FLASH #define strlen_P strlen #define strcpy_P strcpy -#elif defined(ARDUINO_ARCH_STM32) +#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) typedef __FlashStringHelper FSH; -#define GETFLASH(addr) pgm_read_byte_near(addr) -#define GETFLASHW(addr) pgm_read_word_near(addr) +#define GETFLASH(addr) pgm_read_byte(addr) +#define GETFLASHW(addr) (*(const unsigned int8_t *)(addr)) | ((*(const unsigned int8_t *)(addr+1)) << 8) #ifdef FLASH #undef FLASH #endif From 888165e98702c526f43692ce8eb4ad420f3d04c9 Mon Sep 17 00:00:00 2001 From: pmantoine Date: Mon, 24 Oct 2022 08:33:08 +0800 Subject: [PATCH 2/3] Skeletal ADCee class for STM32 --- DCCTimerSTM32.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/DCCTimerSTM32.cpp b/DCCTimerSTM32.cpp index 2cacaff..cab3bc7 100644 --- a/DCCTimerSTM32.cpp +++ b/DCCTimerSTM32.cpp @@ -1,5 +1,5 @@ /* - * © 2022 Paul M Antoine + * © 2022 Paul M. Antoine * © 2021 Mike S * © 2021 Harald Barth * © 2021 Fred Decker @@ -127,4 +127,31 @@ void DCCTimer::reset() { while(true) {}; } +int16_t ADCee::ADCmax() { + return 4095; +} + +int ADCee::init(uint8_t pin) { + return analogRead(pin); +} +/* + * Read function ADCee::read(pin) to get value instead of analogRead(pin) + */ +int ADCee::read(uint8_t pin, bool fromISR) { + int current; + if (!fromISR) noInterrupts(); + current = analogRead(pin); + if (!fromISR) interrupts(); + return current; +} +/* + * Scan function that is called from interrupt + */ +void ADCee::scan() { +} + +void ADCee::begin() { + noInterrupts(); + interrupts(); +} #endif \ No newline at end of file From 88c7e540fa59df201432903c5eb6ca5ce45bca99 Mon Sep 17 00:00:00 2001 From: pmantoine Date: Mon, 24 Oct 2022 11:12:56 +0800 Subject: [PATCH 3/3] STM32 additional serial port support --- DCCTimerSTM32.cpp | 5 +++++ SerialManager.cpp | 14 +++++++++++++- config.example.h | 9 +++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/DCCTimerSTM32.cpp b/DCCTimerSTM32.cpp index cab3bc7..eb0d365 100644 --- a/DCCTimerSTM32.cpp +++ b/DCCTimerSTM32.cpp @@ -37,6 +37,11 @@ #if defined(STM32F411RE) // STM32F411RE doesn't have Serial1 defined by default HardwareSerial Serial1(PB7, PA15); // Rx=PB7, Tx=PA15 -- CN7 pins 17 and 21 - F411RE +// Serial2 is defined to use USART2 by default, but is in fact used as the diag console +// via the debugger on the Nucleo-64 STM32F411RE. It is therefore unavailable +// for other DCC-EX uses like WiFi, DFPlayer, etc. +// Let's define Serial6 as an additional serial port (the only other option for the F411RE) +HardwareSerial Serial6(PA12, PA11); // Rx=PA12, Tx=PA11 -- CN10 pins 12 and 14 - F411RE #elif defined(STM32F446ZE) // STM32F446ZE doesn't have Serial1 defined by default HardwareSerial Serial1(PG9, PG14); // Rx=PG9, Tx=PG14 -- D0, D1 - F446ZE diff --git a/SerialManager.cpp b/SerialManager.cpp index 372cc85..0ac567d 100644 --- a/SerialManager.cpp +++ b/SerialManager.cpp @@ -1,5 +1,5 @@ /* - * © 2022 Paul M Antoine + * © 2022 Paul M. Antoine * © 2021 Chris Harlow * © 2022 Harald Barth * All rights reserved. @@ -51,6 +51,18 @@ void SerialManager::init() { while (!USB_SERIAL && millis() < 5000); // wait max 5s for Serial to start new SerialManager(&USB_SERIAL); +#ifdef SERIAL6_COMMANDS + Serial6.begin(115200); + new SerialManager(&Serial6); +#endif +#ifdef SERIAL5_COMMANDS + Serial5.begin(115200); + new SerialManager(&Serial5); +#endif +#ifdef SERIAL4_COMMANDS + Serial4.begin(115200); + new SerialManager(&Serial4); +#endif #ifdef SERIAL3_COMMANDS Serial3.begin(115200); new SerialManager(&Serial3); diff --git a/config.example.h b/config.example.h index 8bed4ef..aae18a9 100644 --- a/config.example.h +++ b/config.example.h @@ -1,4 +1,5 @@ /* + * © 2022 Paul M. Antoine * © 2021 Neil McKechnie * © 2020-2021 Harald Barth * © 2020-2021 Fred Decker @@ -191,14 +192,18 @@ The configuration file for DCC-EX Command Station // HANDLING MULTIPLE SERIAL THROTTLES // The command station always operates with the default Serial port. // Diagnostics are only emitted on the default serial port and not broadcast. -// Other serial throttles may be added to the Serial1, Serial2, Serial3 ports -// which may or may not exist on your CPU. (Mega has all 3) +// Other serial throttles may be added to the Serial1, Serial2, Serial3, Serial4, +// Serial5, and Serial6 ports which may or may not exist on your CPU. (Mega has 3, +// SAMD/SAMC and STM32 have up to 6.) // To monitor a throttle on one or more serial ports, uncomment the defines below. // NOTE: do not define here the WiFi shield serial port or your wifi will not work. // //#define SERIAL1_COMMANDS //#define SERIAL2_COMMANDS //#define SERIAL3_COMMANDS +//#define SERIAL4_COMMANDS +//#define SERIAL5_COMMANDS +//#define SERIAL6_COMMANDS // // BLUETOOTH SERIAL ON ESP32 // On ESP32 you have the possibility to use the builtin BT serial to connect to