From e5809a06cd00d0e91338142143b5b163fd4c8bed Mon Sep 17 00:00:00 2001 From: Konrad Grucel Date: Mon, 25 Nov 2024 15:46:17 +0100 Subject: [PATCH] [nrf toup] Saving boot reason on nRF54h20 -Use NRF_RESETINFO register to get boot reason Signed-off-by: Konrad Grucel --- .../Zephyr/DiagnosticDataProviderImpl.cpp | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/platform/Zephyr/DiagnosticDataProviderImpl.cpp b/src/platform/Zephyr/DiagnosticDataProviderImpl.cpp index 3c0a106aea..b16504a907 100644 --- a/src/platform/Zephyr/DiagnosticDataProviderImpl.cpp +++ b/src/platform/Zephyr/DiagnosticDataProviderImpl.cpp @@ -52,6 +52,10 @@ const size_t kMaxHeapSize = CONFIG_SRAM_BASE_ADDRESS + KB(CONFIG_SRAM_SIZE) - PO #endif +#ifdef CONFIG_SOC_SERIES_NRF54HX +#include +#endif + namespace chip { namespace DeviceLayer { @@ -59,9 +63,42 @@ namespace { BootReasonType DetermineBootReason() { -#ifdef CONFIG_HWINFO +#if defined(CONFIG_SOC_SERIES_NRF54HX) || defined(CONFIG_HWINFO) uint32_t reason; +#endif + +#ifdef CONFIG_SOC_SERIES_NRF54HX + reason = nrf_resetinfo_resetreas_global_get(NRF_RESETINFO); + + if (reason == RESETINFO_RESETREAS_GLOBAL_ResetValue) + { + return BootReasonType::kSoftwareReset; + } + + if (reason & RESETINFO_RESETREAS_GLOBAL_RESETPORONLY_Msk) + { + return BootReasonType::kBrownOutReset; + } + if (reason & RESETINFO_RESETREAS_GLOBAL_DOG_Msk) + { + return BootReasonType::kHardwareWatchdogReset; + } + + if ((reason & (RESETINFO_RESETREAS_GLOBAL_RESETPIN_Msk | RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk)) == + (RESETINFO_RESETREAS_GLOBAL_RESETPIN_Msk | RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk)) + { + return BootReasonType::kPowerOnReboot; + } + + if ((reason & (RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk | RESETINFO_RESETREAS_GLOBAL_SECSREQ_Msk)) == + (RESETINFO_RESETREAS_GLOBAL_RESETPOR_Msk | RESETINFO_RESETREAS_GLOBAL_SECSREQ_Msk)) + { + return BootReasonType::kSoftwareUpdateCompleted; + } +#endif + +#ifdef CONFIG_HWINFO if (hwinfo_get_reset_cause(&reason) != 0) { return BootReasonType::kUnspecified;