@@ -57,62 +57,63 @@ void common_hal_watchdog_set_timeout(watchdog_watchdogtimer_obj_t *self,
5757 uint64_t timeout = new_timeout * 1000 ;
5858 mp_arg_validate_int_max (timeout , 256000 , MP_QSTR_WatchDogTimeout );
5959
60- if ((uint32_t )self -> timeout != (uint32_t )new_timeout ) {
61-
62- // Watchdog Initialize settings
63- WDOG_Init_TypeDef wdogInit = WDOG_INIT_DEFAULT ;
64-
65- switch ((uint32_t )new_timeout )
66- {
67- case 1 :
68- wdogInit .perSel = wdogPeriod_1k ;
69- break ;
70- case 2 :
71- wdogInit .perSel = wdogPeriod_2k ;
72- break ;
73- case 4 :
74- wdogInit .perSel = wdogPeriod_4k ;
75- break ;
76- case 8 :
77- wdogInit .perSel = wdogPeriod_8k ;
78- break ;
79- case 16 :
80- wdogInit .perSel = wdogPeriod_16k ;
81- break ;
82- case 32 :
83- wdogInit .perSel = wdogPeriod_32k ;
84- break ;
85- case 64 :
86- wdogInit .perSel = wdogPeriod_64k ;
87- break ;
88- case 128 :
89- wdogInit .perSel = wdogPeriod_128k ;
90- break ;
91- case 256 :
92- wdogInit .perSel = wdogPeriod_256k ;
93- break ;
94- default :
95- mp_raise_ValueError (
96- MP_ERROR_TEXT ("Timeout value supported: 1,2,4,8,16,32,64,128,256" ));
60+ // Only reset the watchdog to update the timer if mode has already been set.
61+ if (self -> mode != WATCHDOGMODE_RESET ) {
62+ return ;
63+ }
64+ // Watchdog Initialize settings
65+ WDOG_Init_TypeDef wdogInit = WDOG_INIT_DEFAULT ;
66+
67+ switch ((uint32_t )new_timeout )
68+ {
69+ case 1 :
70+ wdogInit .perSel = wdogPeriod_1k ;
71+ break ;
72+ case 2 :
73+ wdogInit .perSel = wdogPeriod_2k ;
74+ break ;
75+ case 4 :
76+ wdogInit .perSel = wdogPeriod_4k ;
77+ break ;
78+ case 8 :
79+ wdogInit .perSel = wdogPeriod_8k ;
80+ break ;
81+ case 16 :
82+ wdogInit .perSel = wdogPeriod_16k ;
83+ break ;
84+ case 32 :
85+ wdogInit .perSel = wdogPeriod_32k ;
86+ break ;
87+ case 64 :
88+ wdogInit .perSel = wdogPeriod_64k ;
89+ break ;
90+ case 128 :
91+ wdogInit .perSel = wdogPeriod_128k ;
92+ break ;
93+ case 256 :
94+ wdogInit .perSel = wdogPeriod_256k ;
95+ break ;
96+ default :
97+ mp_raise_ValueError (
98+ MP_ERROR_TEXT ("Timeout value supported: 1,2,4,8,16,32,64,128,256" ));
9799
98- }
100+ }
99101
100- self -> timeout = new_timeout ;
101- // Enable clock for the WDOG module; has no effect on xG21
102- CMU_ClockEnable (cmuClock_WDOG0 , true);
102+ self -> timeout = new_timeout ;
103+ // Enable clock for the WDOG module; has no effect on xG21
104+ CMU_ClockEnable (cmuClock_WDOG0 , true);
103105
104- // ULFRCO as clock source
105- CMU_ClockSelectSet (cmuClock_WDOG0 , cmuSelect_ULFRCO );
106+ // ULFRCO as clock source
107+ CMU_ClockSelectSet (cmuClock_WDOG0 , cmuSelect_ULFRCO );
106108
107- wdogInit .em1Run = true;
108- wdogInit .em2Run = true;
109- wdogInit .em3Run = true;
109+ wdogInit .em1Run = true;
110+ wdogInit .em2Run = true;
111+ wdogInit .em3Run = true;
110112
111- // Initializing watchdog with chosen settings
112- WDOGn_Init (DEFAULT_WDOG , & wdogInit );
113+ // Initializing watchdog with chosen settings
114+ WDOGn_Init (DEFAULT_WDOG , & wdogInit );
113115
114- _wdt_init = true;
115- }
116+ _wdt_init = true;
116117}
117118
118119watchdog_watchdogmode_t common_hal_watchdog_get_mode
0 commit comments