summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2018-10-20 10:36:29 +0800
committerGitHub <[email protected]>2018-10-20 10:36:29 +0800
commitbeff9104be7978e69920143ca073e97b5e736815 (patch)
treee4dfaf65c028fc35f475a33392926015c61fbd17
parent2ae638e22d62f231bc59ade5f4e4e42f43f8d9a3 (diff)
parent5e95c574566adfd5512759b4f185121f84c6e58e (diff)
Merge pull request #1903 from XXXXzzzz000/add_iwdg_driver
[driver][iwdg]add iwdg driver. | 添加iwdg驱动,参考:stm32f4xx-HAL/driver_wdg
-rw-r--r--bsp/stm32f10x-HAL/Kconfig11
-rw-r--r--bsp/stm32f10x-HAL/drivers/SConscript3
-rw-r--r--bsp/stm32f10x-HAL/drivers/drv_iwg.c71
-rw-r--r--bsp/stm32f10x-HAL/drivers/drv_iwg.h18
-rw-r--r--bsp/stm32f10x-HAL/drivers/stm32f1xx_hal_conf.h2
5 files changed, 104 insertions, 1 deletions
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 <rthw.h>
+#include <rtthread.h>
+#include <rtdevice.h>
+#include <board.h>
+
+
+#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