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

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 851bccec3 hw/mcu: add reset cause handling for apollo2 board
851bccec3 is described below

commit 851bccec30eb67220859dc49812f6e466ce15bf6
Author: Wiktor Kwiatkowski <[email protected]>
AuthorDate: Mon Jul 21 15:54:29 2025 +0200

    hw/mcu: add reset cause handling for apollo2 board
    
    Added support for reading the reset cause using the RSTGEN->STAT
    register. Function checks what kind of reset occurred and
    returns matching hal_reset_reason enum value.
    After that the register is cleared.
---
 hw/mcu/ambiq/apollo2/src/hal_system.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/hw/mcu/ambiq/apollo2/src/hal_system.c 
b/hw/mcu/ambiq/apollo2/src/hal_system.c
index 31e05a4b3..5a144e531 100644
--- a/hw/mcu/ambiq/apollo2/src/hal_system.c
+++ b/hw/mcu/ambiq/apollo2/src/hal_system.c
@@ -48,7 +48,32 @@ hal_system_reset(void)
 enum hal_reset_reason
 hal_reset_cause(void)
 {
-    enum hal_reset_reason reason = 0;
+    static enum hal_reset_reason reason;
+    uint32_t reg;
+
+    if (reason) {
+        return reason;
+    }
+
+    /* Read STAT register */
+    reg = RSTGEN->STAT;
+
+    if (reg & RSTGEN_STAT_PORSTAT_Msk) {
+        reason = HAL_RESET_POR;
+    } else if (reg & RSTGEN_STAT_WDRSTAT_Msk) {
+        reason = HAL_RESET_WATCHDOG;
+    } else if (reg & RSTGEN_STAT_SWRSTAT_Msk) {
+        reason = HAL_RESET_SOFT;
+    } else if (reg & RSTGEN_STAT_EXRSTAT_Msk) {
+        reason = HAL_RESET_PIN;
+    } else if (reg & RSTGEN_STAT_BORSTAT_Msk) {
+        reason = HAL_RESET_BROWNOUT;
+    } else {
+        reason = HAL_RESET_OTHER;
+    }
+
+    /* Clear STAT register */
+    RSTGEN->CLRSTAT = 1;
     return (reason);
 }
 

Reply via email to