mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 16:16:13 +01:00
Merge pull request #370 from DCC-EX/devel-stm32-eth
stm32-Ethernet with cmri
This commit is contained in:
commit
d893b16783
|
@ -41,8 +41,11 @@ void EthernetInterface::setup()
|
||||||
DIAG(F("Prog Error!"));
|
DIAG(F("Prog Error!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((singleton=new EthernetInterface()))
|
DIAG(F("Ethernet Class setup, attempting to instantiate"));
|
||||||
|
if ((singleton=new EthernetInterface())) {
|
||||||
|
DIAG(F("Ethernet Class initialized"));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
DIAG(F("Ethernet not initialized"));
|
DIAG(F("Ethernet not initialized"));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,24 +58,48 @@ void EthernetInterface::setup()
|
||||||
*/
|
*/
|
||||||
EthernetInterface::EthernetInterface()
|
EthernetInterface::EthernetInterface()
|
||||||
{
|
{
|
||||||
byte mac[6];
|
|
||||||
DCCTimer::getSimulatedMacAddress(mac);
|
|
||||||
connected=false;
|
connected=false;
|
||||||
|
#if defined(STM32_ETHERNET)
|
||||||
#ifdef IP_ADDRESS
|
// Set a HOSTNAME for the DHCP request - a nice to have, but hard it seems on LWIP for STM32
|
||||||
Ethernet.begin(mac, IP_ADDRESS);
|
// The default is "lwip", which is **always** set in STM32Ethernet/src/utility/ethernetif.cpp
|
||||||
#else
|
// for some reason. One can edit it to instead read:
|
||||||
if (Ethernet.begin(mac) == 0)
|
// #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"));
|
DIAG(F("Ethernet.begin FAILED"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
|
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
|
||||||
DIAG(F("Ethernet shield not found or W5100"));
|
DIAG(F("Ethernet shield not found or W5100"));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned long startmilli = millis();
|
uint32_t startmilli = millis();
|
||||||
while ((millis() - startmilli) < 5500) { // Loop to give time to check for cable connection
|
while ((millis() - startmilli) < 5500) { // Loop to give time to check for cable connection
|
||||||
if (Ethernet.linkStatus() == LinkON)
|
if (Ethernet.linkStatus() == LinkON)
|
||||||
break;
|
break;
|
||||||
|
@ -171,17 +198,25 @@ void EthernetInterface::loop2() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// get client from the server
|
// 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();
|
EthernetClient client = server->accept();
|
||||||
|
#endif
|
||||||
// check for new client
|
// check for new client
|
||||||
if (client)
|
if (client)
|
||||||
{
|
{
|
||||||
if (Diag::ETHERNET) DIAG(F("Ethernet: New client "));
|
|
||||||
byte socket;
|
byte socket;
|
||||||
for (socket = 0; socket < MAX_SOCK_NUM; 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
|
// On accept() the EthernetServer doesn't track the client anymore
|
||||||
// so we store it in our client array
|
// so we store it in our client array
|
||||||
if (Diag::ETHERNET) DIAG(F("Socket %d"),socket);
|
if (Diag::ETHERNET) DIAG(F("Socket %d"),socket);
|
||||||
|
|
|
@ -35,8 +35,18 @@
|
||||||
#if defined (ARDUINO_TEENSY41)
|
#if defined (ARDUINO_TEENSY41)
|
||||||
#include <NativeEthernet.h> //TEENSY Ethernet Treiber
|
#include <NativeEthernet.h> //TEENSY Ethernet Treiber
|
||||||
#include <NativeEthernetUdp.h>
|
#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
|
#else
|
||||||
#include "Ethernet.h"
|
#include "Ethernet.h"
|
||||||
|
#define MAX_SOCK_NUM 4
|
||||||
#endif
|
#endif
|
||||||
#include "RingStream.h"
|
#include "RingStream.h"
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,8 @@
|
||||||
#if defined(I2C_USE_INTERRUPTS) && defined(ARDUINO_ARCH_STM32)
|
#if defined(I2C_USE_INTERRUPTS) && defined(ARDUINO_ARCH_STM32)
|
||||||
#if defined(ARDUINO_NUCLEO_F401RE) || defined(ARDUINO_NUCLEO_F411RE) || defined(ARDUINO_NUCLEO_F446RE) \
|
#if defined(ARDUINO_NUCLEO_F401RE) || defined(ARDUINO_NUCLEO_F411RE) || defined(ARDUINO_NUCLEO_F446RE) \
|
||||||
|| defined(ARDUINO_NUCLEO_F412ZG) || defined(ARDUINO_NUCLEO_F413ZH) \
|
|| 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
|
// Assume I2C1 for now - default I2C bus on Nucleo-F411RE and likely all Nucleo-64
|
||||||
// and Nucleo-144 variants
|
// and Nucleo-144 variants
|
||||||
I2C_TypeDef *s = I2C1;
|
I2C_TypeDef *s = I2C1;
|
||||||
|
|
|
@ -30,7 +30,6 @@ include_dir = .
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
build_flags = -Wall -Wextra
|
build_flags = -Wall -Wextra
|
||||||
; monitor_filters = time
|
|
||||||
|
|
||||||
[env:samd21-dev-usb]
|
[env:samd21-dev-usb]
|
||||||
platform = atmelsam
|
platform = atmelsam
|
||||||
|
@ -245,18 +244,32 @@ monitor_echo = yes
|
||||||
|
|
||||||
; Experimental - Ethernet work still in progress
|
; Experimental - Ethernet work still in progress
|
||||||
;
|
;
|
||||||
; [env:Nucleo-F429ZI]
|
[env:Nucleo-F429ZI]
|
||||||
; platform = ststm32
|
platform = ststm32
|
||||||
; board = nucleo_f429zi
|
board = nucleo_f429zi
|
||||||
; framework = arduino
|
framework = arduino
|
||||||
; lib_deps = ${env.lib_deps}
|
lib_deps = ${env.lib_deps}
|
||||||
; arduino-libraries/Ethernet @ ^2.0.1
|
stm32duino/STM32Ethernet @ ^1.3.0
|
||||||
; stm32duino/STM32Ethernet @ ^1.3.0
|
stm32duino/STM32duino LwIP @ ^2.1.2
|
||||||
; stm32duino/STM32duino LwIP @ ^2.1.2
|
build_flags = -std=c++17 -Os -g2 -Wunused-variable
|
||||||
; build_flags = -std=c++17 -Os -g2 -Wunused-variable
|
monitor_speed = 115200
|
||||||
; monitor_speed = 115200
|
monitor_echo = yes
|
||||||
; monitor_echo = yes
|
upload_protocol = stlink
|
||||||
; upload_protocol = stlink
|
|
||||||
|
; Experimental - Ethernet work still in progress
|
||||||
|
; Commented out as the F439ZI also needs variant files
|
||||||
|
;
|
||||||
|
[env:Nucleo-F439ZI]
|
||||||
|
platform = ststm32
|
||||||
|
board = nucleo_f439zi
|
||||||
|
framework = arduino
|
||||||
|
lib_deps = ${env.lib_deps}
|
||||||
|
stm32duino/STM32Ethernet @ ^1.3.0
|
||||||
|
stm32duino/STM32duino LwIP @ ^2.1.2
|
||||||
|
build_flags = -std=c++17 -Os -g2 -Wunused-variable
|
||||||
|
monitor_speed = 115200
|
||||||
|
monitor_echo = yes
|
||||||
|
upload_protocol = stlink
|
||||||
|
|
||||||
[env:Teensy3_2]
|
[env:Teensy3_2]
|
||||||
platform = teensy
|
platform = teensy
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
|
|
||||||
#include "StringFormatter.h"
|
#include "StringFormatter.h"
|
||||||
|
|
||||||
#define VERSION "5.2.14"
|
#define VERSION "5.2.14eth"
|
||||||
|
// 5.2.14eth - Initial ethernet code for STM32F429ZI and F439ZI boards
|
||||||
|
// - CMRI RS485 connection
|
||||||
// 5.2.14 - Reminder window DCC packet optimization
|
// 5.2.14 - Reminder window DCC packet optimization
|
||||||
// - Optional #define DISABLE_FUNCTION_REMINDERS
|
// - Optional #define DISABLE_FUNCTION_REMINDERS
|
||||||
// 5.2.13 - EXRAIL STEALTH
|
// 5.2.13 - EXRAIL STEALTH
|
||||||
|
|
Loading…
Reference in New Issue
Block a user