diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index f33f09c5e..f34da15af 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -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 @@ -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 diff --git a/src/utility/ota/OTA-portenta-h7.cpp b/src/utility/ota/OTA-portenta-h7.cpp index 4b0c635da..784f71969 100644 --- a/src/utility/ota/OTA-portenta-h7.cpp +++ b/src/utility/ota/OTA-portenta-h7.cpp @@ -27,6 +27,7 @@ #include #include +#include #include "../watchdog/Watchdog.h" @@ -34,7 +35,7 @@ * FUNCTION DEFINITION ******************************************************************************/ -int portenta_h7_onOTARequest(char const * ota_url) +int portenta_h7_onOTARequest(char const * ota_url, const bool use_ethernet) { watchdog_reset(); @@ -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(&WiFi); +#if defined (BOARD_HAS_ETHERNET) + if(use_ethernet) { + download_socket = static_cast(&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(); diff --git a/src/utility/ota/OTA.h b/src/utility/ota/OTA.h index ce47a3ad2..c1d3f79a0 100644 --- a/src/utility/ota/OTA.h +++ b/src/utility/ota/OTA.h @@ -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_ */ diff --git a/src/utility/watchdog/Watchdog.cpp b/src/utility/watchdog/Watchdog.cpp index d639d30a7..a45f02d4e 100644 --- a/src/utility/watchdog/Watchdog.cpp +++ b/src/utility/watchdog/Watchdog.cpp @@ -38,6 +38,8 @@ # define NANO_RP2040_WATCHDOG_MAX_TIMEOUT_ms (8389) #endif /* ARDUINO_ARCH_MBED */ +#include + /****************************************************************************** * GLOBAL VARIABLES ******************************************************************************/ @@ -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; @@ -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) */ diff --git a/src/utility/watchdog/Watchdog.h b/src/utility/watchdog/Watchdog.h index 879317684..dbaf2abd6 100644 --- a/src/utility/watchdog/Watchdog.h +++ b/src/utility/watchdog/Watchdog.h @@ -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