From 49fa96c4176abbaa1a6edc68f390ddce2cf41e5f Mon Sep 17 00:00:00 2001 From: Martin Ayotte Date: Wed, 16 Dec 2015 16:18:36 -0500 Subject: [PATCH] add a timeout exit loop when Enc28J60Network never ready --- .../arduino_uip/examples/TcpClient/TcpClient.ino | 8 ++++---- STM32F4/libraries/arduino_uip/library.properties | 2 +- .../arduino_uip/utility/Enc28J60Network.cpp | 9 +++++++-- .../libraries/arduino_uip/utility/Enc28J60Network.h | 13 ++++--------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/STM32F4/libraries/arduino_uip/examples/TcpClient/TcpClient.ino b/STM32F4/libraries/arduino_uip/examples/TcpClient/TcpClient.ino index 444b36a..380a424 100644 --- a/STM32F4/libraries/arduino_uip/examples/TcpClient/TcpClient.ino +++ b/STM32F4/libraries/arduino_uip/examples/TcpClient/TcpClient.ino @@ -30,13 +30,13 @@ void setup() { Ethernet.begin(mac); Serial.print("localIP: "); - Serial.println(Ethernet.localIP()); + Serial.println(Ethernet.localIP().toString()); Serial.print("subnetMask: "); - Serial.println(Ethernet.subnetMask()); + Serial.println(Ethernet.subnetMask().toString()); Serial.print("gatewayIP: "); - Serial.println(Ethernet.gatewayIP()); + Serial.println(Ethernet.gatewayIP().toString()); Serial.print("dnsServerIP: "); - Serial.println(Ethernet.dnsServerIP()); + Serial.println(Ethernet.dnsServerIP().toString()); next = 0; } diff --git a/STM32F4/libraries/arduino_uip/library.properties b/STM32F4/libraries/arduino_uip/library.properties index 8ee6394..34e9709 100644 --- a/STM32F4/libraries/arduino_uip/library.properties +++ b/STM32F4/libraries/arduino_uip/library.properties @@ -4,7 +4,7 @@ email=Norbert Truchsess sentence=Ethernet library for ENC28J60 paragraph=implements the same API as stock Ethernet-lib. Just replace the include of Ethernet.h with UIPEthernet.h url=https://github.com/ntruchsess/arduino_uip -architectures=STM32F1 +architectures=STM32F4 version=1.04 dependencies= core-dependencies=arduino (>=1.5.0) diff --git a/STM32F4/libraries/arduino_uip/utility/Enc28J60Network.cpp b/STM32F4/libraries/arduino_uip/utility/Enc28J60Network.cpp index 1b6b189..33712e0 100644 --- a/STM32F4/libraries/arduino_uip/utility/Enc28J60Network.cpp +++ b/STM32F4/libraries/arduino_uip/utility/Enc28J60Network.cpp @@ -57,6 +57,7 @@ static byte selectPin; void Enc28J60Network::init(uint8_t* macaddr) { + uint32 timeout = 0; MemoryPool::init(); // 1 byte in between RX_STOP_INIT and pool to allow prepending of controlbyte // initialize I/O // ss as output: @@ -100,8 +101,12 @@ void Enc28J60Network::init(uint8_t* macaddr) #ifdef ENC28J60DEBUG Serial.println("ENC28J60::initialize / before readOp(ENC28J60_READ_CTRL_REG, ESTAT)"); #endif - while (!readOp(ENC28J60_READ_CTRL_REG, ESTAT) & ESTAT_CLKRDY) - ; + while (!readOp(ENC28J60_READ_CTRL_REG, ESTAT) & ESTAT_CLKRDY) { + if (++timeout > 100000) { + Serial.println("ENC28J60::initialize TIMEOUT !!!\r\n"); + return; + } + } #ifdef ENC28J60DEBUG Serial.println("ENC28J60::initialize / after readOp(ENC28J60_READ_CTRL_REG, ESTAT)"); #endif diff --git a/STM32F4/libraries/arduino_uip/utility/Enc28J60Network.h b/STM32F4/libraries/arduino_uip/utility/Enc28J60Network.h index 4aee588..73a7934 100644 --- a/STM32F4/libraries/arduino_uip/utility/Enc28J60Network.h +++ b/STM32F4/libraries/arduino_uip/utility/Enc28J60Network.h @@ -28,17 +28,12 @@ #include #include "mempool.h" -//#define ENC28J60_CONTROL_CS SS -//#define SPI_MOSI MOSI -//#define SPI_MISO MISO -//#define SPI_SCK SCK -//#define SPI_SS SS +#ifdef ARDUINO_STM32F4_NETDUINO2PLUS #define ENC28J60_CONTROL_CS PC8 -//#define SPI_MOSI PA7 -//#define SPI_MISO PA6 -//#define SPI_SCK PA5 -//#define SPI_SS PA8 +#else +#define ENC28J60_CONTROL_CS SPI.nssPin() +#endif #define UIP_RECEIVEBUFFERHANDLE 0xff