Skip to content

Add ethernet interface support (OTA and Watchdog) for Portenta H7 #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Watchdog: Enable feed function for Ethernet
  The implementation is done as for WiFi so we can reuse the same define ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC

  Move watchdog network feed configuration into Watchdog module
  • Loading branch information
pennam committed Nov 7, 2022
commit e1d9da0e5f2e12d332ec330570c97b007dabd777
3 changes: 2 additions & 1 deletion src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
if (enable_watchdog) {
watchdog_enable();
#if defined (WIFI_HAS_FEED_WATCHDOG_FUNC) || defined (ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC)
WiFi.setFeedWatchdogFunc(watchdog_reset);
bool const use_ethernet = _connection->getInterface() == NetworkAdapter::ETHERNET ? true : false;
watchdog_enable_network_feed(use_ethernet);
#endif
}
#endif
Expand Down
34 changes: 34 additions & 0 deletions src/utility/watchdog/Watchdog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@

#ifdef ARDUINO_ARCH_SAMD
# include <Adafruit_SleepyDog.h>
# include <WiFi.h>
# define SAMD_WATCHDOG_MAX_TIME_ms (16 * 1000)
#endif /* ARDUINO_ARCH_SAMD */

#ifdef ARDUINO_ARCH_MBED
# include <watchdog_api.h>
# include <WiFi.h>
# include <Ethernet.h>
# define PORTENTA_H7_WATCHDOG_MAX_TIMEOUT_ms (32760)
# define NANO_RP2040_WATCHDOG_MAX_TIMEOUT_ms (8389)
#endif /* ARDUINO_ARCH_MBED */
Expand Down Expand Up @@ -63,6 +66,13 @@ static void samd_watchdog_reset()
}
}

#if defined (WIFI_HAS_FEED_WATCHDOG_FUNC)
static void samd_watchdog_enable_network_feed()
{
WiFi.setFeedWatchdogFunc(watchdog_reset);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function works for NINA? Not to say that it does not, I just never saw it before 😉

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we added this function with this PR arduino-libraries/WiFiNINA#186 one year ago

}
#endif

/* This function is called within the WiFiNINA library when invoking
* the method 'connectBearSSL' in order to prevent a premature bite
* of the watchdog (max timeout on SAMD is 16 s). wifi_nina_feed...
Expand Down Expand Up @@ -114,6 +124,19 @@ static void mbed_watchdog_reset()
}
}

#if defined (ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC)
static void mbed_watchdog_enable_network_feed(const bool use_ethernet)
{
if(use_ethernet) {
#if defined(ARDUINO_PORTENTA_H7_M7)
Ethernet.setFeedWatchdogFunc(watchdog_reset);
#endif
} else {
WiFi.setFeedWatchdogFunc(watchdog_reset);
}
}
#endif

void mbed_watchdog_trigger_reset()
{
watchdog_config_t cfg;
Expand Down Expand Up @@ -154,4 +177,15 @@ void watchdog_reset()
mbed_watchdog_reset();
#endif
}

#if defined (WIFI_HAS_FEED_WATCHDOG_FUNC) || defined (ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC)
void watchdog_enable_network_feed(const bool use_ethernet)
{
#ifdef ARDUINO_ARCH_SAMD
samd_watchdog_enable_network_feed();
#else
mbed_watchdog_enable_network_feed(use_ethernet);
#endif
}
#endif
#endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */
1 change: 1 addition & 0 deletions src/utility/watchdog/Watchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
void watchdog_enable();
void watchdog_reset();
void watchdog_enable_network_feed(bool use_ethernet);
#endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */

#ifdef ARDUINO_ARCH_MBED
Expand Down