소스 검색

Merge pull request #1903 from XXXXzzzz000/add_iwdg_driver

[driver][iwdg]add iwdg driver. | 添加iwdg驱动,参考:stm32f4xx-HAL/driver_wdg
Bernard Xiong 6 년 전
부모
커밋
beff9104be

+ 11 - 0
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"

+ 3 - 0
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']
     

+ 71 - 0
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

+ 18 - 0
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

+ 1 - 1
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