Skip to content

Commit

Permalink
Add watchdog timer to STM32 code #262
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartpittaway committed Dec 6, 2023
1 parent 29be37d commit c6b5412
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions STM32All-In-One/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ extern "C"
void SystemClock_Config(void);
}

#include <IWatchdog.h>

#include "SPI.h"
#include <SerialEncoder.h>
#include "packet_processor.h"
Expand Down Expand Up @@ -496,6 +498,9 @@ void setup()
{
SystemClock_Config();

// Initialize the IWDG with 4 seconds timeout. This would cause a CPU reset if the IWDG timer is not reloaded in approximately 4 seconds.
IWatchdog.begin(4000000);

configurePins();
DisableThermistorPower();

Expand Down Expand Up @@ -967,10 +972,12 @@ void ServiceSerialPort()
}
}


void loop()
{

// make sure the code in this loop is executed in less than 2 seconds to leave 50% headroom for the timer reload.
IWatchdog.reload();

// Temperature sensor readings...
EnableThermistorPower();
TakeExternalTempMeasurements(celldata);
Expand Down Expand Up @@ -1079,5 +1086,4 @@ void loop()
delay(2);
countdown--;
}

}

0 comments on commit c6b5412

Please sign in to comment.