GlobLib
HAL and API libraries for MCUs and hardware.

This module contains low level functions for watchdog configuration. More...

Files

file  stm32f103cb_iwdg.h
 Header file for stm32f103cb independant watchdog timer.
 

Functions

mcu_error IWDG_setup (uint32_t timeout)
 Initialize the independant watchdog timer. More...
 
bool IWDG_resetCheck (void)
 Check if reset occured from watchdog timeout. More...
 
void IWDG_feed (void)
 Reload the watchdog timer. More...
 

Detailed Description

This module contains low level functions for watchdog configuration.

The stm32f103cb independant watchdog timer can be configured with a timeout of up to 26 seconds. To avoid a forced reset the timer should be reloaded with IWDG_feed() before the timeout time has elapsed.

IWDG_resetCheck() can be used to check if a reset has occured from a watchdog timeout.

Author
Stuart Ianna
Version
0.1
Date
June 2018
Warning
None
Bug:
None
Todo:
Verified Compilers
  • arm-none-eabi-gcc (15:4.9.3+svn231177-1) 4.9.3 20150529 (prerelease)
Working example
This program's loop time increasing by a factor of 10 each itteration. The increasing time causes a forced reset by the watchdog timer.
#include <coms128.h>
volatile int cap = 10;
int count;
int main(void){
//Serial setup
COMS(USART_1);
//Ideally this should be first part of program.
//Located here to demonstrate example with terminal
printl("Reset from IWDG");
}
else{
printl("Normal reset");
}
//Setup watchdog for reset after 1 second if not fed.
IWDG_setup(1000);
while (1){
//Feed the dog
prints("Feeding no");
printl(count++);
for(volatile int i = 0; i < cap; i++);
//Each time the loop gets longer
cap *= 10;
}
return 0;
}

Function Documentation

void IWDG_feed ( void  )

Reload the watchdog timer.

This should be called at least as often as the watchdog timeout value to avoid forced reset.

Definition at line 110 of file stm32f103cb_iwdg.c.

bool IWDG_resetCheck ( void  )

Check if reset occured from watchdog timeout.

Returns
  • 1 if reset occured from watchdog
  • 0 from other reset type.

Definition at line 98 of file stm32f103cb_iwdg.c.

mcu_error IWDG_setup ( uint32_t  timeout)

Initialize the independant watchdog timer.

This must be called before any other feature is used.

Parameters
timeoutThe timeout period in milliseconds
Returns
Error number as defined in mcu_error, E_IWDG_NOERROR if no error, E_IWDG_PERIOD if period is too long.

Definition at line 19 of file stm32f103cb_iwdg.c.