@@ -238,14 +238,15 @@ static void check_dfu_mode(void)
238238 _ota_dfu = (gpregret == DFU_MAGIC_OTA_APPJUM ) || (gpregret == DFU_MAGIC_OTA_RESET );
239239
240240 // Serial only mode
241- bool serial_only_dfu = (gpregret == DFU_MAGIC_SERIAL_ONLY_RESET );
242- bool uf2_dfu = (gpregret == DFU_MAGIC_UF2_RESET );
241+ bool const serial_only_dfu = (gpregret == DFU_MAGIC_SERIAL_ONLY_RESET );
242+ bool const uf2_dfu = (gpregret == DFU_MAGIC_UF2_RESET );
243+ bool const dfu_skip = (gpregret == DFU_MAGIC_SKIP );
244+
245+ bool const reason_reset_pin = (NRF_POWER -> RESETREAS & POWER_RESETREAS_RESETPIN_Msk ) ? true : false;
243246
244247 // start either serial, uf2 or ble
245248 bool dfu_start = _ota_dfu || serial_only_dfu || uf2_dfu ||
246- (((* dbl_reset_mem ) == DFU_DBL_RESET_MAGIC ) && (NRF_POWER -> RESETREAS & POWER_RESETREAS_RESETPIN_Msk ));
247-
248- bool const dfu_skip = (gpregret == DFU_MAGIC_SKIP );
249+ (((* dbl_reset_mem ) == DFU_DBL_RESET_MAGIC ) && reason_reset_pin );
249250
250251 // Clear GPREGRET if it is our values
251252 if (dfu_start || dfu_skip ) NRF_POWER -> GPREGRET = 0 ;
@@ -265,12 +266,9 @@ static void check_dfu_mode(void)
265266
266267 if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET ()) dfu_start = 1 ;
267268
268- // App mode: register 1st reset or DFU startup for nrf52832
269+ // App mode: Double Reset detection or DFU startup for nrf52832
269270 if ( ! (just_start_app || dfu_start || !valid_app ) )
270271 {
271- // Register our first reset for double reset detection
272- (* dbl_reset_mem ) = DFU_DBL_RESET_MAGIC ;
273-
274272#ifdef NRF52832_XXAA
275273 /* Even DFU is not active, we still force an 1000 ms dfu serial mode when startup
276274 * to support auto programming from Arduino IDE
@@ -279,8 +277,15 @@ static void check_dfu_mode(void)
279277 */
280278 bootloader_dfu_start (false, DFU_SERIAL_STARTUP_INTERVAL , false);
281279#else
282- // if RST is pressed during this delay (double reset)--> if will enter dfu
283- NRFX_DELAY_MS (DFU_DBL_RESET_DELAY );
280+ // Note: RESETREAS is not clear by bootloader, it should be cleared by application upon init()
281+ if (reason_reset_pin )
282+ {
283+ // Register our first reset for double reset detection
284+ (* dbl_reset_mem ) = DFU_DBL_RESET_MAGIC ;
285+
286+ // if RST is pressed during this delay (double reset)--> if will enter dfu
287+ NRFX_DELAY_MS (DFU_DBL_RESET_DELAY );
288+ }
284289#endif
285290 }
286291
0 commit comments