From 33c8ed19a9a5f6f459e754836e688ec55200769b Mon Sep 17 00:00:00 2001 From: pmantoine Date: Mon, 30 Sep 2024 16:13:00 +0800 Subject: [PATCH] Various STM32 related fixes --- DCCTimerSTM32.cpp | 8 ++++---- I2CManager_STM32.h | 4 ++-- TrackManager.cpp | 16 ++++++++-------- WifiInterface.cpp | 3 ++- version.h | 3 ++- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/DCCTimerSTM32.cpp b/DCCTimerSTM32.cpp index 0917455a..df00df38 100644 --- a/DCCTimerSTM32.cpp +++ b/DCCTimerSTM32.cpp @@ -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) // Nucleo-144 boards don't have Serial1 defined by default HardwareSerial Serial6(PG9, PG14); // Rx=PG9, Tx=PG14 -- USART6 -HardwareSerial Serial5(PD2, PC12); // Rx=PD2, Tx=PC12 -- UART5 -#if !defined(ARDUINO_NUCLEO_F412ZG) - HardwareSerial Serial2(PD6, PD5); // Rx=PD6, Tx=PD5 -- UART5 +HardwareSerial Serial2(PD6, PD5); // Rx=PD6, Tx=PD5 -- UART2 +#if !defined(ARDUINO_NUCLEO_F412ZG) // F412ZG does not have UART5 + HardwareSerial Serial5(PD2, PC12); // Rx=PD2, Tx=PC12 -- UART5 #endif // 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. @@ -328,7 +328,7 @@ void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t frequency if (pin_timer[pin] != NULL) { 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 DIAG(F("DCCEXanalogWriteFrequency::failed to allocate HardwareTimer instance!")); diff --git a/I2CManager_STM32.h b/I2CManager_STM32.h index 109c89b4..45c924fb 100644 --- a/I2CManager_STM32.h +++ b/I2CManager_STM32.h @@ -1,5 +1,5 @@ /* - * © 2022-23 Paul M Antoine + * © 2022-24 Paul M Antoine * © 2023, Neil McKechnie * 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->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 |= (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: // 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 diff --git a/TrackManager.cpp b/TrackManager.cpp index a1641422..c6a30add 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -151,8 +151,8 @@ void TrackManager::setDCCSignal( bool on) { HAVE_PORTD(shadowPORTD=PORTD); HAVE_PORTE(shadowPORTE=PORTE); HAVE_PORTF(shadowPORTF=PORTF); - HAVE_PORTG(shadowPORTF=PORTG); - HAVE_PORTH(shadowPORTF=PORTH); + HAVE_PORTG(shadowPORTG=PORTG); + HAVE_PORTH(shadowPORTH=PORTH); APPLY_BY_MODE(TRACK_MODE_MAIN,setSignal(on)); HAVE_PORTA(PORTA=shadowPORTA); HAVE_PORTB(PORTB=shadowPORTB); @@ -160,8 +160,8 @@ void TrackManager::setDCCSignal( bool on) { HAVE_PORTD(PORTD=shadowPORTD); HAVE_PORTE(PORTE=shadowPORTE); HAVE_PORTF(PORTF=shadowPORTF); - HAVE_PORTG(shadowPORTF=PORTG); - HAVE_PORTH(shadowPORTF=PORTH); + HAVE_PORTG(shadowPORTG=PORTG); + HAVE_PORTH(shadowPORTH=PORTH); } // setPROGSignal(), called from interrupt context @@ -173,8 +173,8 @@ void TrackManager::setPROGSignal( bool on) { HAVE_PORTD(shadowPORTD=PORTD); HAVE_PORTE(shadowPORTE=PORTE); HAVE_PORTF(shadowPORTF=PORTF); - HAVE_PORTG(shadowPORTF=PORTG); - HAVE_PORTH(shadowPORTF=PORTH); + HAVE_PORTG(shadowPORTG=PORTG); + HAVE_PORTH(shadowPORTH=PORTH); APPLY_BY_MODE(TRACK_MODE_PROG,setSignal(on)); HAVE_PORTA(PORTA=shadowPORTA); HAVE_PORTB(PORTB=shadowPORTB); @@ -182,8 +182,8 @@ void TrackManager::setPROGSignal( bool on) { HAVE_PORTD(PORTD=shadowPORTD); HAVE_PORTE(PORTE=shadowPORTE); HAVE_PORTF(PORTF=shadowPORTF); - HAVE_PORTG(shadowPORTF=PORTG); - HAVE_PORTH(shadowPORTF=PORTH); + HAVE_PORTG(shadowPORTG=PORTG); + HAVE_PORTH(shadowPORTH=PORTH); } // setDCSignal(), called from normal context diff --git a/WifiInterface.cpp b/WifiInterface.cpp index fcf99324..6b6ec4af 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -72,8 +72,9 @@ Stream * WifiInterface::wifiStream; #elif defined(ARDUINO_NUCLEO_F413ZH) || defined(ARDUINO_NUCLEO_F429ZI) \ || defined(ARDUINO_NUCLEO_F446ZE) || defined(ARDUINO_NUCLEO_F412ZG) \ || defined(ARDUINO_NUCLEO_F439ZI) || defined(ARDUINO_NUCLEO_F4X9ZI) -#define NUM_SERIAL 2 +#define NUM_SERIAL 3 #define SERIAL1 Serial6 +#define SERIAL3 Serial2 #else #warning This variant of Nucleo not yet explicitly supported #endif diff --git a/version.h b/version.h index c6d0556a..a955a868 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,8 @@ #include "StringFormatter.h" -#define VERSION "5.2.82" +#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.80 - EthernetInterface upgrade, including STM32 Ethernet support