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/SConscript b/bsp/stm32f10x-HAL/drivers/SConscript index 43c9b3f4a0..feb72bed10 100644 --- a/bsp/stm32f10x-HAL/drivers/SConscript +++ b/bsp/stm32f10x-HAL/drivers/SConscript @@ -23,6 +23,9 @@ if GetDepend(['RT_USING_SDCARD']): if GetDepend(['RT_USING_I2C', 'RT_USING_I2C_BITOPS']): src += ['drv_i2c.c'] +if GetDepend(['RT_USING_WDT']): + src += ['drv_iwg.c'] + if rtconfig.CROSS_TOOL == 'gcc': src += ['gcc_startup.s'] 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