From 8107542d761489dd7c3046af7af24b94d5d03b49 Mon Sep 17 00:00:00 2001 From: XXXXzzzz000 <119524428@qq.com> Date: Wed, 17 Oct 2018 15:54:00 +0800 Subject: [PATCH] =?UTF-8?q?[driver][iwdg]add=20iwdg=20driver.=20|=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0iwdg=E9=A9=B1=E5=8A=A8,=E5=8F=82=E8=80=83:stm?= =?UTF-8?q?32f4xx-HAL/driver=5Fwdg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32f10x-HAL/Kconfig | 11 +++ bsp/stm32f10x-HAL/drivers/drv_iwg.c | 71 +++++++++++++++++++ bsp/stm32f10x-HAL/drivers/drv_iwg.h | 18 +++++ .../drivers/stm32f1xx_hal_conf.h | 2 +- 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 bsp/stm32f10x-HAL/drivers/drv_iwg.c create mode 100644 bsp/stm32f10x-HAL/drivers/drv_iwg.h diff --git a/bsp/stm32f10x-HAL/Kconfig b/bsp/stm32f10x-HAL/Kconfig index 534e930ba8..0276d0aa6c 100644 --- a/bsp/stm32f10x-HAL/Kconfig +++ b/bsp/stm32f10x-HAL/Kconfig @@ -182,6 +182,17 @@ if RT_USING_SPI default n endif + +menuconfig BSP_USING_WDT + bool "Using wdt" + select RT_USING_WDT + default n +if BSP_USING_WDT + config BSP_USING_WDT_IWDG + bool "Enable iwdg" + default n +endif + if RT_USING_DEVICE_IPC && (STM32F103RC || STM32F103RD || STM32F103RE || STM32F103RF || STM32F103RG ||STM32F103VC || STM32F103VD || STM32F103VE || STM32F103VF || STM32F103VG ||STM32F103ZC || STM32F103ZD || STM32F103ZE || STM32F103ZF || STM32F103ZG) config RT_USING_SDCARD bool "Using sdcard with sdio" diff --git a/bsp/stm32f10x-HAL/drivers/drv_iwg.c b/bsp/stm32f10x-HAL/drivers/drv_iwg.c new file mode 100644 index 0000000000..1d170b2df0 --- /dev/null +++ b/bsp/stm32f10x-HAL/drivers/drv_iwg.c @@ -0,0 +1,71 @@ +/* + * File : drv_iwg.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2015, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2017-11-08 ZYH the first version + */ + +#include +#include +#include +#include + + +#ifdef RT_USING_WDT +IWDG_HandleTypeDef hiwdg; +static rt_err_t drv_init(rt_watchdog_t *wdt) +{ + hiwdg.Instance = IWDG; + hiwdg.Init.Prescaler = IWDG_PRESCALER_16; //1s + hiwdg.Init.Reload = 4095; + if (HAL_IWDG_Init(&hiwdg) != HAL_OK) + { + RT_ASSERT(0); + } + return RT_EOK; +} + +static rt_err_t drv_control(rt_watchdog_t *wdt, int cmd, void *arg) +{ + switch (cmd) + { + case RT_DEVICE_CTRL_WDT_SET_TIMEOUT: + hiwdg.Init.Reload = (rt_uint32_t)arg; + if (HAL_IWDG_Init(&hiwdg) != HAL_OK) + { + return RT_ERROR; + } + break; + case RT_DEVICE_CTRL_WDT_KEEPALIVE: + HAL_IWDG_Refresh(&hiwdg); + break; + default: + return RT_ERROR; + } + return RT_EOK; +} + +static struct rt_watchdog_ops _ops = + { + drv_init, + drv_control + }; + +static rt_watchdog_t _iwg = + { + .ops = &_ops + }; + +int rt_iwg_init(void) +{ + return rt_hw_watchdog_register(&_iwg, "iwg", RT_DEVICE_FLAG_DEACTIVATE, RT_NULL); +} +INIT_BOARD_EXPORT(rt_iwg_init); +#endif diff --git a/bsp/stm32f10x-HAL/drivers/drv_iwg.h b/bsp/stm32f10x-HAL/drivers/drv_iwg.h new file mode 100644 index 0000000000..4bd63a6ca9 --- /dev/null +++ b/bsp/stm32f10x-HAL/drivers/drv_iwg.h @@ -0,0 +1,18 @@ +/* + * File : drv_iwg.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2015, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2017-11-08 ZYH the first version + */ + +#ifndef __DRV_IWG_H__ +#define __DRV_IWG_H__ +extern int rt_iwg_init(void); +#endif diff --git a/bsp/stm32f10x-HAL/drivers/stm32f1xx_hal_conf.h b/bsp/stm32f10x-HAL/drivers/stm32f1xx_hal_conf.h index 32be5f38d0..fa7d6cbf62 100644 --- a/bsp/stm32f10x-HAL/drivers/stm32f1xx_hal_conf.h +++ b/bsp/stm32f10x-HAL/drivers/stm32f1xx_hal_conf.h @@ -70,7 +70,7 @@ extern "C" { // #define HAL_I2C_MODULE_ENABLED // #define HAL_I2S_MODULE_ENABLED // #define HAL_IRDA_MODULE_ENABLED -// #define HAL_IWDG_MODULE_ENABLED +#define HAL_IWDG_MODULE_ENABLED // #define HAL_NAND_MODULE_ENABLED // #define HAL_NOR_MODULE_ENABLED // #define HAL_PCCARD_MODULE_ENABLED -- GitLab