liam-geotab opened a new pull request, #19969:
URL: https://github.com/apache/nuttx/pull/19969

   ## Summary
   
   Add windowed-watchdog support (WWDG) for STM32H5.
   
   The feature was developed in an experimental way by the author and boiled 
down to being the same as the H7 implementation so I have committed it with 
minor changes relative to the H7 version. There are a couple of different 
register define differences and inttypes.h defines have been used in more 
format strings, 
   
   ## Impact
   
   The changes are additive. STM32_WWDG could already be enabled before due to 
H5 `HAVE`ing STM32_HAVE_IP_WDG_M3M4_V1 but now there is an implementation.
   
   ## Testing
   
   Validated with the watchdog example app. This implementation has also been 
in service for some months.
   
   To test, call `stm32_wwdginitialize("/dev/watchdog1");` in 
boards/arm/stm32h5/nucleo-h563zi/src/stm32_bringup.c.
   
   `nucleo-h563zi:nsh` with the following enabled:
   
   ```
   CONFIG_DEBUG_WATCHDOG=y
   CONFIG_DEBUG_WATCHDOG_ERROR=y
   CONFIG_DEBUG_WATCHDOG_INFO=y
   CONFIG_DEBUG_WATCHDOG_WARN=y
   CONFIG_EXAMPLES_WATCHDOG=y
   CONFIG_EXAMPLES_WATCHDOG_DEVPATH="/dev/watchdog1"
   CONFIG_STM32_WWDG=y
   ```
   
   Run `wdog -t200 -p150 -d1000` - set 200 ms timeout, 150 ms ping period, 1000 
ms before allowing the watchdog to timeout. In this use case, it's the same as 
IWDG. The maximum timeout for WWDG is only 268 ms. **There is an inconsistency 
you can see in `g_main: flags=00000003 timeout=197 timeleft=150`. The timeleft 
is 150 but it should be 50. IWDG does not have this issue.** The issue was 
inherited from the STM32H7 implementation.
   
   ```
   ABCG
   stm32_wwdginitialize: Entry: devpath=/dev/watchdog1
   stm32_settimeout: Entry: timeout=268
   stm32_settimeout: wdgtb=7 fwwdg=238 reload=62 timeout=264
   watchdog_register: Entry: path=/dev/watchdog1
   
   NuttShell (NSH) NuttX-13.0.1-RC0
   nsh> wdog -t200 -p150 -d1000
   wdog_open: crefs: 0
   wdog_ioctl: cmd: 516 arg: 200
   stm32_settimeout: Entry: timeout=200
   stm32_settimeout: wdgtb=7 fwwdg=238 reload=46 timeout=197
   wdog_ioctl: cmd: 513 arg: 0
   stm32_start: Entry
   wdog_ioctl: cmd: 515 arg: 536891056
   stm32_getstatus: Entry
   stm32_getstatus: Status     :
   stm32_getstatus:   flags    : 00000003
   stm32_getstatus:   timeout  : 197
   stm32_getstatus:   timeleft : 150
   wdowdog_ioctl: cmd: 518 arg: 0
   stm32_keepalive: Entry
   g_main: flags=00000003 timeout=197 timeleft=150
     ping elapsed=0
   wdog_ioctl: cmd: 515 arg: 536891056
   stm32_getstatus: Entry
   stm32_getstatus: Status     :
   stm32_getstatus:   flags    : 00000003
   stm32_getstatus:   timeout  : 197
   stm32_getstatus:   timeleft : 150
   wdowdog_ioctl: cmd: 518 arg: 0
   stm32_keepalive: Entry
   g_main: flags=00000003 timeout=197 timeleft=150
     ping elapsed=170
   wdog_ioctl: cmd: 515 arg: 536891056
   stm32_getstatus: Entry
   stm32_getstatus: Status     :
   stm32_getstatus:   flags    : 00000003
   stm32_getstatus:   timeout  : 197
   stm32_getstatus:   timeleft : 150
   wdowdog_ioctl: cmd: 518 arg: 0
   stm32_keepalive: Entry
   g_main: flags=00000003 timeout=197 timeleft=150
     ping elapsed=340
   wdog_ioctl: cmd: 515 arg: 536891056
   stm32_getstatus: Entry
   stm32_getstatus: Status     :
   stm32_getstatus:   flags    : 00000003
   stm32_getstatus:   timeout  : 197
   stm32_getstatus:   timeleft : 150
   wdowdog_ioctl: cmd: 518 arg: 0
   stm32_keepalive: Entry
   g_main: flags=00000003 timeout=197 timeleft=150
     ping elapsed=510
   wdog_ioctl: cmd: 515 arg: 536891056
   stm32_getstatus: Entry
   stm32_getstatus: Status     :
   stm32_getstatus:   flags    : 00000003
   stm32_getstatus:   timeout  : 197
   stm32_getstatus:   timeleft : 150
   wdowdog_ioctl: cmd: 518 arg: 0
   stm32_keepalive: Entry
   g_main: flags=00000003 timeout=197 timeleft=150
     ping elapsed=680
   wdog_ioctl: cmd: 515 arg: 536891056
   stm32_getstatus: Entry
   stm32_getstatus: Status     :
   stm32_getstatus:   flags    : 00000003
   stm32_getstatus:   timeout  : 197
   stm32_getstatus:   timeleft : 150
   wdowdog_ioctl: cmd: 518 arg: 0
   stm32_keepalive: Entry
   g_main: flags=00000003 timeout=197 timeleft=150
     ping elapsed=850
   wdog_ioctl: cmd: 515 arg: 536891056
   stm32_getstatus: Entry
   stm32_getstatus: Status     :
   stm32_getstatus:   flags    : 00000003
   stm32_getstatus:   timeout  : 197
   stm32_getstatus:   timeleft : 150
   wdog_main: flags=00000003 timeout=197 timeleft=150
     NO ping elapsed=1020
   ABCG
   stm32_wwdginitialize: Entry: devpath=/dev/watchdog1
   stm32_settimeout: Entry: timeout=268
   stm32_settimeout: wdgtb=7 fwwdg=238 reload=62 timeout=264
   watchdog_register: Entry: path=/dev/watchdog1
   
   NuttShell (NSH) NuttX-13.0.1-RC0
   nsh>
   ```
   
   A WWDG triggers a reset if not pinged before timing out. It can also trigger 
a reset if pinged twice within a minimum timeframe. This is something that 
distinguishes WWDG from IWDG.
   
   ```diff
   diff --git a/examples/watchdog/watchdog_main.c 
b/examples/watchdog/watchdog_main.c
   index 1167f3116..0271d66d3 100644
   --- a/examples/watchdog/watchdog_main.c
   +++ b/examples/watchdog/watchdog_main.c
   @@ -251,6 +251,15 @@ int main(int argc, FAR char *argv[])
          goto errout_with_dev;
        }
    
   +  /* Set the watchdog window */
   +
   +  ret = ioctl(fd, WDIOC_MINTIME, 75);
   +  if (ret < 0)
   +    {
   +      printf("wdog_main: ioctl(WDIOC_SETMINTIME) failed: %d\n", errno);
   +      goto errout_with_dev;
   +    }
   +
      /* Then start the watchdog timer. */
    
      ret = ioctl(fd, WDIOC_START, 0);
   ```
   
   Test pinging it too rapidly. The mintime is 75 ms but ping it every 50 ms to 
cause a reset for that reason.
   
   ```
   nsh> wdog -t200 -p50 -d1000
   wdog_open: crefs: 0
   wdog_ioctl: cmd: 516 arg: 200
   stm32_settimeout: Entry: timeout=200
   stm32_settimeout: wdgtb=7 fwwdg=238 reload=46 timeout=197
   wdog_ioctl: cmd: 640 arg: 75
   wdog_ioctl: Forwarding unrecognized cmd: 640 arg: 75
   stm32_ioctl: Entry: cmd=640 arg=75
   wdog_ioctl: cmd: 513 arg: 0
   stm32_start: Entry
   wdog_ioctl: cmd: 515 arg: 536891056
   stm32_getstatus: Entry
   stm32_getstatus: Status     :
   stm32_getstatus:   flags    : 00000003
   stm32_getstatus:   timeout  : 197
   stm32_getstatus:   timeleft : 46
   wdowdog_ioctl: cmd: 518 arg: 0
   �ABCG_keepalive: Entry
   stm32_wwdginitialize: Entry: devpath=/dev/watchdog1
   stm32_settimeout: Entry: timeout=268
   stm32_settimeout: wdgtb=7 fwwdg=238 reload=62 timeout=264
   watchdog_register: Entry: path=/dev/watchdog1
   
   NuttShell (NSH) NuttX-13.0.1-RC0
   nsh>
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to