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 all commits
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
8 changes: 4 additions & 4 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,8 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
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);
#endif
bool const use_ethernet = _connection->getInterface() == NetworkAdapter::ETHERNET ? true : false;
watchdog_enable_network_feed(use_ethernet);
}
#endif

Expand Down Expand Up @@ -830,7 +829,8 @@ void ArduinoIoTCloudTCP::onOTARequest()
#endif

#ifdef BOARD_STM32H7
_ota_error = portenta_h7_onOTARequest(_ota_url.c_str());
bool const use_ethernet = _connection->getInterface() == NetworkAdapter::ETHERNET ? true : false;
_ota_error = portenta_h7_onOTARequest(_ota_url.c_str(), use_ethernet);
#endif
}
#endif
Expand Down
11 changes: 9 additions & 2 deletions src/utility/ota/OTA-portenta-h7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@

#include <Arduino_DebugUtils.h>
#include <Arduino_Portenta_OTA.h>
#include <Arduino_ConnectionHandler.h>

#include "../watchdog/Watchdog.h"

/******************************************************************************
* FUNCTION DEFINITION
******************************************************************************/

int portenta_h7_onOTARequest(char const * ota_url)
int portenta_h7_onOTARequest(char const * ota_url, const bool use_ethernet)
{
watchdog_reset();

Expand Down Expand Up @@ -63,7 +64,13 @@ int portenta_h7_onOTARequest(char const * ota_url)
watchdog_reset();

/* Download the OTA file from the web storage location. */
int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download(ota_url, true /* is_https */);
MbedSocketClass * download_socket = static_cast<MbedSocketClass*>(&WiFi);
#if defined (BOARD_HAS_ETHERNET)
if(use_ethernet) {
download_socket = static_cast<MbedSocketClass*>(&Ethernet);
}
#endif
int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download(ota_url, true /* is_https */, download_socket);
DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::download(%s) returns %d", ota_url, ota_portenta_qspi_download_ret_code);

watchdog_reset();
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ota/OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int rp2040_connect_onOTARequest(char const * ota_url);
#endif

#ifdef BOARD_STM32H7
int portenta_h7_onOTARequest(char const * ota_url);
int portenta_h7_onOTARequest(char const * ota_url, const bool use_ethernet);
#endif

#endif /* ARDUINO_OTA_LOGIC_H_ */
26 changes: 26 additions & 0 deletions src/utility/watchdog/Watchdog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
# define NANO_RP2040_WATCHDOG_MAX_TIMEOUT_ms (8389)
#endif /* ARDUINO_ARCH_MBED */

#include <Arduino_ConnectionHandler.h>

/******************************************************************************
* GLOBAL VARIABLES
******************************************************************************/
Expand Down Expand Up @@ -114,6 +116,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 defined(BOARD_HAS_ETHERNET)
if(use_ethernet) {
Ethernet.setFeedWatchdogFunc(watchdog_reset);
} else
#endif
WiFi.setFeedWatchdogFunc(watchdog_reset);

}
#endif

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

void watchdog_enable_network_feed(const bool use_ethernet)
{
#ifdef WIFI_HAS_FEED_WATCHDOG_FUNC
WiFi.setFeedWatchdogFunc(watchdog_reset);
#endif

#ifdef ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC
mbed_watchdog_enable_network_feed(use_ethernet);
#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(const bool use_ethernet);
#endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */

#ifdef ARDUINO_ARCH_MBED
Expand Down