Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
v1.3.2 to use Ethernet_Generic library
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
khoih-prog authored Apr 10, 2022
1 parent 61683a4 commit 3495515
Show file tree
Hide file tree
Showing 19 changed files with 468 additions and 421 deletions.
161 changes: 72 additions & 89 deletions examples/AM2315_Ethernet_STM32/AM2315_Ethernet_STM32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,26 @@ 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

// 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
{
Serial.print(F("H"));
}
else
Serial.print(F("F"));
Serial.print(F("F"));

if (num == 80)
{
Expand Down Expand Up @@ -118,112 +118,100 @@ void check_status()
}
}

#if USING_CUSTOMS_STYLE
const char NewCustomsStyle[] /*PROGMEM*/ = "<style>div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}\
button{background-color:blue;color:white;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}</style>";
#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
#define USE_THIS_SS_PIN 10 // For other boards
#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*/ = "<style>div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}\
button{background-color:blue;color:white;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}</style>";
#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
Expand All @@ -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);
Expand All @@ -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"));
Expand Down
18 changes: 11 additions & 7 deletions examples/AM2315_Ethernet_STM32/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
18 changes: 11 additions & 7 deletions examples/AM2315_Ethernet_STM32_LAN8720/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Loading

0 comments on commit 3495515

Please sign in to comment.