stm32duino / STM32Ethernet

Arduino library to support Ethernet for STM32 based board
156 stars 43 forks source link

Ethernet.begin() does not return under certian circumstances #4

Closed pulli7 closed 7 years ago

pulli7 commented 7 years ago

In the past, with the Arduino-Ethernet-Shield, I used the following code to wait for ethernet connection to get available, so that I can have at least some limited functionality when ethernet is not available at this time, and automatically jump to full functionality as soon as link gets available.

void setup()
{
  if (Ethernet.begin(mac) == 0)
  {
    FallBackMode();
  } 
}
void FallBackMode()
{
  int Timestamp = millis();
  while(1)
  {
     if ( millis() - Timestamp > 300000)  //try reconnect every 5min
     {
       if (Ethernet.begin(mac, 30000) != 0)  //Problem here
       {                                   
         break;  //successfully connected
       }
       Timestamp = millis();
    }
    //call  "offline application"  here, which serves all functionality that does not need Ethernet
  }//ENDwhile
}

With the Nucleo 429ZI this does not work. As long as the cable is unplugged everthing is fine, but as soon as it is plugged in and ethernet gets available, the program gets locked inside the Ethernet.begin() function and never returns.

Am I misusing the function and it worked just coincidentally with the standard ethernet-shield, or is this a bug? If this usage of the begin() function is not intended, is there another way to achieve that the board tries reconnecting itself?

ghost commented 7 years ago

Issue reproduced. This is under investigation.

fpistm commented 7 years ago

Hi all, maybe the PR #5 fix this issue as the Ethernet scheduler is called by timer every 1ms?

pulli7 commented 7 years ago

Gave it a quick try:

Looks like it changes the behavior in the way, that now calling Ethernet.begin() a second time, after the first try failed, always locks the program inside the function, no matter if ethernet is still unavailable or not.

ghost commented 7 years ago

@pulli7 Could you try the PR #5? It fixes your issue when several call of begin().

pulli7 commented 7 years ago

Confirmed, issue is fixed. Thank you again @fprwi6labs !

ghost commented 7 years ago

You're welcome @pulli7 . @fpistm you can close all those issues.

fpistm commented 7 years ago

Thanks guy.

bertoruiz commented 6 years ago

I'm having the same problem with my Arduino UNO and ethernet shield. How exactly do I fix the problem when it hangs?

Examples of hanging:

It works fine when:

fpistm commented 6 years ago

This library is designed for STM32 boards with native Ethernet. You should submit your issue on https://github.com/adafruit/Ethernet2 or https://github.com/arduino/Arduino/tree/master/libraries/Ethernet depending of your shield.