From 9722dda24af94808b40efb163444a9b08fa24b63 Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Wed, 13 Oct 2021 09:38:47 +0300 Subject: [PATCH] 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);