1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 17:46:14 +01:00

Compare commits

...

3 Commits

Author SHA1 Message Date
pmantoine
33c8ed19a9 Various STM32 related fixes 2024-09-30 16:13:00 +08:00
Harald Barth
0e99ad143b version 5.2.82 2024-09-30 10:07:07 +02:00
Harald Barth
01533e2cd2 TrackManager and EXRAIL: Introduce more consistent names for <= ...> and SET_TRACK 2024-09-30 10:05:47 +02:00
9 changed files with 70 additions and 44 deletions

View File

@ -577,7 +577,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
{ {
if (params > 1) break; if (params > 1) break;
if (params==0) { // All if (params==0) { // All
TrackManager::setTrackPower(TRACK_MODE_ALL, POWERMODE::ON); TrackManager::setTrackPower(TRACK_ALL, POWERMODE::ON);
} }
if (params==1) { if (params==1) {
if (p[0]=="MAIN"_hk) { // <1 MAIN> if (p[0]=="MAIN"_hk) { // <1 MAIN>
@ -610,7 +610,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
if (params > 1) break; if (params > 1) break;
if (params==0) { // All if (params==0) { // All
TrackManager::setJoin(false); TrackManager::setJoin(false);
TrackManager::setTrackPower(TRACK_MODE_ALL, POWERMODE::OFF); TrackManager::setTrackPower(TRACK_ALL, POWERMODE::OFF);
} }
if (params==1) { if (params==1) {
if (p[0]=="MAIN"_hk) { // <0 MAIN> if (p[0]=="MAIN"_hk) { // <0 MAIN>

View File

@ -70,9 +70,9 @@ HardwareSerial Serial5(PD2, PC12); // Rx=PD2, Tx=PC12 -- UART5 - F446RE
defined(ARDUINO_NUCLEO_F429ZI) || defined(ARDUINO_NUCLEO_F439ZI) || defined(ARDUINO_NUCLEO_F4X9ZI) defined(ARDUINO_NUCLEO_F429ZI) || defined(ARDUINO_NUCLEO_F439ZI) || defined(ARDUINO_NUCLEO_F4X9ZI)
// Nucleo-144 boards don't have Serial1 defined by default // Nucleo-144 boards don't have Serial1 defined by default
HardwareSerial Serial6(PG9, PG14); // Rx=PG9, Tx=PG14 -- USART6 HardwareSerial Serial6(PG9, PG14); // Rx=PG9, Tx=PG14 -- USART6
HardwareSerial Serial5(PD2, PC12); // Rx=PD2, Tx=PC12 -- UART5 HardwareSerial Serial2(PD6, PD5); // Rx=PD6, Tx=PD5 -- UART2
#if !defined(ARDUINO_NUCLEO_F412ZG) #if !defined(ARDUINO_NUCLEO_F412ZG) // F412ZG does not have UART5
HardwareSerial Serial2(PD6, PD5); // Rx=PD6, Tx=PD5 -- UART5 HardwareSerial Serial5(PD2, PC12); // Rx=PD2, Tx=PC12 -- UART5
#endif #endif
// Serial3 is defined to use USART3 by default, but is in fact used as the diag console // Serial3 is defined to use USART3 by default, but is in fact used as the diag console
// via the debugger on the Nucleo-144. It is therefore unavailable for other DCC-EX uses like WiFi, DFPlayer, etc. // via the debugger on the Nucleo-144. It is therefore unavailable for other DCC-EX uses like WiFi, DFPlayer, etc.
@ -328,7 +328,7 @@ void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t frequency
if (pin_timer[pin] != NULL) if (pin_timer[pin] != NULL)
{ {
pin_timer[pin]->setPWM(pin_channel[pin], pin, frequency, 0); // set frequency in Hertz, 0% dutycycle pin_timer[pin]->setPWM(pin_channel[pin], pin, frequency, 0); // set frequency in Hertz, 0% dutycycle
DIAG(F("DCCEXanalogWriteFrequency::Pin %d on Timer %d, frequency %d"), pin, pin_channel[pin], frequency); DIAG(F("DCCEXanalogWriteFrequency::Pin %d on Timer Channel %d, frequency %d"), pin, pin_channel[pin], frequency);
} }
else else
DIAG(F("DCCEXanalogWriteFrequency::failed to allocate HardwareTimer instance!")); DIAG(F("DCCEXanalogWriteFrequency::failed to allocate HardwareTimer instance!"));

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202409221903Z" #define GITHUB_SHA "devel-202409300806Z"

View File

@ -1,5 +1,5 @@
/* /*
* © 2022-23 Paul M Antoine * © 2022-24 Paul M Antoine
* © 2023, Neil McKechnie * © 2023, Neil McKechnie
* All rights reserved. * All rights reserved.
* *
@ -185,7 +185,7 @@ void I2CManagerClass::I2C_init()
GPIOB->OTYPER |= (1<<8) | (1<<9); // PB8 and PB9 set to open drain output capability GPIOB->OTYPER |= (1<<8) | (1<<9); // PB8 and PB9 set to open drain output capability
GPIOB->OSPEEDR |= (3<<(8*2)) | (3<<(9*2)); // PB8 and PB9 set to High Speed mode GPIOB->OSPEEDR |= (3<<(8*2)) | (3<<(9*2)); // PB8 and PB9 set to High Speed mode
GPIOB->PUPDR &= ~((3<<(8*2)) | (3<<(9*2))); // Clear all PUPDR bits for PB8 and PB9 GPIOB->PUPDR &= ~((3<<(8*2)) | (3<<(9*2))); // Clear all PUPDR bits for PB8 and PB9
GPIOB->PUPDR |= (1<<(8*2)) | (1<<(9*2)); // PB8 and PB9 set to pull-up capability // GPIOB->PUPDR |= (1<<(8*2)) | (1<<(9*2)); // PB8 and PB9 set to pull-up capability
// Alt Function High register routing pins PB8 and PB9 for I2C1: // Alt Function High register routing pins PB8 and PB9 for I2C1:
// Bits (3:2:1:0) = 0:1:0:0 --> AF4 for pin PB8 // Bits (3:2:1:0) = 0:1:0:0 --> AF4 for pin PB8
// Bits (7:6:5:4) = 0:1:0:0 --> AF4 for pin PB9 // Bits (7:6:5:4) = 0:1:0:0 --> AF4 for pin PB9

View File

@ -576,7 +576,7 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
DIAG(F("TRACK %c ALERT FAULT"), trackno + 'A'); DIAG(F("TRACK %c ALERT FAULT"), trackno + 'A');
} }
setPower(POWERMODE::ALERT); setPower(POWERMODE::ALERT);
if ((trackMode & TRACK_MODE_AUTOINV) && (trackMode & (TRACK_MODE_MAIN|TRACK_MODE_EXT|TRACK_MODE_BOOST))){ if ((trackMode & TRACK_MODIFIER_AUTO) && (trackMode & (TRACK_MODE_MAIN|TRACK_MODE_EXT|TRACK_MODE_BOOST))){
DIAG(F("TRACK %c INVERT"), trackno + 'A'); DIAG(F("TRACK %c INVERT"), trackno + 'A');
invertOutput(); invertOutput();
} }

View File

@ -29,21 +29,33 @@
#include <wiring_private.h> #include <wiring_private.h>
// use powers of two so we can do logical and/or on the track modes in if clauses. // use powers of two so we can do logical and/or on the track modes in if clauses.
// RACK_MODE_DCX is (TRACK_MODE_DC|TRACK_MODE_INV) // For example TRACK_MODE_DC_INV is (TRACK_MODE_DC|TRACK_MODIFIER_INV)
template<class T> inline T operator~ (T a) { return (T)~(int)a; } template<class T> inline T operator~ (T a) { return (T)~(int)a; }
template<class T> inline T operator| (T a, T b) { return (T)((int)a | (int)b); } template<class T> inline T operator| (T a, T b) { return (T)((int)a | (int)b); }
template<class T> inline T operator& (T a, T b) { return (T)((int)a & (int)b); } template<class T> inline T operator& (T a, T b) { return (T)((int)a & (int)b); }
template<class T> inline T operator^ (T a, T b) { return (T)((int)a ^ (int)b); } template<class T> inline T operator^ (T a, T b) { return (T)((int)a ^ (int)b); }
enum TRACK_MODE : byte {TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PROG = 4, enum TRACK_MODE : byte {
// main modes
TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PROG = 4,
TRACK_MODE_DC = 8, TRACK_MODE_EXT = 16, TRACK_MODE_DC = 8, TRACK_MODE_EXT = 16,
// modifiers
TRACK_MODIFIER_INV = 64, TRACK_MODIFIER_AUTO = 128,
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
TRACK_MODE_BOOST = 32, TRACK_MODE_BOOST = 32,
TRACK_MODE_BOOST_INV = TRACK_MODE_BOOST|TRACK_MODIFIER_INV,
TRACK_MODE_BOOST_AUTO = TRACK_MODE_BOOST|TRACK_MODIFIER_AUTO,
#else #else
TRACK_MODE_BOOST = 0, TRACK_MODE_BOOST = 0,
TRACK_MODE_BOOST_INV = 0,
TRACK_MODE_BOOST_AUTO = 0,
#endif #endif
TRACK_MODE_ALL = TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_EXT|TRACK_MODE_BOOST, // derived modes; TRACK_ALL is calles that so it does not match TRACK_MODE_*
TRACK_MODE_INV = 64, TRACK_ALL = TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_EXT|TRACK_MODE_BOOST,
TRACK_MODE_DCX = TRACK_MODE_DC|TRACK_MODE_INV, TRACK_MODE_AUTOINV = 128}; TRACK_MODE_MAIN_INV = TRACK_MODE_MAIN|TRACK_MODIFIER_INV,
TRACK_MODE_MAIN_AUTO = TRACK_MODE_MAIN|TRACK_MODIFIER_AUTO,
TRACK_MODE_DC_INV = TRACK_MODE_DC|TRACK_MODIFIER_INV,
TRACK_MODE_DCX = TRACK_MODE_DC_INV // DCX is other name for historical reasons
};
#define setHIGH(fastpin) *fastpin.inout |= fastpin.maskHIGH #define setHIGH(fastpin) *fastpin.inout |= fastpin.maskHIGH
#define setLOW(fastpin) *fastpin.inout &= fastpin.maskLOW #define setLOW(fastpin) *fastpin.inout &= fastpin.maskLOW
@ -273,7 +285,7 @@ class MotorDriver {
#endif #endif
inline void setMode(TRACK_MODE m) { inline void setMode(TRACK_MODE m) {
trackMode = m; trackMode = m;
invertOutput(trackMode & TRACK_MODE_INV); invertOutput(trackMode & TRACK_MODIFIER_INV);
}; };
inline void invertOutput() { // toggles output inversion inline void invertOutput() { // toggles output inversion
invertPhase = !invertPhase; invertPhase = !invertPhase;

View File

@ -151,8 +151,8 @@ void TrackManager::setDCCSignal( bool on) {
HAVE_PORTD(shadowPORTD=PORTD); HAVE_PORTD(shadowPORTD=PORTD);
HAVE_PORTE(shadowPORTE=PORTE); HAVE_PORTE(shadowPORTE=PORTE);
HAVE_PORTF(shadowPORTF=PORTF); HAVE_PORTF(shadowPORTF=PORTF);
HAVE_PORTG(shadowPORTF=PORTG); HAVE_PORTG(shadowPORTG=PORTG);
HAVE_PORTH(shadowPORTF=PORTH); HAVE_PORTH(shadowPORTH=PORTH);
APPLY_BY_MODE(TRACK_MODE_MAIN,setSignal(on)); APPLY_BY_MODE(TRACK_MODE_MAIN,setSignal(on));
HAVE_PORTA(PORTA=shadowPORTA); HAVE_PORTA(PORTA=shadowPORTA);
HAVE_PORTB(PORTB=shadowPORTB); HAVE_PORTB(PORTB=shadowPORTB);
@ -160,8 +160,8 @@ void TrackManager::setDCCSignal( bool on) {
HAVE_PORTD(PORTD=shadowPORTD); HAVE_PORTD(PORTD=shadowPORTD);
HAVE_PORTE(PORTE=shadowPORTE); HAVE_PORTE(PORTE=shadowPORTE);
HAVE_PORTF(PORTF=shadowPORTF); HAVE_PORTF(PORTF=shadowPORTF);
HAVE_PORTG(shadowPORTF=PORTG); HAVE_PORTG(shadowPORTG=PORTG);
HAVE_PORTH(shadowPORTF=PORTH); HAVE_PORTH(shadowPORTH=PORTH);
} }
// setPROGSignal(), called from interrupt context // setPROGSignal(), called from interrupt context
@ -173,8 +173,8 @@ void TrackManager::setPROGSignal( bool on) {
HAVE_PORTD(shadowPORTD=PORTD); HAVE_PORTD(shadowPORTD=PORTD);
HAVE_PORTE(shadowPORTE=PORTE); HAVE_PORTE(shadowPORTE=PORTE);
HAVE_PORTF(shadowPORTF=PORTF); HAVE_PORTF(shadowPORTF=PORTF);
HAVE_PORTG(shadowPORTF=PORTG); HAVE_PORTG(shadowPORTG=PORTG);
HAVE_PORTH(shadowPORTF=PORTH); HAVE_PORTH(shadowPORTH=PORTH);
APPLY_BY_MODE(TRACK_MODE_PROG,setSignal(on)); APPLY_BY_MODE(TRACK_MODE_PROG,setSignal(on));
HAVE_PORTA(PORTA=shadowPORTA); HAVE_PORTA(PORTA=shadowPORTA);
HAVE_PORTB(PORTB=shadowPORTB); HAVE_PORTB(PORTB=shadowPORTB);
@ -182,8 +182,8 @@ void TrackManager::setPROGSignal( bool on) {
HAVE_PORTD(PORTD=shadowPORTD); HAVE_PORTD(PORTD=shadowPORTD);
HAVE_PORTE(PORTE=shadowPORTE); HAVE_PORTE(PORTE=shadowPORTE);
HAVE_PORTF(PORTF=shadowPORTF); HAVE_PORTF(PORTF=shadowPORTF);
HAVE_PORTG(shadowPORTF=PORTG); HAVE_PORTG(shadowPORTG=PORTG);
HAVE_PORTH(shadowPORTF=PORTH); HAVE_PORTH(shadowPORTH=PORTH);
} }
// setDCSignal(), called from normal context // setDCSignal(), called from normal context
@ -389,6 +389,10 @@ bool TrackManager::parseEqualSign(Print *stream, int16_t params, int16_t p[])
if (params==2 && p[1]=="MAIN"_hk) // <= id MAIN> if (params==2 && p[1]=="MAIN"_hk) // <= id MAIN>
return setTrackMode(p[0],TRACK_MODE_MAIN); return setTrackMode(p[0],TRACK_MODE_MAIN);
if (params==2 && p[1]=="MAIN_INV"_hk) // <= id MAIN_INV>
return setTrackMode(p[0],TRACK_MODE_MAIN_INV);
if (params==2 && p[1]=="MAIN_AUTO"_hk) // <= id MAIN_AUTO>
return setTrackMode(p[0],TRACK_MODE_MAIN_AUTO);
#ifndef DISABLE_PROG #ifndef DISABLE_PROG
if (params==2 && p[1]=="PROG"_hk) // <= id PROG> if (params==2 && p[1]=="PROG"_hk) // <= id PROG>
@ -404,18 +408,25 @@ bool TrackManager::parseEqualSign(Print *stream, int16_t params, int16_t p[])
if (TRACK_MODE_BOOST != 0 && // compile time optimization if (TRACK_MODE_BOOST != 0 && // compile time optimization
params==2 && p[1]=="BOOST"_hk) // <= id BOOST> params==2 && p[1]=="BOOST"_hk) // <= id BOOST>
return setTrackMode(p[0],TRACK_MODE_BOOST); return setTrackMode(p[0],TRACK_MODE_BOOST);
if (TRACK_MODE_BOOST_INV != 0 && // compile time optimization
params==2 && p[1]=="BOOST_INV"_hk) // <= id BOOST_INV>
return setTrackMode(p[0],TRACK_MODE_BOOST_INV);
if (TRACK_MODE_BOOST_AUTO != 0 && // compile time optimization
params==2 && p[1]=="BOOST_AUTO"_hk) // <= id BOOST_AUTO>
return setTrackMode(p[0],TRACK_MODE_BOOST_AUTO);
#endif #endif
if (params==2 && p[1]=="AUTO"_hk) // <= id AUTO> if (params==2 && p[1]=="AUTO"_hk) // <= id AUTO>
return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODE_AUTOINV); return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODIFIER_AUTO);
if (params==2 && p[1]=="INV"_hk) // <= id INV> if (params==2 && p[1]=="INV"_hk) // <= id INV>
return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODE_INV); return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODIFIER_INV);
if (params==3 && p[1]=="DC"_hk && p[2]>0) // <= id DC cab> if (params==3 && p[1]=="DC"_hk && p[2]>0) // <= id DC cab>
return setTrackMode(p[0],TRACK_MODE_DC,p[2]); return setTrackMode(p[0],TRACK_MODE_DC,p[2]);
if (params==3 && p[1]=="DCX"_hk && p[2]>0) // <= id DCX cab> if (params==3 && (p[1]=="DC_INV"_hk || // <= id DC_INV cab>
return setTrackMode(p[0],TRACK_MODE_DC|TRACK_MODE_INV,p[2]); p[1]=="DCX"_hk) && p[2]>0) // <= id DCX cab>
return setTrackMode(p[0],TRACK_MODE_DC_INV,p[2]);
return false; return false;
} }
@ -424,9 +435,9 @@ const FSH* TrackManager::getModeName(TRACK_MODE tm) {
const FSH *modename=F("---"); const FSH *modename=F("---");
if (tm & TRACK_MODE_MAIN) { if (tm & TRACK_MODE_MAIN) {
if(tm & TRACK_MODE_AUTOINV) if(tm & TRACK_MODIFIER_AUTO)
modename=F("MAIN A"); modename=F("MAIN A");
else if (tm & TRACK_MODE_INV) else if (tm & TRACK_MODIFIER_INV)
modename=F("MAIN I>\n"); modename=F("MAIN I>\n");
else else
modename=F("MAIN"); modename=F("MAIN");
@ -440,15 +451,15 @@ const FSH* TrackManager::getModeName(TRACK_MODE tm) {
else if(tm & TRACK_MODE_EXT) else if(tm & TRACK_MODE_EXT)
modename=F("EXT"); modename=F("EXT");
else if(tm & TRACK_MODE_BOOST) { else if(tm & TRACK_MODE_BOOST) {
if(tm & TRACK_MODE_AUTOINV) if(tm & TRACK_MODIFIER_AUTO)
modename=F("BOOST A"); modename=F("BOOST A");
else if (tm & TRACK_MODE_INV) else if (tm & TRACK_MODIFIER_INV)
modename=F("BOOST I"); modename=F("BOOST I");
else else
modename=F("BOOST"); modename=F("BOOST");
} }
else if (tm & TRACK_MODE_DC) { else if (tm & TRACK_MODE_DC) {
if (tm & TRACK_MODE_INV) if (tm & TRACK_MODIFIER_INV)
modename=F("DCX"); modename=F("DCX");
else else
modename=F("DC"); modename=F("DC");

View File

@ -72,8 +72,9 @@ Stream * WifiInterface::wifiStream;
#elif defined(ARDUINO_NUCLEO_F413ZH) || defined(ARDUINO_NUCLEO_F429ZI) \ #elif defined(ARDUINO_NUCLEO_F413ZH) || defined(ARDUINO_NUCLEO_F429ZI) \
|| defined(ARDUINO_NUCLEO_F446ZE) || defined(ARDUINO_NUCLEO_F412ZG) \ || defined(ARDUINO_NUCLEO_F446ZE) || defined(ARDUINO_NUCLEO_F412ZG) \
|| defined(ARDUINO_NUCLEO_F439ZI) || defined(ARDUINO_NUCLEO_F4X9ZI) || defined(ARDUINO_NUCLEO_F439ZI) || defined(ARDUINO_NUCLEO_F4X9ZI)
#define NUM_SERIAL 2 #define NUM_SERIAL 3
#define SERIAL1 Serial6 #define SERIAL1 Serial6
#define SERIAL3 Serial2
#else #else
#warning This variant of Nucleo not yet explicitly supported #warning This variant of Nucleo not yet explicitly supported
#endif #endif

View File

@ -3,7 +3,9 @@
#include "StringFormatter.h" #include "StringFormatter.h"
#define VERSION "5.2.81" #define VERSION "5.2.83"
// 5.2.83 - Various STM32 related fixes for serial ports, I2C pullups now turned off, and shadowing of PORTG/PORTH for TrackManager now correct
// 5.2.82 - TrackManager and EXRAIL: Introduce more consistent names for <= ...> and SET_TRACK
// 5.2.81 - STM32 Ethernet boards support, also now have specific EX8874 motor driver definition // 5.2.81 - STM32 Ethernet boards support, also now have specific EX8874 motor driver definition
// 5.2.80 - EthernetInterface upgrade, including STM32 Ethernet support // 5.2.80 - EthernetInterface upgrade, including STM32 Ethernet support
// 5.2.79 - serial manager loop that handles quoted strings // 5.2.79 - serial manager loop that handles quoted strings