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

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

commit 43525cb6913f5a5dc6a56befd24057bb6bfce778
Author: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl>
AuthorDate: Sat May 25 23:35:08 2024 +0200

    mcu/stm32: Fix hal_reset_cause for some stm32 devices
    
    This is common rework for hal_reset_cause().
    Mostly Power on reset or Brown out reset were never reported
    due to reset pin having priority over those two.
    
    Watchdog for some MCU was never reported.
---
 hw/mcu/stm/stm32f0xx/src/hal_reset_cause.c | 8 ++++----
 hw/mcu/stm/stm32f1xx/src/hal_reset_cause.c | 9 ++++-----
 hw/mcu/stm/stm32f4xx/src/hal_reset_cause.c | 6 ++++--
 hw/mcu/stm/stm32l4xx/src/hal_reset_cause.c | 9 ++++-----
 hw/mcu/stm/stm32u5xx/src/hal_reset_cause.c | 9 ++++-----
 hw/mcu/stm/stm32wbxx/src/hal_reset_cause.c | 9 ++++-----
 6 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/hw/mcu/stm/stm32f0xx/src/hal_reset_cause.c 
b/hw/mcu/stm/stm32f0xx/src/hal_reset_cause.c
index 1e9325054..9c692bdfc 100644
--- a/hw/mcu/stm/stm32f0xx/src/hal_reset_cause.c
+++ b/hw/mcu/stm/stm32f0xx/src/hal_reset_cause.c
@@ -31,16 +31,16 @@ hal_reset_cause(void)
     }
 
     reg = RCC->CSR;
-    if (reg & RCC_CSR_WWDGRSTF || reg & RCC_CSR_IWDGRSTF) {
+    if (reg & RCC_CSR_PORRSTF) {
+        reason = HAL_RESET_POR;
+    } else if (reg & RCC_CSR_WWDGRSTF || reg & RCC_CSR_IWDGRSTF) {
         reason = HAL_RESET_WATCHDOG;
     } else if (reg & RCC_CSR_SFTRSTF) {
         reason = HAL_RESET_SOFT;
     } else if (reg & RCC_CSR_PINRSTF) {
         reason = HAL_RESET_PIN;
-    } else if (reg & RCC_CSR_PORRSTF) {
-        reason = HAL_RESET_BROWNOUT;
     } else {
-        reason = HAL_RESET_POR;
+        reason = HAL_RESET_OTHER;
     }
     RCC->CSR |= RCC_CSR_RMVF;
     return reason;
diff --git a/hw/mcu/stm/stm32f1xx/src/hal_reset_cause.c 
b/hw/mcu/stm/stm32f1xx/src/hal_reset_cause.c
index e98aeec3a..d6c1343c7 100644
--- a/hw/mcu/stm/stm32f1xx/src/hal_reset_cause.c
+++ b/hw/mcu/stm/stm32f1xx/src/hal_reset_cause.c
@@ -32,17 +32,16 @@ hal_reset_cause(void)
 
     reg = RCC->CSR;
 
-    if (reg & RCC_CSR_WWDGRSTF) {
+    if (reg & (RCC_CSR_PORRSTF)) {
+        reason = HAL_RESET_POR;
+    } else if (reg & (RCC_CSR_WWDGRSTF | RCC_CSR_IWDGRSTF)) {
         reason = HAL_RESET_WATCHDOG;
     } else if (reg & RCC_CSR_SFTRSTF) {
         reason = HAL_RESET_SOFT;
     } else if (reg & RCC_CSR_PINRSTF) {
         reason = HAL_RESET_PIN;
-    } else if (reg & RCC_CSR_LPWRRSTF) {
-        /* For L1xx this is low-power reset */
-        reason = HAL_RESET_BROWNOUT;
     } else {
-        reason = HAL_RESET_POR;
+        reason = HAL_RESET_OTHER;
     }
     RCC->CSR |= RCC_CSR_RMVF;
     return reason;
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_reset_cause.c 
b/hw/mcu/stm/stm32f4xx/src/hal_reset_cause.c
index f5ca0a030..b734d88ff 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_reset_cause.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_reset_cause.c
@@ -32,7 +32,9 @@ hal_reset_cause(void)
 
     reg = RCC->CSR;
 
-    if (reg & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF)) {
+    if (reg & RCC_CSR_PORRSTF) {
+        reason = HAL_RESET_POR;
+    } else if (reg & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF)) {
         reason = HAL_RESET_WATCHDOG;
     } else if (reg & RCC_CSR_SFTRSTF) {
         reason = HAL_RESET_SOFT;
@@ -43,7 +45,7 @@ hal_reset_cause(void)
         reason = HAL_RESET_BROWNOUT;
 #endif
     } else {
-        reason = HAL_RESET_POR;
+        reason = HAL_RESET_OTHER;
     }
     RCC->CSR |= RCC_CSR_RMVF;
     return reason;
diff --git a/hw/mcu/stm/stm32l4xx/src/hal_reset_cause.c 
b/hw/mcu/stm/stm32l4xx/src/hal_reset_cause.c
index a56891699..47586eb29 100644
--- a/hw/mcu/stm/stm32l4xx/src/hal_reset_cause.c
+++ b/hw/mcu/stm/stm32l4xx/src/hal_reset_cause.c
@@ -32,17 +32,16 @@ hal_reset_cause(void)
 
     reg = RCC->CSR;
 
-    if (reg & RCC_CSR_WWDGRSTF) {
+    if (reg & (RCC_CSR_BORRSTF)) {
+        reason = HAL_RESET_BROWNOUT;
+    } else if (reg & (RCC_CSR_WWDGRSTF | RCC_CSR_IWDGRSTF)) {
         reason = HAL_RESET_WATCHDOG;
     } else if (reg & RCC_CSR_SFTRSTF) {
         reason = HAL_RESET_SOFT;
     } else if (reg & RCC_CSR_PINRSTF) {
         reason = HAL_RESET_PIN;
-    } else if (reg & RCC_CSR_LPWRRSTF) {
-        /* For L1xx this is low-power reset */
-        reason = HAL_RESET_BROWNOUT;
     } else {
-        reason = HAL_RESET_POR;
+        reason = HAL_RESET_OTHER;
     }
     RCC->CSR |= RCC_CSR_RMVF;
     return reason;
diff --git a/hw/mcu/stm/stm32u5xx/src/hal_reset_cause.c 
b/hw/mcu/stm/stm32u5xx/src/hal_reset_cause.c
index 6dc6c006e..8c8dd0c78 100644
--- a/hw/mcu/stm/stm32u5xx/src/hal_reset_cause.c
+++ b/hw/mcu/stm/stm32u5xx/src/hal_reset_cause.c
@@ -32,17 +32,16 @@ hal_reset_cause(void)
 
     reg = RCC->CSR;
 
-    if (reg & RCC_CSR_WWDGRSTF) {
+    if (reg & (RCC_CSR_BORRSTF)) {
+        reason = HAL_RESET_BROWNOUT;
+    } else if (reg & (RCC_CSR_WWDGRSTF | RCC_CSR_IWDGRSTF)) {
         reason = HAL_RESET_WATCHDOG;
     } else if (reg & RCC_CSR_SFTRSTF) {
         reason = HAL_RESET_SOFT;
     } else if (reg & RCC_CSR_PINRSTF) {
         reason = HAL_RESET_PIN;
-    } else if (reg & RCC_CSR_LPWRRSTF) {
-        /* For L1xx this is low-power reset */
-        reason = HAL_RESET_BROWNOUT;
     } else {
-        reason = HAL_RESET_POR;
+        reason = HAL_RESET_OTHER;
     }
     RCC->CSR |= RCC_CSR_RMVF;
     return reason;
diff --git a/hw/mcu/stm/stm32wbxx/src/hal_reset_cause.c 
b/hw/mcu/stm/stm32wbxx/src/hal_reset_cause.c
index 5c396f5d1..35c28f5ad 100644
--- a/hw/mcu/stm/stm32wbxx/src/hal_reset_cause.c
+++ b/hw/mcu/stm/stm32wbxx/src/hal_reset_cause.c
@@ -32,17 +32,16 @@ hal_reset_cause(void)
 
     reg = RCC->CSR;
 
-    if (reg & RCC_CSR_WWDGRSTF) {
+    if (reg & (RCC_CSR_BORRSTF)) {
+        reason = HAL_RESET_BROWNOUT;
+    } else if (reg & (RCC_CSR_WWDGRSTF | RCC_CSR_IWDGRSTF)) {
         reason = HAL_RESET_WATCHDOG;
     } else if (reg & RCC_CSR_SFTRSTF) {
         reason = HAL_RESET_SOFT;
     } else if (reg & RCC_CSR_PINRSTF) {
         reason = HAL_RESET_PIN;
-    } else if (reg & RCC_CSR_LPWRRSTF) {
-        /* For WBxx this is low-power reset */
-        reason = HAL_RESET_BROWNOUT;
     } else {
-        reason = HAL_RESET_POR;
+        reason = HAL_RESET_OTHER;
     }
     RCC->CSR |= RCC_CSR_RMVF;
     return reason;

Reply via email to