Skip to content

Commit

Permalink
Merge branch 'devel-stm32EC' into devel-ash-temp0120
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-4 authored Jan 21, 2024
2 parents 811bce4 + 8503835 commit 057f45b
Show file tree
Hide file tree
Showing 15 changed files with 1,761 additions and 37 deletions.
6 changes: 3 additions & 3 deletions DCCTimerSTM32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ HardwareSerial Serial5(PD2, PC12); // Rx=PD2, Tx=PC12 -- UART5 - F446RE
defined(ARDUINO_NUCLEO_F429ZI) || defined(ARDUINO_NUCLEO_F439ZI)
// 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.
Expand Down
62 changes: 49 additions & 13 deletions EthernetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ void EthernetInterface::setup()
DIAG(F("Prog Error!"));
return;
}
if ((singleton=new EthernetInterface()))
DIAG(F("Ethernet Class setup, attempting to instantiate"));
if ((singleton=new EthernetInterface())) {
DIAG(F("Ethernet Class initialized"));
return;
}
DIAG(F("Ethernet not initialized"));
};

Expand All @@ -59,24 +62,47 @@ static IPAddress myIP(IP_ADDRESS);
*/
EthernetInterface::EthernetInterface()
{
byte mac[6];
DCCTimer::getSimulatedMacAddress(mac);
connected=false;

#ifdef IP_ADDRESS
#if defined(STM32_ETHERNET)
// Set a HOSTNAME for the DHCP request - a nice to have, but hard it seems on LWIP for STM32
// The default is "lwip", which is **always** set in STM32Ethernet/src/utility/ethernetif.cpp
// for some reason. One can edit it to instead read:
// #if LWIP_NETIF_HOSTNAME
// /* Initialize interface hostname */
// if (netif->hostname == NULL)
// netif->hostname = "lwip";
// #endif /* LWIP_NETIF_HOSTNAME */
// Which seems more useful! We should propose the patch... so the following line actually works!
netif_set_hostname(&gnetif, WIFI_HOSTNAME); // Should probably be passed in the contructor...
#ifdef IP_ADDRESS
Ethernet.begin(myIP);
#else
if (Ethernet.begin() == 0)
{
DIAG(F("Ethernet.begin FAILED"));
return;
}
#endif // IP_ADDRESS
#else // All other architectures
byte mac[6]= { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
DIAG(F("Ethernet attempting to get MAC address"));
DCCTimer::getSimulatedMacAddress(mac);
DIAG(F("Ethernet got MAC address"));
#ifdef IP_ADDRESS
Ethernet.begin(mac, myIP);
#else
#else
if (Ethernet.begin(mac) == 0)
{
DIAG(F("Ethernet.begin FAILED"));
return;
}
#endif
}
#endif // IP_ADDRESS
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
DIAG(F("Ethernet shield not found or W5100"));
}

unsigned long startmilli = millis();
#endif // STM32_ETHERNET

uint32_t startmilli = millis();
while ((millis() - startmilli) < 5500) { // Loop to give time to check for cable connection
if (Ethernet.linkStatus() == LinkON)
break;
Expand Down Expand Up @@ -140,8 +166,10 @@ bool EthernetInterface::checkLink() {
DIAG(F("Ethernet cable connected"));
connected=true;
#ifdef IP_ADDRESS
#ifndef STM32_ETHERNET
Ethernet.setLocalIP(myIP); // for static IP, set it again
#endif
#endif
IPAddress ip = Ethernet.localIP(); // look what IP was obtained (dynamic or static)
server = new EthernetServer(IP_PORT); // Ethernet Server listening on default port IP_PORT
server->begin();
Expand Down Expand Up @@ -175,17 +203,25 @@ void EthernetInterface::loop2() {
return;
}
// get client from the server
#if defined (STM32_ETHERNET)
// STM32Ethernet doesn't use accept(), just available()
EthernetClient client = server->available();
#else
EthernetClient client = server->accept();

#endif
// check for new client
if (client)
{
if (Diag::ETHERNET) DIAG(F("Ethernet: New client "));
byte socket;
for (socket = 0; socket < MAX_SOCK_NUM; socket++)
{
if (!clients[socket])
if (clients[socket]) {
if (clients[socket] == client)
break;
}
else //if (!clients[socket])
{
if (Diag::ETHERNET) DIAG(F("Ethernet: New client "));
// On accept() the EthernetServer doesn't track the client anymore
// so we store it in our client array
if (Diag::ETHERNET) DIAG(F("Socket %d"),socket);
Expand Down
10 changes: 10 additions & 0 deletions EthernetInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@
#if defined (ARDUINO_TEENSY41)
#include <NativeEthernet.h> //TEENSY Ethernet Treiber
#include <NativeEthernetUdp.h>
#define MAX_SOCK_NUM 4
#elif defined (ARDUINO_NUCLEO_F429ZI) || defined (ARDUINO_NUCLEO_F439ZI)
#include <LwIP.h>
// #include "STM32lwipopts.h"
#include <STM32Ethernet.h>
#include <lwip/netif.h>
extern "C" struct netif gnetif;
#define STM32_ETHERNET
#define MAX_SOCK_NUM 10
#else
#include "Ethernet.h"
#define MAX_SOCK_NUM 4
#endif
#include "RingStream.h"

Expand Down
9 changes: 6 additions & 3 deletions I2CManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ static const FSH * guessI2CDeviceType(uint8_t address) {
return F("Time-of-flight sensor");
else if (address >= 0x3c && address <= 0x3d)
return F("OLED Display");
else if (address >= 0x48 && address <= 0x57) // Henkk: Added SC16IS752 UART detection
return F("SC16IS752 UART");
else if (address >= 0x48 && address <= 0x4f)
return F("Analogue Inputs or PWM");
else if (address >= 0x40 && address <= 0x4f)
Expand All @@ -64,8 +66,9 @@ static const FSH * guessI2CDeviceType(uint8_t address) {
return F("Real-time clock");
else if (address >= 0x70 && address <= 0x77)
return F("I2C Mux");
else
return F("?");
else if (address >= 0x90 && address <= 0xAE)
return F("UART");
return F("?");
}

// If not already initialised, initialise I2C
Expand Down Expand Up @@ -363,4 +366,4 @@ void I2CAddress::toHex(const uint8_t value, char *buffer) {

/* static */ bool I2CAddress::_addressWarningDone = false;

#endif
#endif
4 changes: 2 additions & 2 deletions I2CManager_STM32.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#if defined(I2C_USE_INTERRUPTS) && defined(ARDUINO_ARCH_STM32)
#if defined(ARDUINO_NUCLEO_F401RE) || defined(ARDUINO_NUCLEO_F411RE) || defined(ARDUINO_NUCLEO_F446RE) \
|| defined(ARDUINO_NUCLEO_F412ZG) || defined(ARDUINO_NUCLEO_F413ZH) \
|| defined(ARDUINO_NUCLEO_F429ZI) || defined(ARDUINO_NUCLEO_F446ZE)
|| defined(ARDUINO_NUCLEO_F429ZI) || defined(ARDUINO_NUCLEO_F439ZI) || defined(ARDUINO_NUCLEO_F446ZE)
// Assume I2C1 for now - default I2C bus on Nucleo-F411RE and likely all Nucleo-64
// and Nucleo-144 variants
I2C_TypeDef *s = I2C1;
Expand Down Expand Up @@ -184,7 +184,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
Expand Down
3 changes: 2 additions & 1 deletion IODevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#define iodevice_h

// Define symbol DIAG_IO to enable diagnostic output
//#define DIAG_IO Y
//#define DIAG_IO


// Define symbol DIAG_LOOPTIMES to enable CS loop execution time to be reported
//#define DIAG_LOOPTIMES
Expand Down
Loading

0 comments on commit 057f45b

Please sign in to comment.