Skip to content

Commit fe5cbd8

Browse files
committed
Allow for single-tap reset when requested
1 parent 563f151 commit fe5cbd8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/main.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "nrf_error.h"
6262

6363
#include "boards.h"
64+
#include "uf2/uf2.h"
6465

6566
#include "pstorage_platform.h"
6667
#include "nrf_mbr.h"
@@ -112,6 +113,8 @@ void usb_teardown(void);
112113
#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0]
113114
#define DFU_SERIAL_STARTUP_INTERVAL 1000
114115

116+
#define APP_ASKS_FOR_SINGLE_TAP_RESET() (*((uint32_t*)(USER_FLASH_START + 0x200)) == 0x87eeb07c)
117+
115118
// These value must be the same with one in dfu_transport_ble.c
116119
#define BLEGAP_EVENT_LENGTH 6
117120
#define BLEGATT_ATT_MTU_MAX 247
@@ -200,6 +203,9 @@ int main(void)
200203
bool const valid_app = bootloader_app_is_valid(DFU_BANK_0_REGION_START);
201204
bool const just_start_app = valid_app && !dfu_start && (*dbl_reset_mem) == DFU_DBL_RESET_APP;
202205

206+
if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET())
207+
dfu_start = 1;
208+
203209
// App mode: register 1st reset and DFU startup (nrf52832)
204210
if ( ! (just_start_app || dfu_start || !valid_app) )
205211
{
@@ -220,7 +226,10 @@ int main(void)
220226
#endif
221227
}
222228

223-
(*dbl_reset_mem) = 0;
229+
if (APP_ASKS_FOR_SINGLE_TAP_RESET())
230+
(*dbl_reset_mem) = DFU_DBL_RESET_APP;
231+
else
232+
(*dbl_reset_mem) = 0;
224233

225234
if ( dfu_start || !valid_app )
226235
{
@@ -263,6 +272,9 @@ int main(void)
263272
// MBR must be init before start application
264273
if ( !sd_inited ) softdev_mbr_init();
265274

275+
// clear in case we kept DFU_DBL_RESET_APP there
276+
(*dbl_reset_mem) = 0;
277+
266278
// Select a bank region to use as application region.
267279
// @note: Only applications running from DFU_BANK_0_REGION_START is supported.
268280
bootloader_app_start(DFU_BANK_0_REGION_START);

0 commit comments

Comments
 (0)