This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit ceea742239681f4a3ba7148f6acb502f892e7336
Author: dechao_gong <[email protected]>
AuthorDate: Thu Aug 27 10:40:30 2026 +0800

    arch/arm/rtl8720f: add watchdog driver support
    
    Wire the RTL8720F into the shared Ameba watchdog driver
    (arch/arm/src/common/ameba/ameba_wdg.c), registered as /dev/watchdog0.
    Only the per-chip base address and IRQ differ, so this adds a small
    ameba_wdg_chip.h (WDG2 non-secure system watchdog at 0x40801D80,
    KM4TZ_NS_WDG IRQ 52, verified against the SoC hal_platform.h and
    ameba_vector_table.h) plus the Make.defs/CMakeLists build hooks, the
    board bring-up registration, and a wdg defconfig.  The shared driver is
    unchanged.
    
    Also corrects the RTL8720F row in the rtl8721dx chip-header reference
    table (the non-secure system WDG IRQ is KM4TZ_NS_WDG = 52).
    
    Assisted-by: Claude <[email protected]>
    Signed-off-by: dechao_gong <[email protected]>
---
 .../arm/rtl8720f/boards/rtl8720f_evb/index.rst     | 13 +++++
 arch/arm/src/rtl8720f/CMakeLists.txt               |  4 ++
 arch/arm/src/rtl8720f/Make.defs                    |  4 ++
 .../src/{rtl8721dx => rtl8720f}/ameba_wdg_chip.h   | 30 +++++-----
 arch/arm/src/rtl8721dx/ameba_wdg_chip.h            |  4 +-
 .../rtl8720f/rtl8720f_evb/configs/wdg/defconfig    | 46 +++++++++++++++
 .../arm/rtl8720f/rtl8720f_evb/src/CMakeLists.txt   |  7 ++-
 boards/arm/rtl8720f/rtl8720f_evb/src/Makefile      |  6 +-
 .../rtl8720f/rtl8720f_evb/src/rtl8720f_bringup.c   | 10 ++++
 .../rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h       | 13 +++++
 .../arm/rtl8720f/rtl8720f_evb/src/rtl8720f_wdg.c   | 67 ++++++++++++++++++++++
 11 files changed, 183 insertions(+), 21 deletions(-)

diff --git a/Documentation/platforms/arm/rtl8720f/boards/rtl8720f_evb/index.rst 
b/Documentation/platforms/arm/rtl8720f/boards/rtl8720f_evb/index.rst
index 8a3231d9752..c99764350e1 100644
--- a/Documentation/platforms/arm/rtl8720f/boards/rtl8720f_evb/index.rst
+++ b/Documentation/platforms/arm/rtl8720f/boards/rtl8720f_evb/index.rst
@@ -45,6 +45,8 @@ Supported in this NuttX port:
   on the SDK fwlib register layer
 * On-chip RTC exposed as a ``/dev/rtc0`` date/time character device with
   alarm support, driven directly on the SDK fwlib register layer
+* On-chip watchdog exposed as a ``/dev/watchdog0`` character device, driven
+  directly on the SDK fwlib register layer
 
 Buttons and LEDs
 ================
@@ -177,6 +179,17 @@ NSH ``date`` command, and arm a one-shot wakeup with the 
example::
     nsh> date -s "Jun 16 12:00:00 2026"  # set the RTC
     nsh> alarm 10                        # fire an alarm in 10 seconds
 
+wdg
+---
+
+Minimal NSH with the on-chip watchdog driver and the ``wdog`` example
+enabled (no Wi-Fi). The watchdog is registered at ``/dev/watchdog0`` from the
+board bring-up (``boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_wdg.c``); it
+has no board wiring (it is an internal timer). Exercise it with the example,
+which opens the device, sets a timeout, and pings it::
+
+    nsh> wdog                            # run the watchdog example
+
 nsh
 ---
 
diff --git a/arch/arm/src/rtl8720f/CMakeLists.txt 
b/arch/arm/src/rtl8720f/CMakeLists.txt
index 3b78ed7dbdc..a2517107303 100644
--- a/arch/arm/src/rtl8720f/CMakeLists.txt
+++ b/arch/arm/src/rtl8720f/CMakeLists.txt
@@ -74,6 +74,10 @@ if(CONFIG_AMEBA_RTC)
   list(APPEND SRCS ${AMEBA_COMMON}/ameba_rtc.c)
 endif()
 
+if(CONFIG_AMEBA_WDG)
+  list(APPEND SRCS ${AMEBA_COMMON}/ameba_wdg.c)
+endif()
+
 target_include_directories(arch PRIVATE ${AMEBA_COMMON})
 target_sources(arch PRIVATE ${SRCS})
 
diff --git a/arch/arm/src/rtl8720f/Make.defs b/arch/arm/src/rtl8720f/Make.defs
index 14ae3933d18..42ac8697a1e 100644
--- a/arch/arm/src/rtl8720f/Make.defs
+++ b/arch/arm/src/rtl8720f/Make.defs
@@ -84,6 +84,10 @@ ifeq ($(CONFIG_AMEBA_RTC),y)
 CHIP_CSRCS += ameba_rtc.c
 endif
 
+ifeq ($(CONFIG_AMEBA_WDG),y)
+CHIP_CSRCS += ameba_wdg.c
+endif
+
 ############################################################################
 # Realtek RTL8720F SDK integration
 #
diff --git a/arch/arm/src/rtl8721dx/ameba_wdg_chip.h 
b/arch/arm/src/rtl8720f/ameba_wdg_chip.h
similarity index 72%
copy from arch/arm/src/rtl8721dx/ameba_wdg_chip.h
copy to arch/arm/src/rtl8720f/ameba_wdg_chip.h
index d2925ea8934..027b5378822 100644
--- a/arch/arm/src/rtl8721dx/ameba_wdg_chip.h
+++ b/arch/arm/src/rtl8720f/ameba_wdg_chip.h
@@ -1,5 +1,5 @@
 /****************************************************************************
- * arch/arm/src/rtl8721dx/ameba_wdg_chip.h
+ * arch/arm/src/rtl8720f/ameba_wdg_chip.h
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -20,8 +20,8 @@
  *
  ****************************************************************************/
 
-#ifndef __ARCH_ARM_SRC_RTL8721DX_AMEBA_WDG_CHIP_H
-#define __ARCH_ARM_SRC_RTL8721DX_AMEBA_WDG_CHIP_H
+#ifndef __ARCH_ARM_SRC_RTL8720F_AMEBA_WDG_CHIP_H
+#define __ARCH_ARM_SRC_RTL8720F_AMEBA_WDG_CHIP_H
 
 /****************************************************************************
  * Included Files
@@ -36,7 +36,7 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* Per-chip watchdog wiring for RTL8721DX (amebadplus).  The shared driver
+/* Per-chip watchdog wiring for RTL8720F.  The shared driver
  * (arch/arm/src/common/ameba/ameba_wdg.c) includes this header to learn
  * which watchdog instance to drive and its interrupt line.  A port to
  * another Ameba chip supplies a same-named header on the chip include path;
@@ -44,11 +44,11 @@
  *
  * The Ameba SoCs carry several watchdog instances (an always-on IWDG plus
  * one "system" WDG per CPU, each with a secure and a non-secure alias).
- * This NuttX port runs on the KM4 core, and -- matching the vendor HAL
- * wdt_api.c, which selects KM4_NS_WDG_DEV / KM4_NS_WDG_IRQ for
- * CONFIG_ARM_CORE_CM4 -- we drive the KM4 non-secure system watchdog.  As
- * with the I2C/SPI drivers the non-secure register alias (0x41xxxxxx) is the
- * one actually reachable from this core, so that is the base used here.
+ * This NuttX port runs on the KM4TZ core, and -- matching the vendor HAL
+ * wdt_api.c, which selects the CPU's non-secure system WDG device / IRQ --
+ * we drive that non-secure system watchdog.  As with the I2C/SPI drivers
+ * the non-secure register alias (0x40xxxxxx) is the one actually reachable
+ * from this core, so that is the base used here.
  *
  * BOTH the base address and the interrupt vector are chip-specific.  The WDG
  * register block, structures, magic keys and the ms-based timeout are the
@@ -56,13 +56,11 @@
  * the two values below move per chip (verified against each SoC's
  * hal_platform.h and ameba_vector_table.h):
  *
- *   chip         KM4/CPU non-secure system WDG base   NuttX IRQ
+ *   chip         non-secure system WDG base           NuttX IRQ
  *   -----------  -----------------------------------  ---------------------
  *   amebadplus   WDG2_REG_BASE            0x41008D80  KM4_NS_WDG_IRQ    = 65
- *   amebalite    WDG2_REG_BASE            0x4101F040  (see its vector table)
- *   amebasmart   WDG2_REG_BASE            0x41000440  (see its vector table)
  *   amebagreen2  WDG2_REG_BASE            0x4080AD80  CPU0_NS_WDG_IRQ   = 69
- *   RTL8720F     WDG2_REG_BASE            0x40801D80  KM4NS_WDG_IRQ     = 49
+ *   RTL8720F     WDG2_REG_BASE            0x40801D80  KM4TZ_NS_WDG_IRQ  = 52
  *
  * A new chip only edits this header: AMEBA_WDG_BASE is the register base of
  * its non-secure system WDG (cast to the fwlib WDG_TypeDef * by the shared
@@ -71,7 +69,7 @@
  * data-driven, never-computed pattern.
  */
 
-#define AMEBA_WDG_BASE            0x41008d80ul
-#define AMEBA_WDG_IRQ             RTL8721DX_IRQ_KM4_NS_WDG
+#define AMEBA_WDG_BASE            0x40801d80ul
+#define AMEBA_WDG_IRQ             RTL8720F_IRQ_KM4TZ_NS_WDG
 
-#endif /* __ARCH_ARM_SRC_RTL8721DX_AMEBA_WDG_CHIP_H */
+#endif /* __ARCH_ARM_SRC_RTL8720F_AMEBA_WDG_CHIP_H */
diff --git a/arch/arm/src/rtl8721dx/ameba_wdg_chip.h 
b/arch/arm/src/rtl8721dx/ameba_wdg_chip.h
index d2925ea8934..98bba2559ac 100644
--- a/arch/arm/src/rtl8721dx/ameba_wdg_chip.h
+++ b/arch/arm/src/rtl8721dx/ameba_wdg_chip.h
@@ -59,10 +59,8 @@
  *   chip         KM4/CPU non-secure system WDG base   NuttX IRQ
  *   -----------  -----------------------------------  ---------------------
  *   amebadplus   WDG2_REG_BASE            0x41008D80  KM4_NS_WDG_IRQ    = 65
- *   amebalite    WDG2_REG_BASE            0x4101F040  (see its vector table)
- *   amebasmart   WDG2_REG_BASE            0x41000440  (see its vector table)
  *   amebagreen2  WDG2_REG_BASE            0x4080AD80  CPU0_NS_WDG_IRQ   = 69
- *   RTL8720F     WDG2_REG_BASE            0x40801D80  KM4NS_WDG_IRQ     = 49
+ *   RTL8720F     WDG2_REG_BASE            0x40801D80  KM4TZ_NS_WDG_IRQ  = 52
  *
  * A new chip only edits this header: AMEBA_WDG_BASE is the register base of
  * its non-secure system WDG (cast to the fwlib WDG_TypeDef * by the shared
diff --git a/boards/arm/rtl8720f/rtl8720f_evb/configs/wdg/defconfig 
b/boards/arm/rtl8720f/rtl8720f_evb/configs/wdg/defconfig
new file mode 100644
index 00000000000..5e83111741d
--- /dev/null
+++ b/boards/arm/rtl8720f/rtl8720f_evb/configs/wdg/defconfig
@@ -0,0 +1,46 @@
+#
+# This file is autogenerated: PLEASE DO NOT EDIT IT.
+#
+# You can use "make menuconfig" to make any modifications to the installed 
.config file.
+# You can then do "make savedefconfig" to generate a new defconfig file that 
includes your
+# modifications.
+#
+CONFIG_AMEBA_WDG=y
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="rtl8720f_evb"
+CONFIG_ARCH_BOARD_RTL8720F_EVB=y
+CONFIG_ARCH_CHIP="rtl8720f"
+CONFIG_ARCH_CHIP_RTL8720F=y
+CONFIG_ARCH_INTERRUPTSTACK=2048
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV8M_SYSTICK=y
+CONFIG_BUILTIN=y
+CONFIG_DEBUG_ASSERTIONS=y
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_FULLOPT=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DEFAULT_TASK_STACKSIZE=4096
+CONFIG_EXAMPLES_HELLO=y
+CONFIG_EXAMPLES_WATCHDOG=y
+CONFIG_FS_PROCFS=y
+CONFIG_FS_TMPFS=y
+CONFIG_IDLETHREAD_STACKSIZE=4096
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_LIBC_MEMFD_ERROR=y
+CONFIG_MM_DEFAULT_ALIGNMENT=32
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=262144
+CONFIG_RAM_START=0x30008000
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_HPWORK=y
+CONFIG_SCHED_HPWORKPRIORITY=192
+CONFIG_SCHED_LPWORK=y
+CONFIG_STACK_COLORATION=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_SYSTEM_NSH_STACKSIZE=2500
+CONFIG_TIMER=y
+CONFIG_TIMER_ARCH=y
+CONFIG_USEC_PER_TICK=1000
diff --git a/boards/arm/rtl8720f/rtl8720f_evb/src/CMakeLists.txt 
b/boards/arm/rtl8720f/rtl8720f_evb/src/CMakeLists.txt
index b590ce55a80..5160bf6170a 100644
--- a/boards/arm/rtl8720f/rtl8720f_evb/src/CMakeLists.txt
+++ b/boards/arm/rtl8720f/rtl8720f_evb/src/CMakeLists.txt
@@ -50,6 +50,10 @@ if(CONFIG_AMEBA_RTC)
   list(APPEND SRCS rtl8720f_rtc.c)
 endif()
 
+if(CONFIG_AMEBA_WDG)
+  list(APPEND SRCS rtl8720f_wdg.c)
+endif()
+
 target_sources(board PRIVATE ${SRCS})
 
 if(CONFIG_AMEBA_GPIO
@@ -58,7 +62,8 @@ if(CONFIG_AMEBA_GPIO
    OR CONFIG_AMEBA_SPI
    OR CONFIG_AMEBA_PWM
    OR CONFIG_AMEBA_ADC
-   OR CONFIG_AMEBA_RTC)
+   OR CONFIG_AMEBA_RTC
+   OR CONFIG_AMEBA_WDG)
   # The board pin tables pull in the shared drivers' public headers from
   # arch/arm/src/common/ameba/, not on the default board include path.
   target_include_directories(board
diff --git a/boards/arm/rtl8720f/rtl8720f_evb/src/Makefile 
b/boards/arm/rtl8720f/rtl8720f_evb/src/Makefile
index 617e9d4767f..ca5e5a9e931 100644
--- a/boards/arm/rtl8720f/rtl8720f_evb/src/Makefile
+++ b/boards/arm/rtl8720f/rtl8720f_evb/src/Makefile
@@ -52,10 +52,14 @@ ifeq ($(CONFIG_AMEBA_RTC),y)
 CSRCS += rtl8720f_rtc.c
 endif
 
+ifeq ($(CONFIG_AMEBA_WDG),y)
+CSRCS += rtl8720f_wdg.c
+endif
+
 # The board pin tables pull in the shared drivers' public headers from
 # arch/arm/src/common/ameba/, which is not on the default board include path.
 
-ifneq 
($(CONFIG_AMEBA_GPIO)$(CONFIG_AMEBA_UART)$(CONFIG_AMEBA_I2C)$(CONFIG_AMEBA_SPI)$(CONFIG_AMEBA_PWM)$(CONFIG_AMEBA_ADC)$(CONFIG_AMEBA_RTC),)
+ifneq 
($(CONFIG_AMEBA_GPIO)$(CONFIG_AMEBA_UART)$(CONFIG_AMEBA_I2C)$(CONFIG_AMEBA_SPI)$(CONFIG_AMEBA_PWM)$(CONFIG_AMEBA_ADC)$(CONFIG_AMEBA_RTC)$(CONFIG_AMEBA_WDG),)
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)common$(DELIM)ameba
 endif
 
diff --git a/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_bringup.c 
b/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_bringup.c
index ac3e232c9e2..59a9cb0d411 100644
--- a/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_bringup.c
+++ b/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_bringup.c
@@ -190,6 +190,16 @@ int rtl8720f_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_AMEBA_WDG
+  /* Register the board's watchdog at /dev/watchdog0. */
+
+  ret = rtl8720f_wdg_initialize();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: rtl8720f_wdg_initialize failed: %d\n", ret);
+    }
+#endif
+
   /* Install the inter-core HW IPC-semaphore RTOS hooks LAST -- after all the
    * flash / WHC bring-up above, and just before this (board_late_initialize)
    * path returns and nx_start() hands off to the init task.
diff --git a/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h 
b/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h
index 0e2e940bfbb..d8cc70e811a 100644
--- a/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h
+++ b/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h
@@ -104,6 +104,19 @@ int rtl8720f_adc_initialize(void);
 int rtl8720f_rtc_initialize(void);
 #endif
 
+#ifdef CONFIG_AMEBA_WDG
+/****************************************************************************
+ * Name: rtl8720f_wdg_initialize
+ *
+ * Description:
+ *   Register the board's watchdog at /dev/watchdog0
+ *   (boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_wdg.c).
+ *
+ ****************************************************************************/
+
+int rtl8720f_wdg_initialize(void);
+#endif
+
 #ifdef CONFIG_RTL8720F_WIFI
 /****************************************************************************
  * Name: rtl8720f_wifi_initialize
diff --git a/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_wdg.c 
b/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_wdg.c
new file mode 100644
index 00000000000..e83d35c7fa2
--- /dev/null
+++ b/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_wdg.c
@@ -0,0 +1,67 @@
+/****************************************************************************
+ * boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_wdg.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <syslog.h>
+#include <errno.h>
+
+#include "ameba_wdg.h"
+#include "rtl8720f_rtl8720f_evb.h"
+
+#ifdef CONFIG_AMEBA_WDG
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rtl8720f_wdg_initialize
+ *
+ * Description:
+ *   Register the on-chip watchdog at /dev/watchdog0.  The WDG has no board
+ *   wiring (it is an internal timer), so this simply defers to the shared
+ *   driver.
+ *
+ ****************************************************************************/
+
+int rtl8720f_wdg_initialize(void)
+{
+  int ret;
+
+  ret = ameba_wdg_initialize();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR,
+             "ERROR: ameba_wdg_initialize(/dev/watchdog0) failed: %d\n",
+             ret);
+      return ret;
+    }
+
+  return OK;
+}
+
+#endif /* CONFIG_AMEBA_WDG */

Reply via email to