Skip to content

Commit 236c336

Browse files
authored
Merge pull request #12299 from NXPmicro/MXRT_WDOG
MIMXRT1050: Add Watchdog support
2 parents 1aa3b8f + 72bd899 commit 236c336

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2020 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "watchdog_api.h"
17+
18+
#if DEVICE_WATCHDOG
19+
20+
#include "reset_reason_api.h"
21+
#include "fsl_rtwdog.h"
22+
#include "fsl_clock.h"
23+
#include "platform/mbed_wait_api.h"
24+
25+
// Platform specific watchdog definitions
26+
#define LPO_CLOCK_FREQUENCY 32768
27+
#define MAX_TIMEOUT 0xFFFFUL
28+
#define DELAY_TIME 100000U
29+
30+
// Number of decrements in the timeout register per millisecond
31+
#define TICKS_PER_MS ((LPO_CLOCK_FREQUENCY) / 1000)
32+
33+
// Maximum timeout that can be specified in milliseconds
34+
#define MAX_TIMEOUT_MS ((MAX_TIMEOUT) / (TICKS_PER_MS))
35+
36+
watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
37+
{
38+
uint32_t temp;
39+
rtwdog_config_t cfg;
40+
41+
/* When system is boot up, WDOG32 is disabled. We must wait for at least 2.5
42+
* periods of wdog32 clock to reconfigure wodg32. So Delay a while to wait for
43+
* the previous configuration taking effect. */
44+
for (temp = 0; temp < DELAY_TIME; temp++) {
45+
__NOP();
46+
}
47+
48+
RTWDOG_GetDefaultConfig(&cfg);
49+
50+
cfg.workMode.enableStop = true;
51+
cfg.workMode.enableDebug = true;
52+
cfg.timeoutValue = (TICKS_PER_MS * config->timeout_ms);
53+
54+
RTWDOG_Init(RTWDOG, &cfg);
55+
56+
return WATCHDOG_STATUS_OK;
57+
}
58+
59+
void hal_watchdog_kick(void)
60+
{
61+
RTWDOG_Refresh(RTWDOG);
62+
}
63+
64+
watchdog_status_t hal_watchdog_stop(void)
65+
{
66+
RTWDOG_Deinit(RTWDOG);
67+
68+
return WATCHDOG_STATUS_OK;
69+
}
70+
71+
uint32_t hal_watchdog_get_reload_value(void)
72+
{
73+
const uint32_t timeout = RTWDOG->TOVAL;
74+
75+
return (timeout / TICKS_PER_MS);
76+
}
77+
78+
watchdog_features_t hal_watchdog_get_platform_features(void)
79+
{
80+
watchdog_features_t features;
81+
features.max_timeout = MAX_TIMEOUT_MS;
82+
features.update_config = true;
83+
features.disable_watchdog = true;
84+
features.clock_typical_frequency = 32000;
85+
features.clock_max_frequency = 32768;
86+
87+
return features;
88+
}
89+
90+
#endif // DEVICE_WATCHDOG

targets/targets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2849,7 +2849,8 @@
28492849
"SPI",
28502850
"SPISLAVE",
28512851
"STDIO_MESSAGES",
2852-
"TRNG"
2852+
"TRNG",
2853+
"WATCHDOG"
28532854
],
28542855
"release_versions": [
28552856
"2",

0 commit comments

Comments
 (0)