6
6
//!
7
7
//! The Independent Watchdog peripheral triggers a system reset when its internal counter expires.
8
8
//!
9
- //! # Peripheral Naming
10
- //!
11
- //! The naming of the Independent Watchdog peripheral varies between parts
12
- //!
13
- //! | Parts | IWDG Peripheral | Second IWDG Peripheral |
14
- //! | --- | --- | --- |
15
- //! | stm32H742/743/750/753/7a3/7b0/7b3 | IWDG | - |
16
- //! | stm32h745/747/755/757 | IWDG1 | IWDG2 |
17
- //! | stm32h723/725/730/733/735 | IWDG1 | - |
18
- //!
19
9
//! # Examples
20
10
//!
21
- //! - [IWDG Example](https://github.com/stm32-rs/stm32h7xx-hal/blob/master/examples/independent_watchdog.rs)
22
- use crate :: { prelude:: * , time:: MilliSeconds } ;
23
-
24
- #[ cfg( any( feature = "rm0433" , feature = "rm0455" ) ) ]
25
- use crate :: stm32:: iwdg:: pr:: PR_A ;
26
- #[ cfg( any( feature = "rm0433" , feature = "rm0455" ) ) ]
27
- use crate :: stm32:: IWDG ;
28
-
29
- #[ cfg( any( all( feature = "rm0399" , feature = "cm7" ) , feature = "rm0468" ) ) ]
30
- use crate :: stm32:: iwdg1:: pr:: PR_A ;
31
- #[ cfg( any( all( feature = "rm0399" , feature = "cm7" ) , feature = "rm0468" ) ) ]
32
- use crate :: stm32:: IWDG1 as IWDG ;
33
-
34
- #[ cfg( all( feature = "rm0399" , feature = "cm4" ) ) ]
35
- use crate :: stm32:: iwdg2:: pr:: PR_A ;
36
- #[ cfg( all( feature = "rm0399" , feature = "cm4" ) ) ]
37
- use crate :: stm32:: IWDG2 as IWDG ;
11
+ //! - [IWDG Example](todo-insert-link-here)
12
+ //!
13
+ //! Originally from stm32h7-hal, adapted for stm32g4xx-hal
14
+ use crate :: { time:: { MicroSecond , U32Ext } , stm32:: {
15
+ IWDG ,
16
+ iwdg:: pr:: PR_A ,
17
+ } } ;
38
18
39
19
/// The implementation of the hardware IWDG
40
20
pub struct IndependentWatchdog {
@@ -91,13 +71,13 @@ impl IndependentWatchdog {
91
71
92
72
/// Start the watchdog where it must be fed before the max time is over and
93
73
/// not before the min time has passed
94
- pub fn start_windowed < T : Into < MilliSeconds > > (
74
+ pub fn start_windowed < T : Into < MicroSecond > > (
95
75
& mut self ,
96
76
min_window_time : T ,
97
77
max_window_time : T ,
98
78
) {
99
- let min_window_time: MilliSeconds = min_window_time. into ( ) ;
100
- let max_window_time: MilliSeconds = max_window_time. into ( ) ;
79
+ let min_window_time: MicroSecond = min_window_time. into ( ) ;
80
+ let max_window_time: MicroSecond = max_window_time. into ( ) ;
101
81
102
82
// Start the watchdog
103
83
self . iwdg . kr . write ( |w| w. key ( ) . start ( ) ) ;
@@ -107,7 +87,7 @@ impl IndependentWatchdog {
107
87
// Set the prescaler
108
88
let ( prescaler, _) = Self :: MAX_MILLIS_FOR_PRESCALER
109
89
. iter ( )
110
- . find ( |( _, max_millis) | * max_millis >= max_window_time. to_millis ( ) )
90
+ . find ( |( _, max_millis) | * max_millis >= max_window_time. 0 / 1000 )
111
91
. expect ( "IWDG max time is greater than is possible" ) ;
112
92
while self . iwdg . sr . read ( ) . pvu ( ) . bit_is_set ( ) {
113
93
cortex_m:: asm:: nop ( ) ;
@@ -123,10 +103,10 @@ impl IndependentWatchdog {
123
103
. write ( |w| w. win ( ) . bits ( Self :: MAX_COUNTER_VALUE as u16 ) ) ;
124
104
125
105
// Calculate the counter values
126
- let reload_value = max_window_time. to_millis ( )
106
+ let reload_value = ( max_window_time. 0 / 1000 )
127
107
* ( Self :: CLOCK_SPEED / 1000 )
128
108
/ Self :: get_prescaler_divider ( prescaler) ;
129
- let window_value = min_window_time. to_millis ( )
109
+ let window_value = ( min_window_time. 0 / 1000 )
130
110
* ( Self :: CLOCK_SPEED / 1000 )
131
111
/ Self :: get_prescaler_divider ( prescaler) ;
132
112
@@ -157,8 +137,8 @@ impl IndependentWatchdog {
157
137
}
158
138
159
139
/// Start the watchdog with the given max time and no minimal time
160
- pub fn start < T : Into < MilliSeconds > > ( & mut self , max_time : T ) {
161
- self . start_windowed ( 0_u32 . millis ( ) , max_time. into ( ) ) ;
140
+ pub fn start < T : Into < MicroSecond > > ( & mut self , max_time : T ) {
141
+ self . start_windowed ( 0_u32 . ms ( ) , max_time. into ( ) ) ;
162
142
}
163
143
164
144
fn get_prescaler_divider ( prescaler : & PR_A ) -> u32 {
0 commit comments