From 9722dda24af94808b40efb163444a9b08fa24b63 Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Wed, 13 Oct 2021 09:38:47 +0300 Subject: [PATCH 1/2] add an interface to read Reset reason --- cores/nRF5/wiring.c | 8 ++++++++ cores/nRF5/wiring.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/cores/nRF5/wiring.c b/cores/nRF5/wiring.c index caa6c316..965a2ed7 100644 --- a/cores/nRF5/wiring.c +++ b/cores/nRF5/wiring.c @@ -30,9 +30,12 @@ nrf_nvic_state_t nrf_nvic_state; // Must match temp register in bootloader #define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0] uint32_t bootloaderVersion = 0; +static uint32_t _reset_reason = 0; void init( void ) { + _reset_reason = NRF_POWER->RESETREAS; + // clear reset reason: can save it for application usage if needed. NRF_POWER->RESETREAS |= NRF_POWER->RESETREAS; @@ -66,6 +69,11 @@ void init( void ) #endif } +uint32_t getResetReason(void) +{ + return _reset_reason; +} + void enterUf2Dfu(void) { NRF_POWER->GPREGRET = DFU_MAGIC_UF2_RESET; diff --git a/cores/nRF5/wiring.h b/cores/nRF5/wiring.h index e1388aed..c49c33f4 100644 --- a/cores/nRF5/wiring.h +++ b/cores/nRF5/wiring.h @@ -29,6 +29,8 @@ extern uint32_t bootloaderVersion; extern void init(void); +uint32_t getResetReason(void); + void enterSerialDfu(void); void enterOTADfu(void); void enterUf2Dfu(void); From 2cfc196bdca0de36836ae195568d9b1b8d015472 Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Wed, 13 Oct 2021 18:26:02 +0000 Subject: [PATCH 2/2] the function name change upon request by the repo maintainer --- cores/nRF5/wiring.c | 2 +- cores/nRF5/wiring.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/nRF5/wiring.c b/cores/nRF5/wiring.c index 965a2ed7..a18e7fc5 100644 --- a/cores/nRF5/wiring.c +++ b/cores/nRF5/wiring.c @@ -69,7 +69,7 @@ void init( void ) #endif } -uint32_t getResetReason(void) +uint32_t readResetReason(void) { return _reset_reason; } diff --git a/cores/nRF5/wiring.h b/cores/nRF5/wiring.h index c49c33f4..4a3682c6 100644 --- a/cores/nRF5/wiring.h +++ b/cores/nRF5/wiring.h @@ -29,7 +29,7 @@ extern uint32_t bootloaderVersion; extern void init(void); -uint32_t getResetReason(void); +uint32_t readResetReason(void); void enterSerialDfu(void); void enterOTADfu(void);