px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_iwdg.c
1/* =============================================================================
2 ____ ___ ____ ___ _ _ ___ __ __ ___ __ __ TM
3 | _ \ |_ _| / ___| / _ \ | \ | | / _ \ | \/ | |_ _| \ \/ /
4 | |_) | | | | | | | | | | \| | | | | | | |\/| | | | \ /
5 | __/ | | | |___ | |_| | | |\ | | |_| | | | | | | | / \
6 |_| |___| \____| \___/ |_| \_| \___/ |_| |_| |___| /_/\_\
7
8 Copyright (c) 2021 Pieter Conradie <https://piconomix.com>
9
10 License: MIT
11 https://github.com/piconomix/px-fwlib/blob/master/LICENSE.md
12
13 Title: px_iwdg.h : Watchdog module
14 Author(s): Pieter Conradie
15 Creation Date: 2021-05-08
16
17============================================================================= */
18
19/* _____STANDARD INCLUDES____________________________________________________ */
20
21/* _____PROJECT INCLUDES_____________________________________________________ */
22#include "px_iwdg.h"
23#include "px_stm32cube.h"
24#include "px_log.h"
25
26/* _____LOCAL DEFINITIONS____________________________________________________ */
27PX_LOG_NAME("px_iwdg");
28
29/* _____MACROS_______________________________________________________________ */
30
31/* _____GLOBAL VARIABLES_____________________________________________________ */
32
33/* _____LOCAL VARIABLES______________________________________________________ */
34
35/* _____LOCAL FUNCTION DECLARATIONS__________________________________________ */
36
37/* _____LOCAL FUNCTIONS______________________________________________________ */
38
39/* _____GLOBAL FUNCTIONS_____________________________________________________ */
40void px_iwdg_init(px_iwdg_prescaler_t prescaler, uint16_t reload, uint16_t window)
41{
42 // Check that parameters does not exceed maximum value
43 PX_LOG_ASSERT(reload < 0x1000);
44 PX_LOG_ASSERT(window < 0x1000);
45
46 // Enable peripheral
47 LL_IWDG_Enable(IWDG);
48 // Enable write access to prescaler, reload and window registers
49 LL_IWDG_EnableWriteAccess(IWDG);
50 // Set clock (40 kHz LSI) prescaler
51 LL_IWDG_SetPrescaler(IWDG, prescaler);
52 // Set counter reload value (maximum period before Watchdog will reset processor)
53 LL_IWDG_SetReloadCounter(IWDG, reload);
54 // Set watchdog counter window
55 if(window != 0)
56 {
57 LL_IWDG_SetWindow(IWDG, window);
58 }
59 // Wait until all values have been updated
60 while(!LL_IWDG_IsReady(IWDG)) {;}
61#if 0
62 // Freeze watchdog when processor is halted by debugger
63 LL_DBGMCU_APB1_GRP1_FreezePeriph(LL_DBGMCU_APB1_GRP1_IWDG_STOP);
64#endif
65}
66
68{
69 LL_IWDG_ReloadCounter(IWDG);
70}
71
#define PX_LOG_NAME(name)
Macro to declare a log name string once for each file to reduce code size.
Definition: px_log.h:349
#define PX_LOG_ASSERT(expression)
Macro that will test an expression, and block indefinitely if false.
Definition: px_log.h:440
void px_iwdg_init(px_iwdg_prescaler_t prescaler, uint16_t reload, uint16_t window)
Initialise Independent Watchdog.
Definition: px_iwdg.c:40
px_iwdg_prescaler_t
Independent Watchdog clock prescaler (40 kHz LSI clock source)
Definition: px_iwdg.h:47
void px_iwdg_reload_counter(void)
Reload watchdog counter, a.k.a.
Definition: px_iwdg.c:67