Skip to content

Commit 646d091

Browse files
authored
Bugfix: Feed watchdog within busy-wait-loop within connectBearSSL to prevent a premature reset. (#157)
Within the Arduino IoT Cloud firmware stack we are using a watchdog to prevent unintended application lockup. Unfortunately in certain situations the connection attempt undertaken within WiFiNINA can take so long that the watchdog is triggered although everything is fine. This change is feeding the watchdog (if one is present) so to avoid prematurely triggering of the watchdog.
1 parent e92e095 commit 646d091

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/utility/server_drv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void ServerDrv::startClient(const char* host, uint8_t host_len, uint32_t ipAddre
130130

131131
SpiDrv::spiSlaveDeselect();
132132
//Wait the reply elaboration
133-
SpiDrv::waitForSlaveReady();
133+
SpiDrv::waitForSlaveReady(/* feed_watchdog = */ (protMode == TLS_BEARSSL_MODE));
134134
SpiDrv::spiSlaveSelect();
135135

136136
// Wait for reply

src/utility/spi_drv.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,30 @@ void SpiDrv::waitForSlaveSign()
207207
while (!waitSlaveSign());
208208
}
209209

210-
void SpiDrv::waitForSlaveReady()
210+
#if defined __has_include
211+
# if __has_include (<Adafruit_SleepyDog.h>)
212+
# include <Adafruit_SleepyDog.h>
213+
# define HAS_WATCHDOG 1
214+
# endif
215+
#else
216+
# define HAS_WATCHDOG 0
217+
#endif
218+
219+
void SpiDrv::waitForSlaveReady(bool const feed_watchdog)
211220
{
212-
while (!waitSlaveReady());
221+
#if HAS_WATCHDOG
222+
unsigned long const start = millis();
223+
#endif /* HAS_WATCHDOG */
224+
while (!waitSlaveReady())
225+
{
226+
#if HAS_WATCHDOG
227+
if (feed_watchdog) {
228+
if ((millis() - start) < 10000) {
229+
Watchdog.reset();
230+
}
231+
}
232+
#endif /* HAS_WATCHDOG */
233+
}
213234
}
214235

215236
void SpiDrv::getParam(uint8_t* param)

src/utility/spi_drv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class SpiDrv
5959

6060
static char spiTransfer(volatile char data);
6161

62-
static void waitForSlaveReady();
62+
static void waitForSlaveReady(bool const feed_watchdog = false);
6363

6464
//static int waitSpiChar(char waitChar, char* readChar);
6565

0 commit comments

Comments
 (0)