Skip to content

Commit

Permalink
Merge branch 'devel-stm32-cmri' into devel-Ash-temp
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-4 authored Dec 13, 2023
2 parents 1881d4c + 6fab3a5 commit b4f40c1
Show file tree
Hide file tree
Showing 10 changed files with 869 additions and 33 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
63 changes: 49 additions & 14 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 @@ -55,24 +58,48 @@ void EthernetInterface::setup()
*/
EthernetInterface::EthernetInterface()
{
byte mac[6];
DCCTimer::getSimulatedMacAddress(mac);
connected=false;

#ifdef IP_ADDRESS
Ethernet.begin(mac, IP_ADDRESS);
#else
if (Ethernet.begin(mac) == 0)
#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
if (Ethernet.begin(IP_ADDRESS) == 0)
#else
if (Ethernet.begin() == 0)
#endif // IP_ADDRESS
{
DIAG(F("Ethernet.begin FAILED"));
return;
}
#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
if (Ethernet.begin(IP_ADDRESS) == 0)
#else
if (Ethernet.begin(mac, IP_ADDRESS) == 0)
#endif
{
DIAG(F("Ethernet.begin FAILED"));
return;
}
#endif

if (Ethernet.hardwareStatus() == EthernetNoHardware) {
DIAG(F("Ethernet shield not found or W5100"));
}

unsigned long startmilli = millis();
#endif

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 @@ -171,17 +198,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
2 changes: 1 addition & 1 deletion 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
Loading

0 comments on commit b4f40c1

Please sign in to comment.