Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop fa9f9a33d -> 4cd926638


MYNEWT-437: Add watchdog for stm32f407

This change adds the hal for the stm32f407. Since the maximum
independent watchdog timeout is 32.768 seconds, I decided to
commit a different sanity and watchdog interval for the OS.
I changed them to 15 seconds and 30 seconds, respectively.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4cd92663
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4cd92663
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4cd92663

Branch: refs/heads/develop
Commit: 4cd92663888e0cfd1d1801f06a49d48ea501ec98
Parents: fa9f9a3
Author: William San Filippo <wi...@runtime.io>
Authored: Mon Oct 17 21:06:14 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Mon Oct 17 21:07:46 2016 -0700

----------------------------------------------------------------------
 .../include/bsp/stm32f4xx_hal_conf.h            |  1 +
 hw/mcu/stm/stm32f4xx/src/hal_watchdog.c         | 25 +++++++++++++++++++-
 kernel/os/src/os.c                              |  3 ++-
 kernel/os/syscfg.yml                            |  4 ++--
 4 files changed, 29 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4cd92663/hw/bsp/olimex_stm32-e407_devboard/include/bsp/stm32f4xx_hal_conf.h
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/include/bsp/stm32f4xx_hal_conf.h 
b/hw/bsp/olimex_stm32-e407_devboard/include/bsp/stm32f4xx_hal_conf.h
index 174fac7..720cf6c 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/include/bsp/stm32f4xx_hal_conf.h
+++ b/hw/bsp/olimex_stm32-e407_devboard/include/bsp/stm32f4xx_hal_conf.h
@@ -95,6 +95,7 @@
 #define HAL_GPIO_MODULE_ENABLED
 #define HAL_RCC_MODULE_ENABLED
 #define HAL_CORTEX_MODULE_ENABLED
+#define HAL_IWDG_MODULE_ENABLED
 #endif
 
 /* ########################## HSE/HSI Values adaptation ##################### 
*/

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4cd92663/hw/mcu/stm/stm32f4xx/src/hal_watchdog.c
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_watchdog.c 
b/hw/mcu/stm/stm32f4xx/src/hal_watchdog.c
index 97bc8e3..a31df3b 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_watchdog.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_watchdog.c
@@ -18,20 +18,43 @@
  */
 
 #include "hal/hal_watchdog.h"
+#include "stm32f407xx.h"
+#include "stm32f4xx_hal.h"
+#include "stm32f4xx_hal_iwdg.h"
+
+IWDG_HandleTypeDef g_wdt_cfg;
 
 int
 hal_watchdog_init(uint32_t expire_msecs)
 {
-    return (0);
+    uint32_t reload;
+
+    /* Max prescaler is 256 */
+    reload = 32768 / 256;
+    reload = (reload * expire_msecs) / 1000;
+
+    /* Check to make sure we are not trying a reload value that is too large */
+    if (reload > IWDG_RLR_RL) {
+        return -1;
+    }
+
+    g_wdt_cfg.Instance = IWDG;
+    g_wdt_cfg.Init.Prescaler = IWDG_PRESCALER_256;
+    g_wdt_cfg.Init.Reload = reload;
+
+    return 0;
 }
 
 void
 hal_watchdog_enable(void)
 {
+    __HAL_DBGMCU_FREEZE_IWDG();
+    HAL_IWDG_Init(&g_wdt_cfg);
 }
 
 void
 hal_watchdog_tickle(void)
 {
+    HAL_IWDG_Refresh(&g_wdt_cfg);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4cd92663/kernel/os/src/os.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os.c b/kernel/os/src/os.c
index 3cd8462..1ef523d 100644
--- a/kernel/os/src/os.c
+++ b/kernel/os/src/os.c
@@ -131,7 +131,8 @@ os_init_idle_task(void)
 
     assert(MYNEWT_VAL(WATCHDOG_INTERVAL) - 200 > MYNEWT_VAL(SANITY_INTERVAL));
 
-    hal_watchdog_init(MYNEWT_VAL(WATCHDOG_INTERVAL));
+    rc = hal_watchdog_init(MYNEWT_VAL(WATCHDOG_INTERVAL));
+    assert(rc == 0);
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4cd92663/kernel/os/syscfg.yml
----------------------------------------------------------------------
diff --git a/kernel/os/syscfg.yml b/kernel/os/syscfg.yml
index 6c613b5..2173c82 100644
--- a/kernel/os/syscfg.yml
+++ b/kernel/os/syscfg.yml
@@ -14,10 +14,10 @@ syscfg.defs:
         value: 1000000
     SANITY_INTERVAL:
         description: 'The interval (in milliseconds) at which the sanity 
checks should run, should be at least 200ms prior to watchdog'
-        value: 59500
+        value: 15000
     WATCHDOG_INTERVAL:
         description: 'The interval (in milliseconds) at which the watchdog 
should reset if not tickled, in ms'
-        value: 60000
+        value: 30000
     MSYS_1_BLOCK_COUNT:
         description: 'TBD'
         value: 12

Reply via email to