bootloader with startup dfu mode in 1 second
This commit is contained in:
1 parent
c410b546ef
commit
27dd9912dc
4 files changed
+64
-5
No files matched your search
+47
-1
@@ -27,6 +27,10 @@
|
||||
#include "nrf_delay.h"
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include "app_timer_appsh.h"
|
||||
|
||||
#define APP_TIMER_PRESCALER 0
|
||||
|
||||
#define IRQ_ENABLED 0x01 /**< Field identifying if an interrupt is enabled. */
|
||||
#define MAX_NUMBER_INTERRUPTS 32 /**< Maximum number of interrupts available. */
|
||||
|
||||
@@ -44,9 +48,13 @@ 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 bootloader_status_t m_update_status; /**< Current update status for the bootloader module to ensure correct behaviour when updating settings and when update completes. */
|
||||
|
||||
// Adafruit modification for dual transports
|
||||
// Adafruit modification for dual transports and forced startup DFU
|
||||
extern bool is_ota(void);
|
||||
|
||||
APP_TIMER_DEF( _forced_startup_dfu_timer );
|
||||
volatile bool forced_startup_dfu_packet_received = false;
|
||||
volatile static bool _terminate_startup_dfu = false;
|
||||
|
||||
/**@brief Function for handling callbacks from pstorage module.
|
||||
*
|
||||
* @details Handles pstorage results for clear and storage operation. For detailed description of
|
||||
@@ -68,6 +76,27 @@ static void pstorage_callback_handler(pstorage_handle_t * p_handle,
|
||||
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
|
||||
* by put an terminal handler to scheduler
|
||||
*/
|
||||
static void forced_startup_dfu_timer_handler(void * p_context)
|
||||
{
|
||||
// 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
|
||||
if (!forced_startup_dfu_packet_received)
|
||||
{
|
||||
app_sched_event_put(NULL, 0, terminate_startup_dfu);
|
||||
}
|
||||
}
|
||||
|
||||
/**@brief Function for waiting for events.
|
||||
*
|
||||
@@ -95,6 +124,13 @@ static void wait_for_events(void)
|
||||
// When update has completed or a timeout/reset occured we will return.
|
||||
return;
|
||||
}
|
||||
|
||||
// Forced startup dfu mode timeout without any received packet
|
||||
if (_terminate_startup_dfu)
|
||||
{
|
||||
dfu_transport_serial_close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,6 +315,16 @@ uint32_t bootloader_dfu_start(bool ota, uint32_t timeout_ms)
|
||||
err_code = dfu_transport_ble_update_start();
|
||||
}else
|
||||
{
|
||||
// timeout_ms > 0 is forced startup DFU
|
||||
if ( timeout_ms )
|
||||
{
|
||||
forced_startup_dfu_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_start(_forced_startup_dfu_timer, APP_TIMER_TICKS(timeout_ms, APP_TIMER_PRESCALER), NULL);
|
||||
}
|
||||
|
||||
err_code = dfu_transport_serial_update_start();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@
|
||||
#define DFU_SERVICE_HANDLE 0x000C /**< Handle of DFU service when DFU service is first service initialized. */
|
||||
#define BLE_HANDLE_MAX 0xFFFF /**< Max handle value is BLE. */
|
||||
|
||||
#define DEVICE_NAME "Bluefruit" /**< Name of device. Will be included in the advertising data. */
|
||||
#define DEVICE_NAME "AdaDfu" // limit of 8 chars /**< Name of device. Will be included in the advertising data. */
|
||||
//#define MANUFACTURER_NAME "NordicSemiconductor" /**< Manufacturer. Will be passed to Device Information Service. */
|
||||
|
||||
#define MIN_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(15, UNIT_1_25_MS)) /**< Minimum acceptable connection interval (11.25 milliseconds). */
|
||||
|
||||
+4
@@ -196,6 +196,10 @@ static void process_dfu_packet(void * p_event_data, uint16_t event_size)
|
||||
uint32_t index;
|
||||
dfu_update_packet_t * packet;
|
||||
|
||||
// Adafruit modification for startup dfu
|
||||
extern bool forced_startup_dfu_packet_received;
|
||||
forced_startup_dfu_packet_received = true;
|
||||
|
||||
while (false == DATA_QUEUE_EMPTY())
|
||||
{
|
||||
// Fetch the element to be processed.
|
||||
|
||||
@@ -70,8 +70,10 @@
|
||||
#define led_on(pin) nrf_gpio_pin_write(pin, LED_STATE_ON)
|
||||
#define led_off(pin) nrf_gpio_pin_write(pin, 1-LED_STATE_ON)
|
||||
|
||||
#define BOOTLOADER_STARTUP_DFU_INTERVAL 1000
|
||||
|
||||
#define BOOTLOADER_BUTTON 20 /**< Button used to enter SW update mode. */
|
||||
#define BOOTLOADER_OTA_BUTTON 13 // Button used in addition to DFU button, to force OTA DFU
|
||||
#define BOOTLOADER_OTA_BUTTON 22 // Button used in addition to DFU button, to force OTA DFU
|
||||
|
||||
#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
|
||||
#define APP_TIMER_OP_QUEUE_SIZE 4 /**< Size of timer operation queues. */
|
||||
@@ -123,13 +125,20 @@ static void leds_init(void)
|
||||
|
||||
static void blinky_handler(void * p_context)
|
||||
{
|
||||
static uint8_t state = 0;
|
||||
static uint32_t count = 0;
|
||||
|
||||
count++;
|
||||
|
||||
// if not uploading then blink slow (interval/2)
|
||||
if ( !isDfuUploading && count%2 ) return;
|
||||
|
||||
nrf_gpio_pin_toggle(LED_STATUS_PIN);
|
||||
state = 1-state;
|
||||
|
||||
nrf_gpio_pin_write(LED_STATUS_PIN, state);
|
||||
|
||||
if (is_ota()) nrf_gpio_pin_write(LED_CONNECTION_PIN, state);
|
||||
|
||||
|
||||
// Feed Watchdog just in case application enable it (WDT last through a soft reboot to bootloader)
|
||||
if ( NRF_WDT->RUNSTATUS ) NRF_WDT->RR[0] = WDT_RR_RR_Reload;
|
||||
@@ -296,7 +305,7 @@ int main(void)
|
||||
* Even DFU is not active, we still force an 1000 ms dfu serial mode when startup
|
||||
* to support auto programming from Arduino IDE
|
||||
*/
|
||||
(void) bootloader_dfu_start(false, 1000);
|
||||
(void) bootloader_dfu_start(false, BOOTLOADER_STARTUP_DFU_INTERVAL);
|
||||
}
|
||||
|
||||
app_timer_stop(blinky_timer_id);
|
||||
|
||||
Reference in new issue
Block a user