Allow for single-tap reset when requested

This commit is contained in:
Michal Moskal 2020-02-14 12:14:33 -08:00
parent 563f15158d
commit fe5cbd8183

View File

@ -61,6 +61,7 @@
#include "nrf_error.h" #include "nrf_error.h"
#include "boards.h" #include "boards.h"
#include "uf2/uf2.h"
#include "pstorage_platform.h" #include "pstorage_platform.h"
#include "nrf_mbr.h" #include "nrf_mbr.h"
@ -112,6 +113,8 @@ void usb_teardown(void);
#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0] #define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0]
#define DFU_SERIAL_STARTUP_INTERVAL 1000 #define DFU_SERIAL_STARTUP_INTERVAL 1000
#define APP_ASKS_FOR_SINGLE_TAP_RESET() (*((uint32_t*)(USER_FLASH_START + 0x200)) == 0x87eeb07c)
// These value must be the same with one in dfu_transport_ble.c // These value must be the same with one in dfu_transport_ble.c
#define BLEGAP_EVENT_LENGTH 6 #define BLEGAP_EVENT_LENGTH 6
#define BLEGATT_ATT_MTU_MAX 247 #define BLEGATT_ATT_MTU_MAX 247
@ -200,6 +203,9 @@ int main(void)
bool const valid_app = bootloader_app_is_valid(DFU_BANK_0_REGION_START); bool const valid_app = bootloader_app_is_valid(DFU_BANK_0_REGION_START);
bool const just_start_app = valid_app && !dfu_start && (*dbl_reset_mem) == DFU_DBL_RESET_APP; bool const just_start_app = valid_app && !dfu_start && (*dbl_reset_mem) == DFU_DBL_RESET_APP;
if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET())
dfu_start = 1;
// App mode: register 1st reset and DFU startup (nrf52832) // App mode: register 1st reset and DFU startup (nrf52832)
if ( ! (just_start_app || dfu_start || !valid_app) ) if ( ! (just_start_app || dfu_start || !valid_app) )
{ {
@ -220,7 +226,10 @@ int main(void)
#endif #endif
} }
(*dbl_reset_mem) = 0; if (APP_ASKS_FOR_SINGLE_TAP_RESET())
(*dbl_reset_mem) = DFU_DBL_RESET_APP;
else
(*dbl_reset_mem) = 0;
if ( dfu_start || !valid_app ) if ( dfu_start || !valid_app )
{ {
@ -263,6 +272,9 @@ int main(void)
// MBR must be init before start application // MBR must be init before start application
if ( !sd_inited ) softdev_mbr_init(); if ( !sd_inited ) softdev_mbr_init();
// clear in case we kept DFU_DBL_RESET_APP there
(*dbl_reset_mem) = 0;
// Select a bank region to use as application region. // Select a bank region to use as application region.
// @note: Only applications running from DFU_BANK_0_REGION_START is supported. // @note: Only applications running from DFU_BANK_0_REGION_START is supported.
bootloader_app_start(DFU_BANK_0_REGION_START); bootloader_app_start(DFU_BANK_0_REGION_START);