fix issue with dfu startup on nrf52832, change to adafruit-nrfutil

clean up dfu startup
This commit is contained in:
hathach 2018-08-21 14:14:23 +07:00
parent 3209ff4471
commit 6feea4e069
6 changed files with 19 additions and 160 deletions

View File

@ -42,7 +42,7 @@ MK_DIS_FIRMWARE = "$(SD_NAME) $(SD_VERSION) r$(SD_VER4)"
#****************************************************************************** #******************************************************************************
# Tool configure # Tool configure
#****************************************************************************** #******************************************************************************
NRFUTIL = nrfutil NRFUTIL = adafruit-nrfutil
ifneq ($(JLINK),) ifneq ($(JLINK),)

View File

@ -6,7 +6,7 @@ This repository contains the bootloader for Adafruit nRF52 series and other popu
- Bluefruit Feather nRF52840 Express - Bluefruit Feather nRF52840 Express
- Nordic nRF52840DK PCA10056 - Nordic nRF52840DK PCA10056
This bootloader is meant to use with [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil), a folk of [Nordic nrfutil](https://github.com/NordicSemiconductor/pc-nrfutil). To install [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil), modified version of [Nordic nrfutil](https://github.com/NordicSemiconductor/pc-nrfutil), is required to perform DFU. Install python3 to your system if it is not installed already and run this command to install adafruit-nrfutil from PyPi:
$ pip3 install --user adafruit-nrfutil $ pip3 install --user adafruit-nrfutil

View File

@ -60,9 +60,8 @@ typedef enum
static pstorage_handle_t m_bootsettings_handle; /**< Pstorage handle to use for registration and identifying the bootloader module on subsequent calls to the pstorage module for load and store of bootloader setting in flash. */ static pstorage_handle_t m_bootsettings_handle; /**< Pstorage handle to use for registration and identifying the bootloader module on subsequent calls to the pstorage module for load and store of bootloader setting in flash. */
static bootloader_status_t m_update_status; /**< Current update status for the bootloader module to ensure correct behaviour when updating settings and when update completes. */ static bootloader_status_t m_update_status; /**< Current update status for the bootloader module to ensure correct behaviour when updating settings and when update completes. */
APP_TIMER_DEF( _forced_startup_dfu_timer ); APP_TIMER_DEF( _dfu_startup_timer );
volatile bool forced_startup_dfu_packet_received = false; volatile bool dfu_startup_packet_received = false;
volatile static bool _terminate_startup_dfu = false;
/**@brief Function for handling callbacks from pstorage module. /**@brief Function for handling callbacks from pstorage module.
* *
@ -85,25 +84,19 @@ static void pstorage_callback_handler(pstorage_handle_t * p_handle,
APP_ERROR_CHECK(result); APP_ERROR_CHECK(result);
} }
// Adafruit modifcation
static void terminate_startup_dfu(void * p_event_data, uint16_t event_size)
{
(void) p_event_data;
(void) event_size;
_terminate_startup_dfu = true;
}
/* Terminate the forced DFU mode on startup if no packets is received /* Terminate the forced DFU mode on startup if no packets is received
* by put an terminal handler to scheduler * by put an terminal handler to scheduler
*/ */
static void forced_startup_dfu_timer_handler(void * p_context) static void dfu_startup_timer_handler(void * p_context)
{ {
// No packets are received within timeout, terminal and DFU mode // No packets are received within timeout, terminal and DFU mode
// forced_startup_dfu_packet_received is set by process_dfu_packet() in dfu_transport_serial.c // dfu_startup_packet_received is set by process_dfu_packet() in dfu_transport_serial.c
if (!forced_startup_dfu_packet_received) if (!dfu_startup_packet_received)
{ {
app_sched_event_put(NULL, 0, terminate_startup_dfu); dfu_update_status_t update_status;
update_status.status_code = DFU_TIMEOUT;
bootloader_dfu_update_process(update_status);
} }
} }
@ -142,9 +135,6 @@ static void wait_for_events(void)
// When update has completed or a timeout/reset occured we will return. // When update has completed or a timeout/reset occured we will return.
return; return;
} }
// Forced startup dfu mode timeout without any received packet
if ( _terminate_startup_dfu ) return;
} }
} }
@ -339,11 +329,10 @@ uint32_t bootloader_dfu_start(bool ota, uint32_t timeout_ms)
// timeout_ms > 0 is forced startup DFU // timeout_ms > 0 is forced startup DFU
if ( timeout_ms ) if ( timeout_ms )
{ {
forced_startup_dfu_packet_received = false; dfu_startup_packet_received = false;
_terminate_startup_dfu = false;
(void) app_timer_create(&_forced_startup_dfu_timer, APP_TIMER_MODE_SINGLE_SHOT, forced_startup_dfu_timer_handler); app_timer_create(&_dfu_startup_timer, APP_TIMER_MODE_SINGLE_SHOT, dfu_startup_timer_handler);
app_timer_start(_forced_startup_dfu_timer, APP_TIMER_TICKS(timeout_ms), NULL); app_timer_start(_dfu_startup_timer, APP_TIMER_TICKS(timeout_ms), NULL);
} }
err_code = dfu_transport_serial_update_start(); err_code = dfu_transport_serial_update_start();
@ -351,9 +340,6 @@ uint32_t bootloader_dfu_start(bool ota, uint32_t timeout_ms)
wait_for_events(); wait_for_events();
// Close Serial transport after done
if ( !ota ) dfu_transport_serial_close();
return err_code; return err_code;
} }

View File

@ -198,8 +198,8 @@ static void process_dfu_packet(void * p_event_data, uint16_t event_size)
dfu_update_packet_t * packet; dfu_update_packet_t * packet;
// Adafruit modification for startup dfu // Adafruit modification for startup dfu
extern bool forced_startup_dfu_packet_received; extern bool dfu_startup_packet_received;
forced_startup_dfu_packet_received = true; dfu_startup_packet_received = true;
while (false == DATA_QUEUE_EMPTY()) while (false == DATA_QUEUE_EMPTY())
{ {

View File

@ -61,6 +61,9 @@ uint16_t _pwm_blue_seq[PWM_CHANNEL_NUM] = { PWM_MAXCOUNT/2, 0, 0 , 0 };
void board_init(void) void board_init(void)
{ {
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
// stop WDT if started by application, when jumping from application using BLE DFU // stop WDT if started by application, when jumping from application using BLE DFU
if ( NRF_WDT->RUNSTATUS ) if ( NRF_WDT->RUNSTATUS )
{ {

View File

@ -252,136 +252,6 @@
// </e> // </e>
// <e> PWM_ENABLED - nrf_drv_pwm - PWM peripheral driver
//==========================================================
#ifndef PWM_ENABLED
#define PWM_ENABLED 0
#endif
// <o> PWM_DEFAULT_CONFIG_OUT0_PIN - Out0 pin <0-31>
#ifndef PWM_DEFAULT_CONFIG_OUT0_PIN
#define PWM_DEFAULT_CONFIG_OUT0_PIN 31
#endif
// <o> PWM_DEFAULT_CONFIG_OUT1_PIN - Out1 pin <0-31>
#ifndef PWM_DEFAULT_CONFIG_OUT1_PIN
#define PWM_DEFAULT_CONFIG_OUT1_PIN 31
#endif
// <o> PWM_DEFAULT_CONFIG_OUT2_PIN - Out2 pin <0-31>
#ifndef PWM_DEFAULT_CONFIG_OUT2_PIN
#define PWM_DEFAULT_CONFIG_OUT2_PIN 31
#endif
// <o> PWM_DEFAULT_CONFIG_OUT3_PIN - Out3 pin <0-31>
#ifndef PWM_DEFAULT_CONFIG_OUT3_PIN
#define PWM_DEFAULT_CONFIG_OUT3_PIN 31
#endif
// <o> PWM_DEFAULT_CONFIG_BASE_CLOCK - Base clock
// <0=> 16 MHz
// <1=> 8 MHz
// <2=> 4 MHz
// <3=> 2 MHz
// <4=> 1 MHz
// <5=> 500 kHz
// <6=> 250 kHz
// <7=> 125 kHz
#ifndef PWM_DEFAULT_CONFIG_BASE_CLOCK
#define PWM_DEFAULT_CONFIG_BASE_CLOCK 4
#endif
// <o> PWM_DEFAULT_CONFIG_COUNT_MODE - Count mode
// <0=> Up
// <1=> Up and Down
#ifndef PWM_DEFAULT_CONFIG_COUNT_MODE
#define PWM_DEFAULT_CONFIG_COUNT_MODE 0
#endif
// <o> PWM_DEFAULT_CONFIG_TOP_VALUE - Top value
#ifndef PWM_DEFAULT_CONFIG_TOP_VALUE
#define PWM_DEFAULT_CONFIG_TOP_VALUE 1000
#endif
// <o> PWM_DEFAULT_CONFIG_LOAD_MODE - Load mode
// <0=> Common
// <1=> Grouped
// <2=> Individual
// <3=> Waveform
#ifndef PWM_DEFAULT_CONFIG_LOAD_MODE
#define PWM_DEFAULT_CONFIG_LOAD_MODE 0
#endif
// <o> PWM_DEFAULT_CONFIG_STEP_MODE - Step mode
// <0=> Auto
// <1=> Triggered
#ifndef PWM_DEFAULT_CONFIG_STEP_MODE
#define PWM_DEFAULT_CONFIG_STEP_MODE 0
#endif
// <o> PWM_DEFAULT_CONFIG_IRQ_PRIORITY - Interrupt priority
// <i> Priorities 0,1,4,5 (nRF52) are reserved for SoftDevice
// <0=> 0 (highest)
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7
#ifndef PWM_DEFAULT_CONFIG_IRQ_PRIORITY
#define PWM_DEFAULT_CONFIG_IRQ_PRIORITY 7
#endif
// <q> PWM0_ENABLED - Enable PWM0 instance
#ifndef PWM0_ENABLED
#define PWM0_ENABLED 0
#endif
// <q> PWM1_ENABLED - Enable PWM1 instance
#ifndef PWM1_ENABLED
#define PWM1_ENABLED 0
#endif
// <q> PWM2_ENABLED - Enable PWM2 instance
#ifndef PWM2_ENABLED
#define PWM2_ENABLED 0
#endif
// <q> PWM3_ENABLED - Enable PWM3 instance
#ifndef PWM3_ENABLED
#define PWM3_ENABLED 0
#endif
// </e>
// <e> RTC_ENABLED - nrf_drv_rtc - RTC peripheral driver // <e> RTC_ENABLED - nrf_drv_rtc - RTC peripheral driver
//========================================================== //==========================================================
#ifndef RTC_ENABLED #ifndef RTC_ENABLED