Skip to content

Commit 5393437

Browse files
authored
Merge pull request #328 from pennam/portenta-eth
Add ethernet interface support (OTA and Watchdog) for Portenta H7
2 parents 5823642 + fdaac0f commit 5393437

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

Diff for: src/ArduinoIoTCloudTCP.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,8 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
307307
#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
308308
if (enable_watchdog) {
309309
watchdog_enable();
310-
#if defined (WIFI_HAS_FEED_WATCHDOG_FUNC) || defined (ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC)
311-
WiFi.setFeedWatchdogFunc(watchdog_reset);
312-
#endif
310+
bool const use_ethernet = _connection->getInterface() == NetworkAdapter::ETHERNET ? true : false;
311+
watchdog_enable_network_feed(use_ethernet);
313312
}
314313
#endif
315314

@@ -830,7 +829,8 @@ void ArduinoIoTCloudTCP::onOTARequest()
830829
#endif
831830

832831
#ifdef BOARD_STM32H7
833-
_ota_error = portenta_h7_onOTARequest(_ota_url.c_str());
832+
bool const use_ethernet = _connection->getInterface() == NetworkAdapter::ETHERNET ? true : false;
833+
_ota_error = portenta_h7_onOTARequest(_ota_url.c_str(), use_ethernet);
834834
#endif
835835
}
836836
#endif

Diff for: src/utility/ota/OTA-portenta-h7.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727

2828
#include <Arduino_DebugUtils.h>
2929
#include <Arduino_Portenta_OTA.h>
30+
#include <Arduino_ConnectionHandler.h>
3031

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

3334
/******************************************************************************
3435
* FUNCTION DEFINITION
3536
******************************************************************************/
3637

37-
int portenta_h7_onOTARequest(char const * ota_url)
38+
int portenta_h7_onOTARequest(char const * ota_url, const bool use_ethernet)
3839
{
3940
watchdog_reset();
4041

@@ -63,7 +64,13 @@ int portenta_h7_onOTARequest(char const * ota_url)
6364
watchdog_reset();
6465

6566
/* Download the OTA file from the web storage location. */
66-
int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download(ota_url, true /* is_https */);
67+
MbedSocketClass * download_socket = static_cast<MbedSocketClass*>(&WiFi);
68+
#if defined (BOARD_HAS_ETHERNET)
69+
if(use_ethernet) {
70+
download_socket = static_cast<MbedSocketClass*>(&Ethernet);
71+
}
72+
#endif
73+
int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download(ota_url, true /* is_https */, download_socket);
6774
DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::download(%s) returns %d", ota_url, ota_portenta_qspi_download_ret_code);
6875

6976
watchdog_reset();

Diff for: src/utility/ota/OTA.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int rp2040_connect_onOTARequest(char const * ota_url);
6363
#endif
6464

6565
#ifdef BOARD_STM32H7
66-
int portenta_h7_onOTARequest(char const * ota_url);
66+
int portenta_h7_onOTARequest(char const * ota_url, const bool use_ethernet);
6767
#endif
6868

6969
#endif /* ARDUINO_OTA_LOGIC_H_ */

Diff for: src/utility/watchdog/Watchdog.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
# define NANO_RP2040_WATCHDOG_MAX_TIMEOUT_ms (8389)
3939
#endif /* ARDUINO_ARCH_MBED */
4040

41+
#include <Arduino_ConnectionHandler.h>
42+
4143
/******************************************************************************
4244
* GLOBAL VARIABLES
4345
******************************************************************************/
@@ -114,6 +116,19 @@ static void mbed_watchdog_reset()
114116
}
115117
}
116118

119+
#if defined (ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC)
120+
static void mbed_watchdog_enable_network_feed(const bool use_ethernet)
121+
{
122+
#if defined(BOARD_HAS_ETHERNET)
123+
if(use_ethernet) {
124+
Ethernet.setFeedWatchdogFunc(watchdog_reset);
125+
} else
126+
#endif
127+
WiFi.setFeedWatchdogFunc(watchdog_reset);
128+
129+
}
130+
#endif
131+
117132
void mbed_watchdog_trigger_reset()
118133
{
119134
watchdog_config_t cfg;
@@ -154,4 +169,15 @@ void watchdog_reset()
154169
mbed_watchdog_reset();
155170
#endif
156171
}
172+
173+
void watchdog_enable_network_feed(const bool use_ethernet)
174+
{
175+
#ifdef WIFI_HAS_FEED_WATCHDOG_FUNC
176+
WiFi.setFeedWatchdogFunc(watchdog_reset);
177+
#endif
178+
179+
#ifdef ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC
180+
mbed_watchdog_enable_network_feed(use_ethernet);
181+
#endif
182+
}
157183
#endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */

Diff for: src/utility/watchdog/Watchdog.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
2626
void watchdog_enable();
2727
void watchdog_reset();
28+
void watchdog_enable_network_feed(const bool use_ethernet);
2829
#endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */
2930

3031
#ifdef ARDUINO_ARCH_MBED

0 commit comments

Comments
 (0)