Two new features needs to be added to our project: The functionality of a heartbeat that will indicate if the program is “working as expected” will be added, as well a watchdog that will apply a reset if for some reason the application crashes and got stuck
Heartbeat
REQ-401
One single led should be used to represent a heart beat with a frequency of just one hertz
REQ-402
An initialization function must be created to configure all the necessary resources to control the led
static void Heartbeat_Init( void );
REQ-403
A function must be created to controls the blinking every hertz. It is necessary to use the function HAL_GeTick
to establish the frequency, there is a code you can use as reference in here NVIC: Systick Timer
static void Heartbeat_MainFuncntion( void );
Watchdog
REQ-404
Add to the project the activation of the windowed watchdog that come with the microcontroller, which allows resetting the system in case it stays frozen for some reason. Calculate the most appropriate time window for your application to avoid an unexpected reset.
REQ-405
A function will need to be created that initializes the watchdog and configures it to work in a given time window.
static void Watchdog_Init( void );
REQ-406
You must create a function to “resets” the watchdog every x time (also use the HAL_GeTick
function) so that it does not cause a soft reset when is not necessary. How often?, well that something that you must deduct based on the amount of CPU time all the task consume (worst case scenario) in one execution run
static void Watchdog_MainFunction( void );
REQ-407
There is no need to create a separate file to place the new functions, all of them should be declared as static in the same main.c file
REQ-408
The functions from this piece of code should be called from main.c like this.
#include "bsp.h"
#include "serial.h"
#include "clock.h"
//Add more includes as needed
...
int main( void )
{
HAL_Init();
Serial_Init();
Clock_Init();
Heartbeat_Init();
Watchdog_Init();
//Add more initilizations as needed
for(;;)
{
Serial_MainFunction();
Clock_MainFunction();
Heartbeat_MainFunction();
Watchdog_MainFunction();
//Add another task as needed
}
}