From 34955150516bfc8ae418a554f9b879037b3e86f5 Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Sun, 10 Apr 2022 18:58:58 -0400 Subject: [PATCH] v1.3.2 to use `Ethernet_Generic` library ### Releases v1.3.2 1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00. 2. Add example [multiFileProject](examples/multiFileProject) to demo how to avoid `multiple-definitions` linker error for multiple-file project 3. Rewrite all the examples to support new features --- .../AM2315_Ethernet_STM32.ino | 161 ++++++++--------- examples/AM2315_Ethernet_STM32/defines.h | 18 +- .../AM2315_Ethernet_STM32_LAN8720.ino | 6 +- .../AM2315_Ethernet_STM32_LAN8720/defines.h | 18 +- .../DHT11_Ethernet_STM32.ino | 163 ++++++++---------- examples/DHT11_Ethernet_STM32/defines.h | 18 +- .../DHT11_Ethernet_STM32_LAN8720.ino | 6 +- .../DHT11_Ethernet_STM32_LAN8720/defines.h | 16 +- examples/Ethernet_STM32/Ethernet_STM32.ino | 154 ++++++++--------- examples/Ethernet_STM32/defines.h | 16 +- .../Ethernet_STM32_LAN8720.ino | 8 +- examples/Ethernet_STM32_LAN8720/defines.h | 20 ++- .../MQTT_ThingStream_Ethernet_STM32.ino | 159 ++++++++--------- .../MQTT_ThingStream_Ethernet_STM32/defines.h | 20 ++- ...QTT_ThingStream_Ethernet_STM32_LAN8720.ino | 6 +- .../defines.h | 16 +- .../multiFileProject/multiFileProject.cpp | 14 ++ examples/multiFileProject/multiFileProject.h | 24 +++ .../multiFileProject/multiFileProject.ino | 46 +++++ 19 files changed, 468 insertions(+), 421 deletions(-) create mode 100644 examples/multiFileProject/multiFileProject.cpp create mode 100644 examples/multiFileProject/multiFileProject.h create mode 100644 examples/multiFileProject/multiFileProject.ino diff --git a/examples/AM2315_Ethernet_STM32/AM2315_Ethernet_STM32.ino b/examples/AM2315_Ethernet_STM32/AM2315_Ethernet_STM32.ino index 34c8b3e..e2bbeb3 100644 --- a/examples/AM2315_Ethernet_STM32/AM2315_Ethernet_STM32.ino +++ b/examples/AM2315_Ethernet_STM32/AM2315_Ethernet_STM32.ino @@ -64,10 +64,10 @@ void heartBeatPrint() localEthernetIP = Ethernet.localIP(); -#if (USE_ETHERNET2 || USE_ETHERNET3) +#if (USE_ETHERNET_GENERIC) // To modify Ethernet2 library linkStatus = Ethernet.link(); - ET_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == 1) ? F("LinkON") : F("LinkOFF") ); + ETM_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == 1) ? F("LinkON") : F("LinkOFF") ); if ( ( linkStatus == 1 ) && ((uint32_t) localEthernetIP != 0) ) #else @@ -75,7 +75,7 @@ void heartBeatPrint() // The linkStatus() is not working with W5100. Just using IP != 0.0.0.0 // Better to use ping for W5100 linkStatus = (int) Ethernet.linkStatus(); - ET_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == LinkON) ? F("LinkON") : F("LinkOFF") ); + ETM_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == LinkON) ? F("LinkON") : F("LinkOFF") ); if ( ( (linkStatus == LinkON) || !isW5500 ) && ((uint32_t) localEthernetIP != 0) ) #endif @@ -83,7 +83,7 @@ void heartBeatPrint() Serial.print(F("H")); } else - Serial.print(F("F")); + Serial.print(F("F")); if (num == 80) { @@ -118,50 +118,27 @@ void check_status() } } -#if USING_CUSTOMS_STYLE -const char NewCustomsStyle[] /*PROGMEM*/ = ""; -#endif - -void setup() +void initEthernet() { - // Debug console - Serial.begin(115200); - while (!Serial); - - Serial.print(F("\nStart AM2315_Ethernet_STM32 on ")); - Serial.println(BOARD_NAME); - Serial.print(F("Ethernet Shield type : ")); - Serial.println(SHIELD_TYPE); - Serial.println(ETHERNET_MANAGER_STM32_VERSION); - Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION); - #if ( defined(USE_BUILTIN_ETHERNET) && USE_BUILTIN_ETHERNET ) - ET_LOGWARN(F("======== USE_BUILTIN_ETHERNET ========")); + ETM_LOGWARN(F("======== USE_BUILTIN_ETHERNET ========")); #elif ( defined(USE_UIP_ETHERNET) && USE_UIP_ETHERNET ) - ET_LOGWARN(F("======== USE_UIP_ETHERNET ========")); - #elif USE_NATIVE_ETHERNET - ET_LOGWARN(F("======== USE_NATIVE_ETHERNET ========")); - #elif USE_ETHERNET - ET_LOGWARN(F("=========== USE_ETHERNET ===========")); - #elif USE_ETHERNET2 - ET_LOGWARN(F("=========== USE_ETHERNET2 ===========")); - #elif USE_ETHERNET3 - ET_LOGWARN(F("=========== USE_ETHERNET3 ===========")); - #elif USE_ETHERNET_LARGE - ET_LOGWARN(F("=========== USE_ETHERNET_LARGE ===========")); + ETM_LOGWARN(F("======== USE_UIP_ETHERNET ========")); + #elif USE_ETHERNET_GENERIC + ETM_LOGWARN(F("=========== USE_ETHERNET_GENERIC ===========")); #elif USE_ETHERNET_ENC - ET_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); + ETM_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); #else - ET_LOGWARN(F("=========================")); + ETM_LOGWARN(F("=========================")); #endif - - ET_LOGWARN(F("Default SPI pinout:")); - ET_LOGWARN1(F("MOSI:"), MOSI); - ET_LOGWARN1(F("MISO:"), MISO); - ET_LOGWARN1(F("SCK:"), SCK); - ET_LOGWARN1(F("SS:"), SS); - ET_LOGWARN(F("=========================")); + +#if !(USE_BUILTIN_ETHERNET ) + ETM_LOGWARN(F("Default SPI pinout:")); + ETM_LOGWARN1(F("MOSI:"), MOSI); + ETM_LOGWARN1(F("MISO:"), MISO); + ETM_LOGWARN1(F("SCK:"), SCK); + ETM_LOGWARN1(F("SS:"), SS); + ETM_LOGWARN(F("=========================")); // unknown board, do nothing, use default SS = 10 #ifndef USE_THIS_SS_PIN @@ -169,61 +146,72 @@ void setup() #endif #if defined(BOARD_NAME) - ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); + ETM_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); #else - ET_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN); + ETM_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN); #endif +#endif #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) - pinMode(SDCARD_CS, OUTPUT); - digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card - - #if USE_ETHERNET_WRAPPER + #if (defined(ETHERNET_WITH_SD_CARD) && ETHERNET_WITH_SD_CARD) + pinMode(SDCARD_CS, OUTPUT); + digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card + #endif - EthernetInit(); + // For other boards, to change if necessary + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - #else + Ethernet.init (USE_THIS_SS_PIN); + + #elif USE_CUSTOM_ETHERNET - // For other boards, to change if necessary - #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - - #elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - - #elif USE_CUSTOM_ETHERNET - - // You have to add initialization for your Custom Ethernet here - // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough - Ethernet.init(USE_THIS_SS_PIN); - - #endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE ) + // You have to add initialization for your Custom Ethernet here + // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough + Ethernet.init(USE_THIS_SS_PIN); - #endif //USE_ETHERNET_WRAPPER + #endif // ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) #endif +#if !(USE_BUILTIN_ETHERNET ) // Just info to know how to connect correctly - ET_LOGWARN(F("=========================")); - ET_LOGWARN(F("Currently Used SPI pinout:")); - ET_LOGWARN1(F("MOSI:"), MOSI); - ET_LOGWARN1(F("MISO:"), MISO); - ET_LOGWARN1(F("SCK:"), SCK); - ET_LOGWARN1(F("SS:"), SS); + #if defined(CUR_PIN_MISO) + ETM_LOGWARN(F("Currently Used SPI pinout:")); + ETM_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); + ETM_LOGWARN1(F("MISO:"), CUR_PIN_MISO); + ETM_LOGWARN1(F("SCK:"), CUR_PIN_SCK); + ETM_LOGWARN1(F("SS:"), CUR_PIN_SS); + #else + ETM_LOGWARN(F("Currently Used SPI pinout:")); + ETM_LOGWARN1(F("MOSI:"), MOSI); + ETM_LOGWARN1(F("MISO:"), MISO); + ETM_LOGWARN1(F("SCK:"), SCK); + ETM_LOGWARN1(F("SS:"), SS); + #endif -#if USE_ETHERNET3 - ET_LOGWARN1(F("SPI_CS:"), SPI_CS); + ETM_LOGWARN(F("=========================")); #endif - ET_LOGWARN(F("=========================")); - +} + +#if USING_CUSTOMS_STYLE +const char NewCustomsStyle[] /*PROGMEM*/ = ""; +#endif + +void setup() +{ + // Debug console + Serial.begin(115200); + while (!Serial); + + Serial.print(F("\nStart AM2315_Ethernet_STM32 on ")); Serial.println(BOARD_NAME); + Serial.print(F("Ethernet Shield type : ")); Serial.println(SHIELD_TYPE); + Serial.println(ETHERNET_MANAGER_STM32_VERSION); + Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION); + + initEthernet(); + ////////////////////////////////////////////// #if USING_CUSTOMS_STYLE @@ -244,12 +232,7 @@ void setup() localEthernetIP = Ethernet.localIP(); -#if (USE_ETHERNET2 || USE_ETHERNET3) - // To modify Ethernet2 library if ( (uint32_t) localEthernetIP != 0 ) -#else - if ( (uint32_t) localEthernetIP != 0 ) -#endif { Serial.print(F("Connected! IP address: ")); Serial.println(localEthernetIP); @@ -260,7 +243,7 @@ void setup() } // Detect W5100 only in Ethernet and EthernetLarge libraries -#if ( USE_ETHERNET || USE_ETHERNET_LARGE) +#if (USE_ETHERNET_GENERIC) isW5500 = (Ethernet.hardwareStatus() == EthernetW5500); Serial.print(F("Ethernet type is ")); Serial.println(isW5500 ? F("W5500") : F("W5100")); diff --git a/examples/AM2315_Ethernet_STM32/defines.h b/examples/AM2315_Ethernet_STM32/defines.h index 3e2ebe9..6541adc 100644 --- a/examples/AM2315_Ethernet_STM32/defines.h +++ b/examples/AM2315_Ethernet_STM32/defines.h @@ -43,11 +43,8 @@ #define USE_THIS_SS_PIN 10 // Only one if the following to be true -#define USE_BUILTIN_ETHERNET false -#define USE_ETHERNET false -#define USE_ETHERNET2 false -#define USE_ETHERNET3 false -#define USE_ETHERNET_LARGE true +#define USE_BUILTIN_ETHERNET true +#define USE_ETHERNET_GENERIC false #define USE_ETHERNET_ENC false #define USE_UIP_ETHERNET false #define USE_CUSTOM_ETHERNET false @@ -129,8 +126,15 @@ #define SHIELD_TYPE "Unknown Ethernet shield/library" #endif -#define W5100_CS 10 -#define SDCARD_CS 4 +#if USE_ETHERNET_GENERIC + // Change to true if using old Ethernet card with built-in SD + #define ETHERNET_WITH_SD_CARD false +#endif + +#if (defined(ETHERNET_WITH_SD_CARD) && ETHERNET_WITH_SD_CARD) + #define W5100_CS 10 + #define SDCARD_CS 4 +#endif #define ETHERNET_HOST_NAME "STM32-Ethernet" diff --git a/examples/AM2315_Ethernet_STM32_LAN8720/AM2315_Ethernet_STM32_LAN8720.ino b/examples/AM2315_Ethernet_STM32_LAN8720/AM2315_Ethernet_STM32_LAN8720.ino index 2ee81a5..188f761 100644 --- a/examples/AM2315_Ethernet_STM32_LAN8720/AM2315_Ethernet_STM32_LAN8720.ino +++ b/examples/AM2315_Ethernet_STM32_LAN8720/AM2315_Ethernet_STM32_LAN8720.ino @@ -116,10 +116,8 @@ void setup() Serial.begin(115200); delay(2000); - Serial.print(F("\nStart AM2315_Ethernet_STM32_LAN8720 on ")); - Serial.println(BOARD_NAME); - Serial.print(F("Ethernet Shield type : ")); - Serial.println(SHIELD_TYPE); + Serial.print(F("\nStart AM2315_Ethernet_STM32_LAN8720 on ")); Serial.println(BOARD_NAME); + Serial.print(F("Ethernet Shield type : ")); Serial.println(SHIELD_TYPE); Serial.println(ETHERNET_MANAGER_STM32_VERSION); Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION); diff --git a/examples/AM2315_Ethernet_STM32_LAN8720/defines.h b/examples/AM2315_Ethernet_STM32_LAN8720/defines.h index e66261b..727b1a5 100644 --- a/examples/AM2315_Ethernet_STM32_LAN8720/defines.h +++ b/examples/AM2315_Ethernet_STM32_LAN8720/defines.h @@ -46,10 +46,7 @@ // Only one if the following to be true #define USE_BUILTIN_ETHERNET true -#define USE_ETHERNET false -#define USE_ETHERNET2 false -#define USE_ETHERNET3 false -#define USE_ETHERNET_LARGE false +#define USE_ETHERNET_GENERIC false #define USE_ETHERNET_ENC false #define USE_UIP_ETHERNET false #define USE_CUSTOM_ETHERNET false @@ -131,9 +128,16 @@ #define SHIELD_TYPE "LAN8720 Ethernet" #endif -#define W5100_CS 10 -#define SDCARD_CS 4 +#if USE_ETHERNET_GENERIC + // Change to true if using old Ethernet card with built-in SD + #define ETHERNET_WITH_SD_CARD false +#endif + +#if (defined(ETHERNET_WITH_SD_CARD) && ETHERNET_WITH_SD_CARD) + #define W5100_CS 10 + #define SDCARD_CS 4 +#endif -#define ETHERNET_HOST_NAME "STM32-LAN8720" +#define ETHERNET_HOST_NAME "STM32-Ethernet" #endif //defines_h diff --git a/examples/DHT11_Ethernet_STM32/DHT11_Ethernet_STM32.ino b/examples/DHT11_Ethernet_STM32/DHT11_Ethernet_STM32.ino index 87e9f5f..509cef2 100644 --- a/examples/DHT11_Ethernet_STM32/DHT11_Ethernet_STM32.ino +++ b/examples/DHT11_Ethernet_STM32/DHT11_Ethernet_STM32.ino @@ -62,10 +62,10 @@ void heartBeatPrint() localEthernetIP = Ethernet.localIP(); -#if (USE_ETHERNET2 || USE_ETHERNET3) +#if (USE_ETHERNET_GENERIC) // To modify Ethernet2 library linkStatus = Ethernet.link(); - ET_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == 1) ? F("LinkON") : F("LinkOFF") ); + ETM_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == 1) ? F("LinkON") : F("LinkOFF") ); if ( ( linkStatus == 1 ) && ((uint32_t) localEthernetIP != 0) ) #else @@ -73,7 +73,7 @@ void heartBeatPrint() // The linkStatus() is not working with W5100. Just using IP != 0.0.0.0 // Better to use ping for W5100 linkStatus = (int) Ethernet.linkStatus(); - ET_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == LinkON) ? F("LinkON") : F("LinkOFF") ); + ETM_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == LinkON) ? F("LinkON") : F("LinkOFF") ); if ( ( (linkStatus == LinkON) || !isW5500 ) && ((uint32_t) localEthernetIP != 0) ) #endif @@ -81,9 +81,9 @@ void heartBeatPrint() Serial.print(F("H")); } else - Serial.print(F("F")); + Serial.print(F("F")); - if (num == 40) + if (num == 80) { Serial.println(); num = 1; @@ -116,50 +116,27 @@ void check_status() } } -#if USING_CUSTOMS_STYLE -const char NewCustomsStyle[] /*PROGMEM*/ = ""; -#endif - -void setup() +void initEthernet() { - // Debug console - Serial.begin(115200); - while (!Serial); - - Serial.print(F("\nStart DHT11_Ethernet_STM32 on ")); - Serial.println(BOARD_NAME); - Serial.print(F("Ethernet Shield type : ")); - Serial.println(SHIELD_TYPE); - Serial.println(ETHERNET_MANAGER_STM32_VERSION); - Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION); - #if ( defined(USE_BUILTIN_ETHERNET) && USE_BUILTIN_ETHERNET ) - ET_LOGWARN(F("======== USE_BUILTIN_ETHERNET ========")); + ETM_LOGWARN(F("======== USE_BUILTIN_ETHERNET ========")); #elif ( defined(USE_UIP_ETHERNET) && USE_UIP_ETHERNET ) - ET_LOGWARN(F("======== USE_UIP_ETHERNET ========")); - #elif USE_NATIVE_ETHERNET - ET_LOGWARN(F("======== USE_NATIVE_ETHERNET ========")); - #elif USE_ETHERNET - ET_LOGWARN(F("=========== USE_ETHERNET ===========")); - #elif USE_ETHERNET2 - ET_LOGWARN(F("=========== USE_ETHERNET2 ===========")); - #elif USE_ETHERNET3 - ET_LOGWARN(F("=========== USE_ETHERNET3 ===========")); - #elif USE_ETHERNET_LARGE - ET_LOGWARN(F("=========== USE_ETHERNET_LARGE ===========")); + ETM_LOGWARN(F("======== USE_UIP_ETHERNET ========")); + #elif USE_ETHERNET_GENERIC + ETM_LOGWARN(F("=========== USE_ETHERNET_GENERIC ===========")); #elif USE_ETHERNET_ENC - ET_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); + ETM_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); #else - ET_LOGWARN(F("=========================")); + ETM_LOGWARN(F("=========================")); #endif - - ET_LOGWARN(F("Default SPI pinout:")); - ET_LOGWARN1(F("MOSI:"), MOSI); - ET_LOGWARN1(F("MISO:"), MISO); - ET_LOGWARN1(F("SCK:"), SCK); - ET_LOGWARN1(F("SS:"), SS); - ET_LOGWARN(F("=========================")); + +#if !(USE_BUILTIN_ETHERNET ) + ETM_LOGWARN(F("Default SPI pinout:")); + ETM_LOGWARN1(F("MOSI:"), MOSI); + ETM_LOGWARN1(F("MISO:"), MISO); + ETM_LOGWARN1(F("SCK:"), SCK); + ETM_LOGWARN1(F("SS:"), SS); + ETM_LOGWARN(F("=========================")); // unknown board, do nothing, use default SS = 10 #ifndef USE_THIS_SS_PIN @@ -167,61 +144,72 @@ void setup() #endif #if defined(BOARD_NAME) - ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); + ETM_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); #else - ET_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN); + ETM_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN); #endif +#endif #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) - pinMode(SDCARD_CS, OUTPUT); - digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card - - #if USE_ETHERNET_WRAPPER + #if (defined(ETHERNET_WITH_SD_CARD) && ETHERNET_WITH_SD_CARD) + pinMode(SDCARD_CS, OUTPUT); + digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card + #endif - EthernetInit(); + // For other boards, to change if necessary + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - #else + Ethernet.init (USE_THIS_SS_PIN); + + #elif USE_CUSTOM_ETHERNET - // For other boards, to change if necessary - #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - - #elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - - #elif USE_CUSTOM_ETHERNET - - // You have to add initialization for your Custom Ethernet here - // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough - Ethernet.init(USE_THIS_SS_PIN); - - #endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE ) + // You have to add initialization for your Custom Ethernet here + // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough + Ethernet.init(USE_THIS_SS_PIN); - #endif //USE_ETHERNET_WRAPPER + #endif // ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) #endif +#if !(USE_BUILTIN_ETHERNET ) // Just info to know how to connect correctly - ET_LOGWARN(F("=========================")); - ET_LOGWARN(F("Currently Used SPI pinout:")); - ET_LOGWARN1(F("MOSI:"), MOSI); - ET_LOGWARN1(F("MISO:"), MISO); - ET_LOGWARN1(F("SCK:"), SCK); - ET_LOGWARN1(F("SS:"), SS); + #if defined(CUR_PIN_MISO) + ETM_LOGWARN(F("Currently Used SPI pinout:")); + ETM_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); + ETM_LOGWARN1(F("MISO:"), CUR_PIN_MISO); + ETM_LOGWARN1(F("SCK:"), CUR_PIN_SCK); + ETM_LOGWARN1(F("SS:"), CUR_PIN_SS); + #else + ETM_LOGWARN(F("Currently Used SPI pinout:")); + ETM_LOGWARN1(F("MOSI:"), MOSI); + ETM_LOGWARN1(F("MISO:"), MISO); + ETM_LOGWARN1(F("SCK:"), SCK); + ETM_LOGWARN1(F("SS:"), SS); + #endif -#if USE_ETHERNET3 - ET_LOGWARN1(F("SPI_CS:"), SPI_CS); + ETM_LOGWARN(F("=========================")); +#endif +} + +#if USING_CUSTOMS_STYLE +const char NewCustomsStyle[] /*PROGMEM*/ = ""; #endif - ET_LOGWARN(F("=========================")); - + +void setup() +{ + // Debug console + Serial.begin(115200); + while (!Serial); + + Serial.print(F("\nStart DHT11_Ethernet_STM32 on ")); Serial.println(BOARD_NAME); + Serial.print(F("Ethernet Shield type : ")); Serial.println(SHIELD_TYPE); + Serial.println(ETHERNET_MANAGER_STM32_VERSION); + Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION); + + initEthernet(); + ////////////////////////////////////////////// #if USING_CUSTOMS_STYLE @@ -242,12 +230,7 @@ void setup() localEthernetIP = Ethernet.localIP(); -#if (USE_ETHERNET2 || USE_ETHERNET3) - // To modify Ethernet2 library if ( (uint32_t) localEthernetIP != 0 ) -#else - if ( (uint32_t) localEthernetIP != 0 ) -#endif { Serial.print(F("Connected! IP address: ")); Serial.println(localEthernetIP); @@ -258,7 +241,7 @@ void setup() } // Detect W5100 only in Ethernet and EthernetLarge libraries -#if ( USE_ETHERNET || USE_ETHERNET_LARGE) +#if (USE_ETHERNET_GENERIC) isW5500 = (Ethernet.hardwareStatus() == EthernetW5500); Serial.print(F("Ethernet type is ")); Serial.println(isW5500 ? F("W5500") : F("W5100")); diff --git a/examples/DHT11_Ethernet_STM32/defines.h b/examples/DHT11_Ethernet_STM32/defines.h index 3e2ebe9..6541adc 100644 --- a/examples/DHT11_Ethernet_STM32/defines.h +++ b/examples/DHT11_Ethernet_STM32/defines.h @@ -43,11 +43,8 @@ #define USE_THIS_SS_PIN 10 // Only one if the following to be true -#define USE_BUILTIN_ETHERNET false -#define USE_ETHERNET false -#define USE_ETHERNET2 false -#define USE_ETHERNET3 false -#define USE_ETHERNET_LARGE true +#define USE_BUILTIN_ETHERNET true +#define USE_ETHERNET_GENERIC false #define USE_ETHERNET_ENC false #define USE_UIP_ETHERNET false #define USE_CUSTOM_ETHERNET false @@ -129,8 +126,15 @@ #define SHIELD_TYPE "Unknown Ethernet shield/library" #endif -#define W5100_CS 10 -#define SDCARD_CS 4 +#if USE_ETHERNET_GENERIC + // Change to true if using old Ethernet card with built-in SD + #define ETHERNET_WITH_SD_CARD false +#endif + +#if (defined(ETHERNET_WITH_SD_CARD) && ETHERNET_WITH_SD_CARD) + #define W5100_CS 10 + #define SDCARD_CS 4 +#endif #define ETHERNET_HOST_NAME "STM32-Ethernet" diff --git a/examples/DHT11_Ethernet_STM32_LAN8720/DHT11_Ethernet_STM32_LAN8720.ino b/examples/DHT11_Ethernet_STM32_LAN8720/DHT11_Ethernet_STM32_LAN8720.ino index e964640..423b2ed 100644 --- a/examples/DHT11_Ethernet_STM32_LAN8720/DHT11_Ethernet_STM32_LAN8720.ino +++ b/examples/DHT11_Ethernet_STM32_LAN8720/DHT11_Ethernet_STM32_LAN8720.ino @@ -118,10 +118,8 @@ void setup() Serial.begin(115200); delay(2000); - Serial.print(F("\nStart DHT11_Ethernet_STM32_LAN8720 on ")); - Serial.println(BOARD_NAME); - Serial.print(F("Ethernet Shield type : ")); - Serial.println(SHIELD_TYPE); + Serial.print(F("\nStart DHT11_Ethernet_STM32_LAN8720 on ")); Serial.println(BOARD_NAME); + Serial.print(F("Ethernet Shield type : ")); Serial.println(SHIELD_TYPE); Serial.println(ETHERNET_MANAGER_STM32_VERSION); Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION); diff --git a/examples/DHT11_Ethernet_STM32_LAN8720/defines.h b/examples/DHT11_Ethernet_STM32_LAN8720/defines.h index adf842f..727b1a5 100644 --- a/examples/DHT11_Ethernet_STM32_LAN8720/defines.h +++ b/examples/DHT11_Ethernet_STM32_LAN8720/defines.h @@ -46,10 +46,7 @@ // Only one if the following to be true #define USE_BUILTIN_ETHERNET true -#define USE_ETHERNET false -#define USE_ETHERNET2 false -#define USE_ETHERNET3 false -#define USE_ETHERNET_LARGE false +#define USE_ETHERNET_GENERIC false #define USE_ETHERNET_ENC false #define USE_UIP_ETHERNET false #define USE_CUSTOM_ETHERNET false @@ -131,8 +128,15 @@ #define SHIELD_TYPE "LAN8720 Ethernet" #endif -#define W5100_CS 10 -#define SDCARD_CS 4 +#if USE_ETHERNET_GENERIC + // Change to true if using old Ethernet card with built-in SD + #define ETHERNET_WITH_SD_CARD false +#endif + +#if (defined(ETHERNET_WITH_SD_CARD) && ETHERNET_WITH_SD_CARD) + #define W5100_CS 10 + #define SDCARD_CS 4 +#endif #define ETHERNET_HOST_NAME "STM32-Ethernet" diff --git a/examples/Ethernet_STM32/Ethernet_STM32.ino b/examples/Ethernet_STM32/Ethernet_STM32.ino index 144afd5..42c599d 100644 --- a/examples/Ethernet_STM32/Ethernet_STM32.ino +++ b/examples/Ethernet_STM32/Ethernet_STM32.ino @@ -28,10 +28,10 @@ void heartBeatPrint() localEthernetIP = Ethernet.localIP(); -#if (USE_ETHERNET2 || USE_ETHERNET3) +#if (USE_ETHERNET_GENERIC) // To modify Ethernet2 library linkStatus = Ethernet.link(); - ET_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == 1) ? F("LinkON") : F("LinkOFF") ); + ETM_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == 1) ? F("LinkON") : F("LinkOFF") ); if ( ( linkStatus == 1 ) && ((uint32_t) localEthernetIP != 0) ) #else @@ -39,7 +39,7 @@ void heartBeatPrint() // The linkStatus() is not working with W5100. Just using IP != 0.0.0.0 // Better to use ping for W5100 linkStatus = (int) Ethernet.linkStatus(); - ET_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == LinkON) ? F("LinkON") : F("LinkOFF") ); + ETM_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == LinkON) ? F("LinkON") : F("LinkOFF") ); if ( ( (linkStatus == LinkON) || !isW5500 ) && ((uint32_t) localEthernetIP != 0) ) #endif @@ -74,50 +74,27 @@ void check_status() } } -#if USING_CUSTOMS_STYLE -const char NewCustomsStyle[] /*PROGMEM*/ = ""; -#endif - -void setup() +void initEthernet() { - // Debug console - Serial.begin(115200); - while (!Serial); - - Serial.print(F("\nStart Ethernet_STM32 on ")); - Serial.println(BOARD_NAME); - Serial.print(F("Ethernet Shield type : ")); - Serial.println(SHIELD_TYPE); - Serial.println(ETHERNET_MANAGER_STM32_VERSION); - Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION); - #if ( defined(USE_BUILTIN_ETHERNET) && USE_BUILTIN_ETHERNET ) - ET_LOGWARN(F("======== USE_BUILTIN_ETHERNET ========")); + ETM_LOGWARN(F("======== USE_BUILTIN_ETHERNET ========")); #elif ( defined(USE_UIP_ETHERNET) && USE_UIP_ETHERNET ) - ET_LOGWARN(F("======== USE_UIP_ETHERNET ========")); - #elif USE_NATIVE_ETHERNET - ET_LOGWARN(F("======== USE_NATIVE_ETHERNET ========")); - #elif USE_ETHERNET - ET_LOGWARN(F("=========== USE_ETHERNET ===========")); - #elif USE_ETHERNET2 - ET_LOGWARN(F("=========== USE_ETHERNET2 ===========")); - #elif USE_ETHERNET3 - ET_LOGWARN(F("=========== USE_ETHERNET3 ===========")); - #elif USE_ETHERNET_LARGE - ET_LOGWARN(F("=========== USE_ETHERNET_LARGE ===========")); + ETM_LOGWARN(F("======== USE_UIP_ETHERNET ========")); + #elif USE_ETHERNET_GENERIC + ETM_LOGWARN(F("=========== USE_ETHERNET_GENERIC ===========")); #elif USE_ETHERNET_ENC - ET_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); + ETM_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); #else - ET_LOGWARN(F("=========================")); + ETM_LOGWARN(F("=========================")); #endif - - ET_LOGWARN(F("Default SPI pinout:")); - ET_LOGWARN1(F("MOSI:"), MOSI); - ET_LOGWARN1(F("MISO:"), MISO); - ET_LOGWARN1(F("SCK:"), SCK); - ET_LOGWARN1(F("SS:"), SS); - ET_LOGWARN(F("=========================")); + +#if !(USE_BUILTIN_ETHERNET ) + ETM_LOGWARN(F("Default SPI pinout:")); + ETM_LOGWARN1(F("MOSI:"), MOSI); + ETM_LOGWARN1(F("MISO:"), MISO); + ETM_LOGWARN1(F("SCK:"), SCK); + ETM_LOGWARN1(F("SS:"), SS); + ETM_LOGWARN(F("=========================")); // unknown board, do nothing, use default SS = 10 #ifndef USE_THIS_SS_PIN @@ -125,61 +102,74 @@ void setup() #endif #if defined(BOARD_NAME) - ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); + ETM_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); #else - ET_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN); + ETM_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN); #endif +#endif #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) - pinMode(SDCARD_CS, OUTPUT); - digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card - - #if USE_ETHERNET_WRAPPER + #if (defined(ETHERNET_WITH_SD_CARD) && ETHERNET_WITH_SD_CARD) + pinMode(SDCARD_CS, OUTPUT); + digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card + #endif - EthernetInit(); + // For other boards, to change if necessary + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - #else + Ethernet.init (USE_THIS_SS_PIN); + + #elif USE_CUSTOM_ETHERNET - // For other boards, to change if necessary - #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - - #elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif + // You have to add initialization for your Custom Ethernet here + // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough + Ethernet.init(USE_THIS_SS_PIN); - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - - #elif USE_CUSTOM_ETHERNET - - // You have to add initialization for your Custom Ethernet here - // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough - Ethernet.init(USE_THIS_SS_PIN); - - #endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE ) - - #endif //USE_ETHERNET_WRAPPER + #endif // ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) #endif +#if !(USE_BUILTIN_ETHERNET ) // Just info to know how to connect correctly - ET_LOGWARN(F("=========================")); - ET_LOGWARN(F("Currently Used SPI pinout:")); - ET_LOGWARN1(F("MOSI:"), MOSI); - ET_LOGWARN1(F("MISO:"), MISO); - ET_LOGWARN1(F("SCK:"), SCK); - ET_LOGWARN1(F("SS:"), SS); + #if defined(CUR_PIN_MISO) + ETM_LOGWARN(F("Currently Used SPI pinout:")); + ETM_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); + ETM_LOGWARN1(F("MISO:"), CUR_PIN_MISO); + ETM_LOGWARN1(F("SCK:"), CUR_PIN_SCK); + ETM_LOGWARN1(F("SS:"), CUR_PIN_SS); + #else + ETM_LOGWARN(F("Currently Used SPI pinout:")); + ETM_LOGWARN1(F("MOSI:"), MOSI); + ETM_LOGWARN1(F("MISO:"), MISO); + ETM_LOGWARN1(F("SCK:"), SCK); + ETM_LOGWARN1(F("SS:"), SS); + #endif -#if USE_ETHERNET3 - ET_LOGWARN1(F("SPI_CS:"), SPI_CS); + ETM_LOGWARN(F("=========================")); #endif - ET_LOGWARN(F("=========================")); - +} + +#if USING_CUSTOMS_STYLE +const char NewCustomsStyle[] /*PROGMEM*/ = ""; +#endif + +void setup() +{ + // Debug console + Serial.begin(115200); + while (!Serial); + + Serial.print(F("\nStart Ethernet_STM32 on ")); + Serial.println(BOARD_NAME); + Serial.print(F("Ethernet Shield type : ")); + Serial.println(SHIELD_TYPE); + Serial.println(ETHERNET_MANAGER_STM32_VERSION); + Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION); + + initEthernet(); + ////////////////////////////////////////////// #if USING_CUSTOMS_STYLE diff --git a/examples/Ethernet_STM32/defines.h b/examples/Ethernet_STM32/defines.h index 439555f..6541adc 100644 --- a/examples/Ethernet_STM32/defines.h +++ b/examples/Ethernet_STM32/defines.h @@ -44,10 +44,7 @@ // Only one if the following to be true #define USE_BUILTIN_ETHERNET true -#define USE_ETHERNET false -#define USE_ETHERNET2 false -#define USE_ETHERNET3 false -#define USE_ETHERNET_LARGE false +#define USE_ETHERNET_GENERIC false #define USE_ETHERNET_ENC false #define USE_UIP_ETHERNET false #define USE_CUSTOM_ETHERNET false @@ -129,8 +126,15 @@ #define SHIELD_TYPE "Unknown Ethernet shield/library" #endif -#define W5100_CS 10 -#define SDCARD_CS 4 +#if USE_ETHERNET_GENERIC + // Change to true if using old Ethernet card with built-in SD + #define ETHERNET_WITH_SD_CARD false +#endif + +#if (defined(ETHERNET_WITH_SD_CARD) && ETHERNET_WITH_SD_CARD) + #define W5100_CS 10 + #define SDCARD_CS 4 +#endif #define ETHERNET_HOST_NAME "STM32-Ethernet" diff --git a/examples/Ethernet_STM32_LAN8720/Ethernet_STM32_LAN8720.ino b/examples/Ethernet_STM32_LAN8720/Ethernet_STM32_LAN8720.ino index 37d7772..2b456f1 100644 --- a/examples/Ethernet_STM32_LAN8720/Ethernet_STM32_LAN8720.ino +++ b/examples/Ethernet_STM32_LAN8720/Ethernet_STM32_LAN8720.ino @@ -27,7 +27,7 @@ void heartBeatPrint() // The linkStatus() is not working with W5100. Just using IP != 0.0.0.0 // Better to use ping for W5100 linkStatus = (int) Ethernet.linkStatus(); - ET_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == LinkON) ? F("LinkON") : F("LinkOFF") ); + ETM_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == LinkON) ? F("LinkON") : F("LinkOFF") ); if ( (uint32_t) localEthernetIP != 0 ) { @@ -72,10 +72,8 @@ void setup() Serial.begin(115200); delay(2000); - Serial.print(F("\nStart Ethernet_STM32_LAN8720 on ")); - Serial.println(BOARD_NAME); - Serial.print(F("Ethernet Shield type : ")); - Serial.println(SHIELD_TYPE); + Serial.print(F("\nStart Ethernet_STM32_LAN8720 on ")); Serial.println(BOARD_NAME); + Serial.print(F("Ethernet Shield type : ")); Serial.println(SHIELD_TYPE); Serial.println(ETHERNET_MANAGER_STM32_VERSION); Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION); diff --git a/examples/Ethernet_STM32_LAN8720/defines.h b/examples/Ethernet_STM32_LAN8720/defines.h index c32ab86..727b1a5 100644 --- a/examples/Ethernet_STM32_LAN8720/defines.h +++ b/examples/Ethernet_STM32_LAN8720/defines.h @@ -31,8 +31,8 @@ #define ETHERNET_MANAGER_STM32_DEBUG_PORT Serial // Debug Level from 0 to 4 -#define _ETHERNET_WEBSERVER_LOGLEVEL_ 4 -#define _ETHERNET_MANAGER_STM32_LOGLEVEL_ 4 +#define _ETHERNET_WEBSERVER_LOGLEVEL_ 0 +#define _ETHERNET_MANAGER_STM32_LOGLEVEL_ 2 #define DRD_GENERIC_DEBUG true @@ -46,10 +46,7 @@ // Only one if the following to be true #define USE_BUILTIN_ETHERNET true -#define USE_ETHERNET false -#define USE_ETHERNET2 false -#define USE_ETHERNET3 false -#define USE_ETHERNET_LARGE false +#define USE_ETHERNET_GENERIC false #define USE_ETHERNET_ENC false #define USE_UIP_ETHERNET false #define USE_CUSTOM_ETHERNET false @@ -131,8 +128,15 @@ #define SHIELD_TYPE "LAN8720 Ethernet" #endif -#define W5100_CS 10 -#define SDCARD_CS 4 +#if USE_ETHERNET_GENERIC + // Change to true if using old Ethernet card with built-in SD + #define ETHERNET_WITH_SD_CARD false +#endif + +#if (defined(ETHERNET_WITH_SD_CARD) && ETHERNET_WITH_SD_CARD) + #define W5100_CS 10 + #define SDCARD_CS 4 +#endif #define ETHERNET_HOST_NAME "STM32-Ethernet" diff --git a/examples/MQTT_ThingStream_Ethernet_STM32/MQTT_ThingStream_Ethernet_STM32.ino b/examples/MQTT_ThingStream_Ethernet_STM32/MQTT_ThingStream_Ethernet_STM32.ino index 4ff6dd7..b068983 100644 --- a/examples/MQTT_ThingStream_Ethernet_STM32/MQTT_ThingStream_Ethernet_STM32.ino +++ b/examples/MQTT_ThingStream_Ethernet_STM32/MQTT_ThingStream_Ethernet_STM32.ino @@ -129,10 +129,10 @@ void heartBeatPrint() localEthernetIP = Ethernet.localIP(); -#if (USE_ETHERNET2 || USE_ETHERNET3) +#if (USE_ETHERNET_GENERIC) // To modify Ethernet2 library linkStatus = Ethernet.link(); - ET_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == 1) ? F("LinkON") : F("LinkOFF") ); + ETM_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == 1) ? F("LinkON") : F("LinkOFF") ); if ( ( linkStatus == 1 ) && ((uint32_t) localEthernetIP != 0) ) #else @@ -140,7 +140,7 @@ void heartBeatPrint() // The linkStatus() is not working with W5100. Just using IP != 0.0.0.0 // Better to use ping for W5100 linkStatus = (int) Ethernet.linkStatus(); - ET_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == LinkON) ? F("LinkON") : F("LinkOFF") ); + ETM_LOGINFO3(F("localEthernetIP = "), localEthernetIP, F(", linkStatus = "), (linkStatus == LinkON) ? F("LinkON") : F("LinkOFF") ); if ( ( (linkStatus == LinkON) || !isW5500 ) && ((uint32_t) localEthernetIP != 0) ) #endif @@ -175,50 +175,27 @@ void check_status() } } -#if USING_CUSTOMS_STYLE -const char NewCustomsStyle[] /*PROGMEM*/ = ""; -#endif - -void setup() +void initEthernet() { - // Debug console - Serial.begin(115200); - while (!Serial); - - Serial.print(F("\nStart MQTT_ThingStream_Ethernet_STM32 on ")); - Serial.println(BOARD_NAME); - Serial.print(F("Ethernet Shield type : ")); - Serial.println(SHIELD_TYPE); - Serial.println(ETHERNET_MANAGER_STM32_VERSION); - Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION); - #if ( defined(USE_BUILTIN_ETHERNET) && USE_BUILTIN_ETHERNET ) - ET_LOGWARN(F("======== USE_BUILTIN_ETHERNET ========")); + ETM_LOGWARN(F("======== USE_BUILTIN_ETHERNET ========")); #elif ( defined(USE_UIP_ETHERNET) && USE_UIP_ETHERNET ) - ET_LOGWARN(F("======== USE_UIP_ETHERNET ========")); - #elif USE_NATIVE_ETHERNET - ET_LOGWARN(F("======== USE_NATIVE_ETHERNET ========")); - #elif USE_ETHERNET - ET_LOGWARN(F("=========== USE_ETHERNET ===========")); - #elif USE_ETHERNET2 - ET_LOGWARN(F("=========== USE_ETHERNET2 ===========")); - #elif USE_ETHERNET3 - ET_LOGWARN(F("=========== USE_ETHERNET3 ===========")); - #elif USE_ETHERNET_LARGE - ET_LOGWARN(F("=========== USE_ETHERNET_LARGE ===========")); + ETM_LOGWARN(F("======== USE_UIP_ETHERNET ========")); + #elif USE_ETHERNET_GENERIC + ETM_LOGWARN(F("=========== USE_ETHERNET_GENERIC ===========")); #elif USE_ETHERNET_ENC - ET_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); + ETM_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); #else - ET_LOGWARN(F("=========================")); + ETM_LOGWARN(F("=========================")); #endif - - ET_LOGWARN(F("Default SPI pinout:")); - ET_LOGWARN1(F("MOSI:"), MOSI); - ET_LOGWARN1(F("MISO:"), MISO); - ET_LOGWARN1(F("SCK:"), SCK); - ET_LOGWARN1(F("SS:"), SS); - ET_LOGWARN(F("=========================")); + +#if !(USE_BUILTIN_ETHERNET ) + ETM_LOGWARN(F("Default SPI pinout:")); + ETM_LOGWARN1(F("MOSI:"), MOSI); + ETM_LOGWARN1(F("MISO:"), MISO); + ETM_LOGWARN1(F("SCK:"), SCK); + ETM_LOGWARN1(F("SS:"), SS); + ETM_LOGWARN(F("=========================")); // unknown board, do nothing, use default SS = 10 #ifndef USE_THIS_SS_PIN @@ -226,61 +203,72 @@ void setup() #endif #if defined(BOARD_NAME) - ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); + ETM_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); #else - ET_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN); + ETM_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN); #endif +#endif #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) - pinMode(SDCARD_CS, OUTPUT); - digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card - - #if USE_ETHERNET_WRAPPER + #if (defined(ETHERNET_WITH_SD_CARD) && ETHERNET_WITH_SD_CARD) + pinMode(SDCARD_CS, OUTPUT); + digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card + #endif - EthernetInit(); + // For other boards, to change if necessary + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - #else + Ethernet.init (USE_THIS_SS_PIN); + + #elif USE_CUSTOM_ETHERNET - // For other boards, to change if necessary - #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - - #elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - - #elif USE_CUSTOM_ETHERNET - - // You have to add initialization for your Custom Ethernet here - // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough - Ethernet.init(USE_THIS_SS_PIN); - - #endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE ) + // You have to add initialization for your Custom Ethernet here + // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough + Ethernet.init(USE_THIS_SS_PIN); - #endif //USE_ETHERNET_WRAPPER + #endif // ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) #endif +#if !(USE_BUILTIN_ETHERNET ) // Just info to know how to connect correctly - ET_LOGWARN(F("=========================")); - ET_LOGWARN(F("Currently Used SPI pinout:")); - ET_LOGWARN1(F("MOSI:"), MOSI); - ET_LOGWARN1(F("MISO:"), MISO); - ET_LOGWARN1(F("SCK:"), SCK); - ET_LOGWARN1(F("SS:"), SS); + #if defined(CUR_PIN_MISO) + ETM_LOGWARN(F("Currently Used SPI pinout:")); + ETM_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); + ETM_LOGWARN1(F("MISO:"), CUR_PIN_MISO); + ETM_LOGWARN1(F("SCK:"), CUR_PIN_SCK); + ETM_LOGWARN1(F("SS:"), CUR_PIN_SS); + #else + ETM_LOGWARN(F("Currently Used SPI pinout:")); + ETM_LOGWARN1(F("MOSI:"), MOSI); + ETM_LOGWARN1(F("MISO:"), MISO); + ETM_LOGWARN1(F("SCK:"), SCK); + ETM_LOGWARN1(F("SS:"), SS); + #endif -#if USE_ETHERNET3 - ET_LOGWARN1(F("SPI_CS:"), SPI_CS); + ETM_LOGWARN(F("=========================")); +#endif +} + +#if USING_CUSTOMS_STYLE +const char NewCustomsStyle[] /*PROGMEM*/ = ""; #endif - ET_LOGWARN(F("=========================")); - + +void setup() +{ + // Debug console + Serial.begin(115200); + while (!Serial); + + Serial.print(F("\nStart MQTT_ThingStream_Ethernet_STM32 on ")); Serial.println(BOARD_NAME); + Serial.print(F("Ethernet Shield type : ")); Serial.println(SHIELD_TYPE); + Serial.println(ETHERNET_MANAGER_STM32_VERSION); + Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION); + + initEthernet(); + ////////////////////////////////////////////// #if USING_CUSTOMS_STYLE @@ -301,12 +289,7 @@ void setup() localEthernetIP = Ethernet.localIP(); -#if (USE_ETHERNET2 || USE_ETHERNET3) - // To modify Ethernet2 library if ( (uint32_t) localEthernetIP != 0 ) -#else - if ( (uint32_t) localEthernetIP != 0 ) -#endif { Serial.print(F("Connected! IP address: ")); Serial.println(localEthernetIP); @@ -317,7 +300,7 @@ void setup() } // Detect W5100 only in Ethernet and EthernetLarge libraries -#if ( USE_ETHERNET || USE_ETHERNET_LARGE) +#if (USE_ETHERNET_GENERIC) isW5500 = (Ethernet.hardwareStatus() == EthernetW5500); Serial.print(F("Ethernet type is ")); Serial.println(isW5500 ? F("W5500") : F("W5100")); diff --git a/examples/MQTT_ThingStream_Ethernet_STM32/defines.h b/examples/MQTT_ThingStream_Ethernet_STM32/defines.h index 0535018..6541adc 100644 --- a/examples/MQTT_ThingStream_Ethernet_STM32/defines.h +++ b/examples/MQTT_ThingStream_Ethernet_STM32/defines.h @@ -43,11 +43,8 @@ #define USE_THIS_SS_PIN 10 // Only one if the following to be true -#define USE_BUILTIN_ETHERNET false -#define USE_ETHERNET false -#define USE_ETHERNET2 false -#define USE_ETHERNET3 false -#define USE_ETHERNET_LARGE true +#define USE_BUILTIN_ETHERNET true +#define USE_ETHERNET_GENERIC false #define USE_ETHERNET_ENC false #define USE_UIP_ETHERNET false #define USE_CUSTOM_ETHERNET false @@ -126,11 +123,18 @@ #include #ifndef SHIELD_TYPE -#define SHIELD_TYPE "Unknown Ethernet shield/library" + #define SHIELD_TYPE "Unknown Ethernet shield/library" #endif -#define W5100_CS 10 -#define SDCARD_CS 4 +#if USE_ETHERNET_GENERIC + // Change to true if using old Ethernet card with built-in SD + #define ETHERNET_WITH_SD_CARD false +#endif + +#if (defined(ETHERNET_WITH_SD_CARD) && ETHERNET_WITH_SD_CARD) + #define W5100_CS 10 + #define SDCARD_CS 4 +#endif #define ETHERNET_HOST_NAME "STM32-Ethernet" diff --git a/examples/MQTT_ThingStream_Ethernet_STM32_LAN8720/MQTT_ThingStream_Ethernet_STM32_LAN8720.ino b/examples/MQTT_ThingStream_Ethernet_STM32_LAN8720/MQTT_ThingStream_Ethernet_STM32_LAN8720.ino index 74a3988..b5156e4 100644 --- a/examples/MQTT_ThingStream_Ethernet_STM32_LAN8720/MQTT_ThingStream_Ethernet_STM32_LAN8720.ino +++ b/examples/MQTT_ThingStream_Ethernet_STM32_LAN8720/MQTT_ThingStream_Ethernet_STM32_LAN8720.ino @@ -173,10 +173,8 @@ void setup() Serial.begin(115200); delay(2000); - Serial.print(F("\nStart MQTT_ThingStream_Ethernet_STM32_LAN8720 on ")); - Serial.println(BOARD_NAME); - Serial.print(F("Ethernet Shield type : ")); - Serial.println(SHIELD_TYPE); + Serial.print(F("\nStart MQTT_ThingStream_Ethernet_STM32_LAN8720 on ")); Serial.println(BOARD_NAME); + Serial.print(F("Ethernet Shield type : ")); Serial.println(SHIELD_TYPE); Serial.println(ETHERNET_MANAGER_STM32_VERSION); Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION); diff --git a/examples/MQTT_ThingStream_Ethernet_STM32_LAN8720/defines.h b/examples/MQTT_ThingStream_Ethernet_STM32_LAN8720/defines.h index adf842f..727b1a5 100644 --- a/examples/MQTT_ThingStream_Ethernet_STM32_LAN8720/defines.h +++ b/examples/MQTT_ThingStream_Ethernet_STM32_LAN8720/defines.h @@ -46,10 +46,7 @@ // Only one if the following to be true #define USE_BUILTIN_ETHERNET true -#define USE_ETHERNET false -#define USE_ETHERNET2 false -#define USE_ETHERNET3 false -#define USE_ETHERNET_LARGE false +#define USE_ETHERNET_GENERIC false #define USE_ETHERNET_ENC false #define USE_UIP_ETHERNET false #define USE_CUSTOM_ETHERNET false @@ -131,8 +128,15 @@ #define SHIELD_TYPE "LAN8720 Ethernet" #endif -#define W5100_CS 10 -#define SDCARD_CS 4 +#if USE_ETHERNET_GENERIC + // Change to true if using old Ethernet card with built-in SD + #define ETHERNET_WITH_SD_CARD false +#endif + +#if (defined(ETHERNET_WITH_SD_CARD) && ETHERNET_WITH_SD_CARD) + #define W5100_CS 10 + #define SDCARD_CS 4 +#endif #define ETHERNET_HOST_NAME "STM32-Ethernet" diff --git a/examples/multiFileProject/multiFileProject.cpp b/examples/multiFileProject/multiFileProject.cpp new file mode 100644 index 0000000..b166f2c --- /dev/null +++ b/examples/multiFileProject/multiFileProject.cpp @@ -0,0 +1,14 @@ +/**************************************************************************************************************************** + multiFileProject.cpp + For W5x00, ENC28J60 and built-in LAN8742A Ethernet shields. + + Ethernet_Manager is a library for STM32F/L/H/G/WB/MP1 with Ethernet W5x00, ENC28J60 or built-in LAN8742A shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + + Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager_STM32 + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#include "multiFileProject.h" diff --git a/examples/multiFileProject/multiFileProject.h b/examples/multiFileProject/multiFileProject.h new file mode 100644 index 0000000..2243d94 --- /dev/null +++ b/examples/multiFileProject/multiFileProject.h @@ -0,0 +1,24 @@ +/**************************************************************************************************************************** + multiFileProject.h + For W5x00, ENC28J60 and built-in LAN8742A Ethernet shields. + + Ethernet_Manager is a library for STM32F/L/H/G/WB/MP1 with Ethernet W5x00, ENC28J60 or built-in LAN8742A shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + + Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager_STM32 + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#pragma once + +// Only one if the following to be true +#define USE_BUILTIN_ETHERNET true +#define USE_ETHERNET_GENERIC false +#define USE_ETHERNET_ENC false +#define USE_UIP_ETHERNET false +#define USE_CUSTOM_ETHERNET false + +// Can be included as many times as necessary, without `Multiple Definitions` Linker Error +#include // https://github.com/khoih-prog/Ethernet_Manager_STM32 diff --git a/examples/multiFileProject/multiFileProject.ino b/examples/multiFileProject/multiFileProject.ino new file mode 100644 index 0000000..2824701 --- /dev/null +++ b/examples/multiFileProject/multiFileProject.ino @@ -0,0 +1,46 @@ +/**************************************************************************************************************************** + multiFileProject.ino + For W5x00, ENC28J60 and built-in LAN8742A Ethernet shields. + + Ethernet_Manager is a library for STM32F/L/H/G/WB/MP1 with Ethernet W5x00, ENC28J60 or built-in LAN8742A shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + + Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager_STM32 + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#define ETHERNET_MANAGER_STM32_VERSION_MIN_TARGET "Ethernet_Manager_STM32 v1.3.2" +#define ETHERNET_MANAGER_STM32_VERSION_MIN 1003002 + +#include "multiFileProject.h" + +// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error +#include // https://github.com/khoih-prog/Ethernet_Manager_STM32 + +void setup() +{ + Serial.begin(115200); + while (!Serial); + + delay(500); + + Serial.println("\nStart multiFileProject"); + Serial.println(ETHERNET_MANAGER_STM32_VERSION); + +#if defined(ETHERNET_MANAGER_STM32_VERSION_MIN) + if (ETHERNET_MANAGER_STM32_VERSION_INT < ETHERNET_MANAGER_STM32_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(ETHERNET_MANAGER_STM32_VERSION_MIN_TARGET); + } +#endif + + Serial.print("You're OK now"); +} + +void loop() +{ + // put your main code here, to run repeatedly: +}