Skip to content

Commit c6b5412

Browse files
Add watchdog timer to STM32 code #262
1 parent 29be37d commit c6b5412

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

STM32All-In-One/src/main.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ extern "C"
3737
void SystemClock_Config(void);
3838
}
3939

40+
#include <IWatchdog.h>
41+
4042
#include "SPI.h"
4143
#include <SerialEncoder.h>
4244
#include "packet_processor.h"
@@ -496,6 +498,9 @@ void setup()
496498
{
497499
SystemClock_Config();
498500

501+
// Initialize the IWDG with 4 seconds timeout. This would cause a CPU reset if the IWDG timer is not reloaded in approximately 4 seconds.
502+
IWatchdog.begin(4000000);
503+
499504
configurePins();
500505
DisableThermistorPower();
501506

@@ -967,10 +972,12 @@ void ServiceSerialPort()
967972
}
968973
}
969974

970-
971975
void loop()
972976
{
973977

978+
// make sure the code in this loop is executed in less than 2 seconds to leave 50% headroom for the timer reload.
979+
IWatchdog.reload();
980+
974981
// Temperature sensor readings...
975982
EnableThermistorPower();
976983
TakeExternalTempMeasurements(celldata);
@@ -1079,5 +1086,4 @@ void loop()
10791086
delay(2);
10801087
countdown--;
10811088
}
1082-
10831089
}

0 commit comments

Comments
 (0)