2019-07-15 16:07:00 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Centaur Analytics, Inc
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2020-03-24 14:28:48 -05:00
|
|
|
#define DT_DRV_COMPAT st_stm32_window_watchdog
|
|
|
|
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/drivers/watchdog.h>
|
2019-07-15 16:07:00 +03:00
|
|
|
#include <soc.h>
|
2020-11-20 15:33:11 +01:00
|
|
|
#include <stm32_ll_bus.h>
|
|
|
|
#include <stm32_ll_wwdg.h>
|
|
|
|
#include <stm32_ll_system.h>
|
2019-07-15 16:07:00 +03:00
|
|
|
#include <errno.h>
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/sys/__assert.h>
|
|
|
|
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
|
|
|
|
#include <zephyr/drivers/clock_control.h>
|
2022-10-04 15:33:53 +02:00
|
|
|
#include <zephyr/irq.h>
|
2022-10-04 17:59:29 +02:00
|
|
|
#include <zephyr/sys_clock.h>
|
2019-07-15 16:07:00 +03:00
|
|
|
|
|
|
|
#include "wdt_wwdg_stm32.h"
|
|
|
|
|
2021-09-10 21:26:46 +10:00
|
|
|
#define LOG_LEVEL CONFIG_WDT_LOG_LEVEL
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/logging/log.h>
|
2019-11-13 09:13:08 +01:00
|
|
|
LOG_MODULE_REGISTER(wdt_wwdg_stm32);
|
|
|
|
|
2019-07-15 16:07:00 +03:00
|
|
|
#define WWDG_INTERNAL_DIVIDER 4096U
|
|
|
|
#define WWDG_RESET_LIMIT WWDG_COUNTER_MIN
|
|
|
|
#define WWDG_COUNTER_MIN 0x40
|
|
|
|
#define WWDG_COUNTER_MAX 0x7f
|
|
|
|
|
2021-03-05 17:26:35 +01:00
|
|
|
#if defined WWDG_CFR_WDGTB_Pos
|
|
|
|
#define WWDG_PRESCALER_POS WWDG_CFR_WDGTB_Pos
|
|
|
|
#define WWDG_PRESCALER_MASK WWDG_CFR_WDGTB_Msk
|
|
|
|
#else
|
|
|
|
#error "WWDG CFR WDGTB position not defined for soc"
|
|
|
|
#endif
|
|
|
|
|
2021-03-05 18:14:27 +01:00
|
|
|
/*
|
2022-02-24 12:00:55 +00:00
|
|
|
* additionally to the internal divider, the clock is divided by a
|
2021-03-05 18:14:27 +01:00
|
|
|
* programmable prescaler.
|
|
|
|
*/
|
|
|
|
#if defined(LL_WWDG_PRESCALER_128)
|
|
|
|
#define WWDG_PRESCALER_EXPONENT_MAX 7 /* 2^7 = 128 */
|
|
|
|
#elif defined(LL_WWDG_PRESCALER_8)
|
|
|
|
#define WWDG_PRESCALER_EXPONENT_MAX 3 /* 2^3 = 8 */
|
|
|
|
#endif
|
|
|
|
|
2019-07-15 16:07:00 +03:00
|
|
|
/* The timeout of the WWDG in milliseconds is calculated by the below formula:
|
|
|
|
*
|
|
|
|
* t_WWDG = 1000 * ((counter & 0x3F) + 1) / f_WWDG (ms)
|
|
|
|
*
|
|
|
|
* where:
|
|
|
|
* - t_WWDG: WWDG timeout
|
|
|
|
* - counter: a value in [0x40, 0x7F] representing the cycles before timeout.
|
|
|
|
* Giving the counter a value below 0x40, will result in an
|
|
|
|
* immediate system reset. A reset is produced when the counter
|
|
|
|
* rolls over from 0x40 to 0x3F.
|
|
|
|
* - f_WWDG: the frequency of the WWDG clock. This can be calculated by the
|
|
|
|
* below formula:
|
|
|
|
* f_WWDG = f_PCLK / (4096 * prescaler) (Hz)
|
|
|
|
* where:
|
|
|
|
* - f_PCLK: the clock frequency of the system
|
|
|
|
* - 4096: the constant internal divider
|
2021-03-05 18:14:27 +01:00
|
|
|
* - prescaler: the programmable divider with valid values of 1, 2, 4 or 8,
|
|
|
|
* and for some series additionally 16, 32, 64 and 128
|
2019-07-15 16:07:00 +03:00
|
|
|
*
|
|
|
|
* The minimum timeout is calculated with:
|
|
|
|
* - counter = 0x40
|
|
|
|
* - prescaler = 1
|
2022-02-24 12:00:55 +00:00
|
|
|
* The maximum timeout is calculated with:
|
2019-07-15 16:07:00 +03:00
|
|
|
* - counter = 0x7F
|
|
|
|
* - prescaler = 8
|
|
|
|
*
|
|
|
|
* E.g. for f_PCLK = 2MHz
|
|
|
|
* t_WWDG_min = 1000 * ((0x40 & 0x3F) + 1) / (2000000 / (4096 * 1))
|
|
|
|
* = 2.048 ms
|
|
|
|
* t_WWDG_max = 1000 * ((0x7F & 0x3F) + 1) / (2000000 / (4096 * 8))
|
|
|
|
* = 1048.576 ms
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ABS_DIFF_UINT(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))
|
2021-01-27 11:07:03 +01:00
|
|
|
#define WWDG_TIMEOUT_ERROR_MARGIN(__TIMEOUT__) (__TIMEOUT__ / 10)
|
2019-07-15 16:07:00 +03:00
|
|
|
#define IS_WWDG_TIMEOUT(__TIMEOUT_GOLDEN__, __TIMEOUT__) \
|
2021-01-27 11:07:03 +01:00
|
|
|
(__TIMEOUT__ - __TIMEOUT_GOLDEN__) < \
|
|
|
|
WWDG_TIMEOUT_ERROR_MARGIN(__TIMEOUT_GOLDEN__)
|
2019-07-15 16:07:00 +03:00
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void wwdg_stm32_irq_config(const struct device *dev);
|
2019-07-15 16:07:00 +03:00
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static uint32_t wwdg_stm32_get_pclk(const struct device *dev)
|
2019-07-15 16:07:00 +03:00
|
|
|
{
|
2022-08-22 10:36:10 +02:00
|
|
|
const struct device *const clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
|
2019-07-15 16:07:00 +03:00
|
|
|
const struct wwdg_stm32_config *cfg = WWDG_STM32_CFG(dev);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t pclk_rate;
|
2019-07-15 16:07:00 +03:00
|
|
|
|
2023-03-28 08:24:07 +02:00
|
|
|
if (clock_control_get_rate(clk, (clock_control_subsys_t) &cfg->pclken,
|
2019-11-13 09:13:08 +01:00
|
|
|
&pclk_rate) < 0) {
|
|
|
|
LOG_ERR("Failed call clock_control_get_rate");
|
|
|
|
return -EIO;
|
|
|
|
}
|
2019-07-15 16:07:00 +03:00
|
|
|
|
|
|
|
return pclk_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Calculates the timeout in microseconds.
|
|
|
|
*
|
|
|
|
* @param dev Pointer to device structure.
|
2022-02-24 12:00:55 +00:00
|
|
|
* @param prescaler_exp The prescaler exponent value(Base 2).
|
2019-07-15 16:07:00 +03:00
|
|
|
* @param counter The counter value.
|
|
|
|
* @return The timeout calculated in microseconds.
|
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static uint32_t wwdg_stm32_get_timeout(const struct device *dev,
|
2021-03-05 17:26:35 +01:00
|
|
|
uint32_t prescaler_exp,
|
2020-04-30 20:33:38 +02:00
|
|
|
uint32_t counter)
|
2019-07-15 16:07:00 +03:00
|
|
|
{
|
2021-03-05 17:26:35 +01:00
|
|
|
uint32_t divider = WWDG_INTERNAL_DIVIDER * (1 << prescaler_exp);
|
2019-11-12 10:59:03 +01:00
|
|
|
float f_wwdg = (float)wwdg_stm32_get_pclk(dev) / divider;
|
2019-07-15 16:07:00 +03:00
|
|
|
|
|
|
|
return USEC_PER_SEC * (((counter & 0x3F) + 1) / f_wwdg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Calculates prescaler & counter values.
|
|
|
|
*
|
|
|
|
* @param dev Pointer to device structure.
|
|
|
|
* @param timeout Timeout value in microseconds.
|
2021-03-05 17:26:35 +01:00
|
|
|
* @param prescaler_exp Pointer to prescaler exponent value(Base 2).
|
2019-07-15 16:07:00 +03:00
|
|
|
* @param counter Pointer to counter value.
|
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static void wwdg_stm32_convert_timeout(const struct device *dev,
|
|
|
|
uint32_t timeout,
|
2021-03-05 17:26:35 +01:00
|
|
|
uint32_t *prescaler_exp,
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t *counter)
|
2019-07-15 16:07:00 +03:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t clock_freq = wwdg_stm32_get_pclk(dev);
|
2019-07-15 16:07:00 +03:00
|
|
|
|
|
|
|
/* Convert timeout to seconds. */
|
|
|
|
float timeout_s = (float)timeout / USEC_PER_SEC;
|
|
|
|
float wwdg_freq;
|
|
|
|
|
2021-03-05 17:26:35 +01:00
|
|
|
*prescaler_exp = 0U;
|
2019-07-15 16:07:00 +03:00
|
|
|
*counter = 0;
|
|
|
|
|
2021-03-05 18:14:27 +01:00
|
|
|
for (*prescaler_exp = 0; *prescaler_exp <= WWDG_PRESCALER_EXPONENT_MAX;
|
|
|
|
(*prescaler_exp)++) {
|
|
|
|
wwdg_freq = ((float)clock_freq) / WWDG_INTERNAL_DIVIDER
|
|
|
|
/ (1 << *prescaler_exp);
|
2019-07-15 16:07:00 +03:00
|
|
|
/* +1 to ceil the result, which may lose from truncation */
|
2020-05-27 11:26:57 -05:00
|
|
|
*counter = (uint32_t)(timeout_s * wwdg_freq + 1) - 1;
|
2021-01-27 11:07:03 +01:00
|
|
|
*counter += WWDG_RESET_LIMIT;
|
2019-07-15 16:07:00 +03:00
|
|
|
|
|
|
|
if (*counter <= WWDG_COUNTER_MAX) {
|
2021-03-05 17:26:35 +01:00
|
|
|
return;
|
2019-07-15 16:07:00 +03:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 17:26:35 +01:00
|
|
|
|
|
|
|
/* timeout longer than wwdg can provide, set to max possible value */
|
|
|
|
*counter = WWDG_COUNTER_MAX;
|
|
|
|
*prescaler_exp = WWDG_PRESCALER_EXPONENT_MAX;
|
2019-07-15 16:07:00 +03:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int wwdg_stm32_setup(const struct device *dev, uint8_t options)
|
2019-07-15 16:07:00 +03:00
|
|
|
{
|
|
|
|
WWDG_TypeDef *wwdg = WWDG_STM32_STRUCT(dev);
|
|
|
|
|
|
|
|
/* Deactivate running when debugger is attached. */
|
|
|
|
if (options & WDT_OPT_PAUSE_HALTED_BY_DBG) {
|
|
|
|
#if defined(CONFIG_SOC_SERIES_STM32F0X)
|
|
|
|
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_DBGMCU);
|
|
|
|
#elif defined(CONFIG_SOC_SERIES_STM32L0X)
|
|
|
|
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_DBGMCU);
|
2023-03-17 16:35:28 +01:00
|
|
|
#elif defined(CONFIG_SOC_SERIES_STM32C0X) || defined(CONFIG_SOC_SERIES_STM32G0X)
|
2021-11-26 15:18:13 +01:00
|
|
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_DBGMCU);
|
2019-07-15 16:07:00 +03:00
|
|
|
#endif
|
2021-11-26 14:16:32 +01:00
|
|
|
#if defined(CONFIG_SOC_SERIES_STM32H7X)
|
|
|
|
LL_DBGMCU_APB3_GRP1_FreezePeriph(LL_DBGMCU_APB3_GRP1_WWDG1_STOP);
|
2021-11-26 14:44:21 +01:00
|
|
|
#elif defined(CONFIG_SOC_SERIES_STM32MP1X)
|
|
|
|
LL_DBGMCU_APB1_GRP1_FreezePeriph(LL_DBGMCU_APB1_GRP1_WWDG1_STOP);
|
2021-11-26 14:16:32 +01:00
|
|
|
#else
|
2019-07-15 16:07:00 +03:00
|
|
|
LL_DBGMCU_APB1_GRP1_FreezePeriph(LL_DBGMCU_APB1_GRP1_WWDG_STOP);
|
2021-11-26 14:16:32 +01:00
|
|
|
#endif /* CONFIG_SOC_SERIES_STM32H7X */
|
2019-07-15 16:07:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options & WDT_OPT_PAUSE_IN_SLEEP) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2019-12-05 10:49:31 +02:00
|
|
|
/* Ensure that Early Wakeup Interrupt Flag is cleared */
|
|
|
|
LL_WWDG_ClearFlag_EWKUP(wwdg);
|
|
|
|
|
2019-07-15 16:07:00 +03:00
|
|
|
/* Enable the WWDG */
|
|
|
|
LL_WWDG_Enable(wwdg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int wwdg_stm32_disable(const struct device *dev)
|
2019-07-15 16:07:00 +03:00
|
|
|
{
|
|
|
|
/* watchdog cannot be stopped once started unless SOC gets a reset */
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int wwdg_stm32_install_timeout(const struct device *dev,
|
2019-07-15 16:07:00 +03:00
|
|
|
const struct wdt_timeout_cfg *config)
|
|
|
|
{
|
|
|
|
struct wwdg_stm32_data *data = WWDG_STM32_DATA(dev);
|
|
|
|
WWDG_TypeDef *wwdg = WWDG_STM32_STRUCT(dev);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t timeout = config->window.max * USEC_PER_MSEC;
|
|
|
|
uint32_t calculated_timeout;
|
2021-03-05 17:26:35 +01:00
|
|
|
uint32_t prescaler_exp = 0U;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t counter = 0U;
|
2019-07-15 16:07:00 +03:00
|
|
|
|
|
|
|
if (config->callback != NULL) {
|
|
|
|
data->callback = config->callback;
|
|
|
|
}
|
|
|
|
|
2021-03-05 17:26:35 +01:00
|
|
|
wwdg_stm32_convert_timeout(dev, timeout, &prescaler_exp, &counter);
|
|
|
|
calculated_timeout = wwdg_stm32_get_timeout(dev, prescaler_exp, counter);
|
2021-01-27 11:07:03 +01:00
|
|
|
|
2021-03-05 17:26:35 +01:00
|
|
|
LOG_DBG("prescaler: %d", (1 << prescaler_exp));
|
2021-01-27 11:07:03 +01:00
|
|
|
LOG_DBG("Desired WDT: %d us", timeout);
|
|
|
|
LOG_DBG("Set WDT: %d us", calculated_timeout);
|
|
|
|
|
2021-03-05 17:26:35 +01:00
|
|
|
if (!(IS_WWDG_COUNTER(counter) &&
|
2019-07-15 16:07:00 +03:00
|
|
|
IS_WWDG_TIMEOUT(timeout, calculated_timeout))) {
|
|
|
|
/* One of the parameters provided is invalid */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->counter = counter;
|
|
|
|
|
|
|
|
/* Configure WWDG */
|
|
|
|
/* Set the programmable prescaler */
|
2021-03-05 17:26:35 +01:00
|
|
|
LL_WWDG_SetPrescaler(wwdg,
|
|
|
|
(prescaler_exp << WWDG_PRESCALER_POS) & WWDG_PRESCALER_MASK);
|
2019-07-15 16:07:00 +03:00
|
|
|
|
|
|
|
/* Set window the same as the counter to be able to feed the WWDG almost
|
|
|
|
* immediately
|
|
|
|
*/
|
|
|
|
LL_WWDG_SetWindow(wwdg, counter);
|
|
|
|
LL_WWDG_SetCounter(wwdg, counter);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int wwdg_stm32_feed(const struct device *dev, int channel_id)
|
2019-07-15 16:07:00 +03:00
|
|
|
{
|
|
|
|
WWDG_TypeDef *wwdg = WWDG_STM32_STRUCT(dev);
|
|
|
|
struct wwdg_stm32_data *data = WWDG_STM32_DATA(dev);
|
|
|
|
|
|
|
|
ARG_UNUSED(channel_id);
|
|
|
|
LL_WWDG_SetCounter(wwdg, data->counter);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs
This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.
Note that only the ISR passed to IRQ_CONNECT are of interest here.
In order to do so, the script fix_isr.py below is necessary:
from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os
cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
...
(
const struct device *D = (const struct device *)P;
|
const struct device *D = P;
)
...
}
@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
...
const struct device *D;
...
(
D = (const struct device *)P;
|
D = P;
)
...
}
@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
...
}
@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);
@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
...
}
@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
...
}
"""
def find_isr(fn):
db = []
data = None
start = 0
try:
with open(fn, 'r+') as f:
data = str(mmap.mmap(f.fileno(), 0).read())
except Exception as e:
return db
while True:
isr = ""
irq = data.find('IRQ_CONNECT', start)
while irq > -1:
p = 1
arg = 1
p_o = data.find('(', irq)
if p_o < 0:
irq = -1
break;
pos = p_o + 1
while p > 0:
if data[pos] == ')':
p -= 1
elif data[pos] == '(':
p += 1
elif data[pos] == ',' and p == 1:
arg += 1
if arg == 3:
isr += data[pos]
pos += 1
isr = isr.strip(',\\n\\t ')
if isr not in db and len(isr) > 0:
db.append(isr)
start = pos
break
if irq < 0:
break
return db
def patch_isr(fn, isr_list):
if len(isr_list) <= 0:
return
for isr in isr_list:
tmplt = cocci_template.replace('<!fn!>', isr)
with open('/tmp/isr_fix.cocci', 'w') as f:
f.write(tmplt)
cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]
subprocess.run(cmd)
def process_files(path):
if path.is_file() and path.suffix in ['.h', '.c']:
p = str(path.parent) + '/' + path.name
isr_list = find_isr(p)
patch_isr(p, isr_list)
elif path.is_dir():
for p in path.iterdir():
process_files(p)
if len(sys.argv) < 2:
print("You need to provide a dir/file path")
sys.exit(1)
process_files(Path(sys.argv[1]))
And is run: ./fix_isr.py <zephyr root directory>
Finally, some files needed manual fixes such.
Fixes #27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-06-17 14:58:56 +02:00
|
|
|
void wwdg_stm32_isr(const struct device *dev)
|
2019-07-15 16:07:00 +03:00
|
|
|
{
|
|
|
|
struct wwdg_stm32_data *data = WWDG_STM32_DATA(dev);
|
|
|
|
WWDG_TypeDef *wwdg = WWDG_STM32_STRUCT(dev);
|
|
|
|
|
|
|
|
if (LL_WWDG_IsEnabledIT_EWKUP(wwdg)) {
|
|
|
|
if (LL_WWDG_IsActiveFlag_EWKUP(wwdg)) {
|
|
|
|
LL_WWDG_ClearFlag_EWKUP(wwdg);
|
|
|
|
data->callback(dev, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wdt_driver_api wwdg_stm32_api = {
|
|
|
|
.setup = wwdg_stm32_setup,
|
|
|
|
.disable = wwdg_stm32_disable,
|
|
|
|
.install_timeout = wwdg_stm32_install_timeout,
|
|
|
|
.feed = wwdg_stm32_feed,
|
|
|
|
};
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int wwdg_stm32_init(const struct device *dev)
|
2019-07-15 16:07:00 +03:00
|
|
|
{
|
2022-08-22 10:36:10 +02:00
|
|
|
const struct device *const clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
|
2019-07-15 16:07:00 +03:00
|
|
|
const struct wwdg_stm32_config *cfg = WWDG_STM32_CFG(dev);
|
|
|
|
|
|
|
|
wwdg_stm32_irq_config(dev);
|
|
|
|
|
2022-08-08 16:06:08 +02:00
|
|
|
if (!device_is_ready(clk)) {
|
|
|
|
LOG_ERR("clock control device not ready");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2023-03-28 08:24:07 +02:00
|
|
|
return clock_control_on(clk, (clock_control_subsys_t) &cfg->pclken);
|
2019-07-15 16:07:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct wwdg_stm32_data wwdg_stm32_dev_data = {
|
|
|
|
.counter = WWDG_RESET_LIMIT,
|
|
|
|
.callback = NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct wwdg_stm32_config wwdg_stm32_dev_config = {
|
|
|
|
.pclken = {
|
2020-03-24 14:28:48 -05:00
|
|
|
.enr = DT_INST_CLOCKS_CELL(0, bits),
|
|
|
|
.bus = DT_INST_CLOCKS_CELL(0, bus)
|
2019-07-15 16:07:00 +03:00
|
|
|
},
|
2020-03-24 14:28:48 -05:00
|
|
|
.Instance = (WWDG_TypeDef *)DT_INST_REG_ADDR(0),
|
2019-07-15 16:07:00 +03:00
|
|
|
};
|
|
|
|
|
2021-04-28 12:07:15 +02:00
|
|
|
DEVICE_DT_INST_DEFINE(0, wwdg_stm32_init, NULL,
|
2020-12-10 08:49:59 -06:00
|
|
|
&wwdg_stm32_dev_data, &wwdg_stm32_dev_config,
|
2019-07-15 16:07:00 +03:00
|
|
|
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
|
|
|
&wwdg_stm32_api);
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void wwdg_stm32_irq_config(const struct device *dev)
|
2019-07-15 16:07:00 +03:00
|
|
|
{
|
|
|
|
WWDG_TypeDef *wwdg = WWDG_STM32_STRUCT(dev);
|
|
|
|
|
2020-03-24 14:28:48 -05:00
|
|
|
IRQ_CONNECT(DT_INST_IRQN(0),
|
|
|
|
DT_INST_IRQ(0, priority),
|
2020-12-10 08:49:59 -06:00
|
|
|
wwdg_stm32_isr, DEVICE_DT_INST_GET(0), 0);
|
2020-03-24 14:28:48 -05:00
|
|
|
irq_enable(DT_INST_IRQN(0));
|
2019-07-15 16:07:00 +03:00
|
|
|
LL_WWDG_EnableIT_EWKUP(wwdg);
|
|
|
|
}
|