Skip to content

Commit 35e8ad9

Browse files
authored
Merge pull request #166 from adafruit/remove-timeout
remove dfu timeout
2 parents 8b49f47 + 73d5190 commit 35e8ad9

File tree

7 files changed

+70
-163
lines changed

7 files changed

+70
-163
lines changed

.github/workflows/githubci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ jobs:
2525
run: |
2626
pip3 install adafruit-nrfutil uritemplate requests intelhex
2727
npm install --global xpm
28-
xpm install --global @xpack-dev-tools/arm-none-eabi-gcc@latest
28+
# 9.3.1-1.2.1 is xpack modified version which significantly increased compiled size to 6-7KB and cause flash overflow.
29+
# Skip this version for now, we will try again with next official release from ARM
30+
xpm install --global @xpack-dev-tools/[email protected]
2931
echo "::add-path::`echo $HOME/opt/xPacks/@xpack-dev-tools/arm-none-eabi-gcc/*/.content/bin`"
3032
3133
- name: Build

Makefile

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ IPATH += $(SD_PATH)/$(SD_FILENAME)_API/include/nrf52
232232
ifeq ($(DEBUG), 1)
233233
RTT_SRC = lib/SEGGER_RTT
234234

235-
CFLAGS += -ggdb -DCFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
235+
CFLAGS += -DCFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
236236
IPATH += $(RTT_SRC)/RTT
237237
C_SRC += $(RTT_SRC)/RTT/SEGGER_RTT.c
238238
endif
@@ -263,7 +263,8 @@ CFLAGS += \
263263
-Wsign-compare \
264264
-Wmissing-format-attribute \
265265
-Wno-endif-labels \
266-
-Wunreachable-code
266+
-Wunreachable-code \
267+
-ggdb
267268

268269
# Suppress warning caused by SDK
269270
CFLAGS += -Wno-unused-parameter -Wno-expansion-to-defined
@@ -306,7 +307,6 @@ LIBS += -lm -lc
306307
#------------------------------------------------------------------------------
307308
ASFLAGS += $(CFLAGS)
308309

309-
310310
#function for removing duplicates in a list
311311
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
312312

@@ -329,16 +329,6 @@ INC_PATHS = $(addprefix -I,$(IPATH))
329329
# BUILD TARGETS
330330
#------------------------------------------------------------------------------
331331

332-
# Verbose mode (V=). 0: default, 1: print out CFLAG, LDFLAG 2: print all compile command
333-
ifeq ("$(V)","1")
334-
$(info CFLAGS $(CFLAGS))
335-
$(info )
336-
$(info LDFLAGS $(LDFLAGS))
337-
$(info )
338-
$(info ASFLAGS $(ASFLAGS))
339-
$(info )
340-
endif
341-
342332
.PHONY: all clean flash dfu-flash sd gdbflash gdb
343333

344334
# default target to build

lib/sdk11/components/libraries/bootloader_dfu/bootloader.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ static void dfu_startup_timer_handler(void * p_context)
8787
}
8888
#endif
8989

90-
// No packets are received within timeout, terminal and DFU mode
90+
// nRF52832 forced DFU on startup
91+
// No packets are received within timeout, exit DFU mode
9192
// dfu_startup_packet_received is set by process_dfu_packet() in dfu_transport_serial.c
9293
if (!dfu_startup_packet_received)
9394
{
@@ -336,7 +337,9 @@ uint32_t bootloader_dfu_start(bool ota, uint32_t timeout_ms, bool cancel_timeout
336337
err_code = dfu_transport_ble_update_start();
337338
}else
338339
{
339-
// timeout_ms > 0 is forced startup DFU
340+
// DFU mode with timeout can be
341+
// - Forced startup DFU for nRF52832 or
342+
// - Makecode single tap reset but no enumerated (battery power)
340343
if ( timeout_ms )
341344
{
342345
dfu_startup_packet_received = false;

lib/sdk11/components/libraries/bootloader_dfu/dfu_bank_internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ typedef enum
4040
DFU_STATE_WAIT_4_ACTIVATE /**< State for: waiting for dfu_image_activate(). */
4141
} dfu_state_t;
4242

43-
#define DFU_TIMEOUT_INTERVAL APP_TIMER_TICKS(300000) /**< DFU timeout interval in units of timer ticks. */
44-
4543
#define IS_UPDATING_SD(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_SD) /**< Macro for determining if a SoftDevice update is ongoing. */
4644
#define IS_UPDATING_BL(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_BL) /**< Macro for determining if a Bootloader update is ongoing. */
4745
#define IS_UPDATING_APP(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_APP) /**< Macro for determining if a Application update is ongoing. */

lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c

Lines changed: 8 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ static uint8_t m_init_packet[64]; /**< Init packet
3535
static uint8_t m_init_packet_length; /**< Length of init packet received. */
3636
static uint16_t m_image_crc; /**< Calculated CRC of the image received. */
3737

38-
APP_TIMER_DEF(m_dfu_timer_id); /**< Application timer id. */
39-
static bool m_dfu_timed_out = false; /**< Boolean flag value for tracking DFU timer timeout state. */
40-
4138
static pstorage_handle_t m_storage_handle_app; /**< Pstorage handle for the application area (bank 0). Bank used when updating a SoftDevice w/wo bootloader. Handle also used when swapping received application from bank 1 to bank 0. */
4239
static pstorage_handle_t * mp_storage_handle_active; /**< Pointer to the pstorage handle for the active bank for receiving of data packets. */
4340

@@ -83,47 +80,6 @@ static void pstorage_callback_handler(pstorage_handle_t * p_handle,
8380
APP_ERROR_CHECK(result);
8481
}
8582

86-
87-
/**@brief Function for handling the DFU timeout.
88-
*
89-
* @param[in] p_context The timeout context.
90-
*/
91-
static void dfu_timeout_handler(void * p_context)
92-
{
93-
UNUSED_PARAMETER(p_context);
94-
dfu_update_status_t update_status;
95-
96-
m_dfu_timed_out = true;
97-
update_status.status_code = DFU_TIMEOUT;
98-
99-
bootloader_dfu_update_process(update_status);
100-
}
101-
102-
103-
/**@brief Function for restarting the DFU Timer.
104-
*
105-
* @details This function will stop and restart the DFU timer. This function will be called by the
106-
* functions handling any DFU packet received from the peer that is transferring a firmware
107-
* image.
108-
*/
109-
static uint32_t dfu_timer_restart(void)
110-
{
111-
if (m_dfu_timed_out)
112-
{
113-
// The DFU timer had already timed out.
114-
return NRF_ERROR_INVALID_STATE;
115-
}
116-
117-
uint32_t err_code = app_timer_stop(m_dfu_timer_id);
118-
APP_ERROR_CHECK(err_code);
119-
120-
err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL);
121-
APP_ERROR_CHECK(err_code);
122-
123-
return err_code;
124-
}
125-
126-
12783
/**@brief Function for preparing of flash before receiving SoftDevice image.
12884
*
12985
* @details This function will erase current application area to ensure sufficient amount of
@@ -289,16 +245,6 @@ uint32_t dfu_init(void)
289245

290246
m_storage_handle_app.block_id = DFU_BANK_0_REGION_START;
291247

292-
// Create the timer to monitor the activity by the peer doing the firmware update.
293-
err_code = app_timer_create(&m_dfu_timer_id,
294-
APP_TIMER_MODE_SINGLE_SHOT,
295-
dfu_timeout_handler);
296-
APP_ERROR_CHECK(err_code);
297-
298-
// Start the DFU timer.
299-
err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL);
300-
APP_ERROR_CHECK(err_code);
301-
302248
m_data_received = 0;
303249
m_dfu_state = DFU_STATE_IDLE;
304250

@@ -314,8 +260,6 @@ void dfu_register_callback(dfu_callback_t callback_handler)
314260

315261
uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet)
316262
{
317-
uint32_t err_code;
318-
319263
m_start_packet = *(p_packet->params.start_packet);
320264

321265
// Check that the requested update procedure is supported.
@@ -367,22 +311,11 @@ uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet)
367311
m_functions.activate = dfu_activate_app;
368312
}
369313

370-
switch (m_dfu_state)
371-
{
372-
case DFU_STATE_IDLE:
373-
// Valid peer activity detected. Hence restart the DFU timer.
374-
err_code = dfu_timer_restart();
375-
VERIFY_SUCCESS(err_code);
376-
m_functions.prepare(m_image_size);
314+
if ( DFU_STATE_IDLE != m_dfu_state ) return NRF_ERROR_INVALID_STATE;
377315

378-
break;
316+
m_functions.prepare(m_image_size);
379317

380-
default:
381-
err_code = NRF_ERROR_INVALID_STATE;
382-
break;
383-
}
384-
385-
return err_code;
318+
return NRF_SUCCESS;
386319
}
387320

388321

@@ -422,10 +355,6 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet)
422355
return NRF_ERROR_DATA_SIZE;
423356
}
424357

425-
// Valid peer activity detected. Hence restart the DFU timer.
426-
err_code = dfu_timer_restart();
427-
VERIFY_SUCCESS(err_code);
428-
429358
p_data = (uint32_t *)p_packet->params.data_packet.p_data_packet;
430359

431360
if ( is_ota() )
@@ -493,7 +422,6 @@ uint32_t dfu_init_pkt_complete(void)
493422

494423
uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet)
495424
{
496-
uint32_t err_code = NRF_SUCCESS;
497425
uint32_t length;
498426

499427
switch (m_dfu_state)
@@ -511,10 +439,6 @@ uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet)
511439
return NRF_ERROR_INVALID_STATE;
512440
}
513441

514-
// Valid peer activity detected. Hence restart the DFU timer.
515-
err_code = dfu_timer_restart();
516-
VERIFY_SUCCESS(err_code);
517-
518442
length = p_packet->params.data_packet.packet_length * sizeof(uint32_t);
519443
if ((m_init_packet_length + length) > sizeof(m_init_packet))
520444
{
@@ -529,11 +453,10 @@ uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet)
529453

530454
default:
531455
// Either the start packet was not received or dfu_init function was not called before.
532-
err_code = NRF_ERROR_INVALID_STATE;
533-
break;
456+
return NRF_ERROR_INVALID_STATE;
534457
}
535458

536-
return err_code;
459+
return NRF_SUCCESS;
537460
}
538461

539462

@@ -555,16 +478,9 @@ uint32_t dfu_image_validate()
555478
{
556479
m_dfu_state = DFU_STATE_VALIDATE;
557480

558-
// Valid peer activity detected. Hence restart the DFU timer.
559-
err_code = dfu_timer_restart();
560-
if (err_code == NRF_SUCCESS)
561-
{
562-
err_code = dfu_init_postvalidate((uint8_t *)mp_storage_handle_active->block_id,
563-
m_image_size);
564-
VERIFY_SUCCESS(err_code);
565-
566-
m_dfu_state = DFU_STATE_WAIT_4_ACTIVATE;
567-
}
481+
err_code = dfu_init_postvalidate((uint8_t *)mp_storage_handle_active->block_id, m_image_size);
482+
VERIFY_SUCCESS(err_code);
483+
m_dfu_state = DFU_STATE_WAIT_4_ACTIVATE;
568484
}
569485
break;
570486

@@ -584,11 +500,6 @@ uint32_t dfu_image_activate()
584500
switch (m_dfu_state)
585501
{
586502
case DFU_STATE_WAIT_4_ACTIVATE:
587-
588-
// Stop the DFU Timer because the peer activity need not be monitored any longer.
589-
err_code = app_timer_stop(m_dfu_timer_id);
590-
APP_ERROR_CHECK(err_code);
591-
592503
err_code = m_functions.activate();
593504
break;
594505

lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_serial.c

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -201,55 +201,55 @@ static void process_dfu_packet(void * p_event_data, uint16_t event_size)
201201
extern bool dfu_startup_packet_received;
202202
dfu_startup_packet_received = true;
203203

204-
while (false == DATA_QUEUE_EMPTY())
204+
while (false == DATA_QUEUE_EMPTY())
205+
{
206+
// Fetch the element to be processed.
207+
for (index = 0; index < MAX_BUFFERS ; index++)
205208
{
206-
// Fetch the element to be processed.
207-
for (index = 0; index < MAX_BUFFERS ; index++)
209+
packet = &m_data_queue.data_packet[index];
210+
if (INVALID_PACKET != packet->packet_type)
208211
{
209-
packet = &m_data_queue.data_packet[index];
210-
if (INVALID_PACKET != packet->packet_type)
212+
switch (DATA_QUEUE_ELEMENT_GET_PTYPE(index))
211213
{
212-
switch (DATA_QUEUE_ELEMENT_GET_PTYPE(index))
213-
{
214-
case DATA_PACKET:
215-
(void)dfu_data_pkt_handle(packet);
216-
break;
217-
218-
case START_PACKET:
219-
packet->params.start_packet =
220-
(dfu_start_packet_t*)packet->params.data_packet.p_data_packet;
221-
retval = dfu_start_pkt_handle(packet);
222-
APP_ERROR_CHECK(retval);
223-
break;
224-
225-
case INIT_PACKET:
226-
(void)dfu_init_pkt_handle(packet);
227-
retval = dfu_init_pkt_complete();
228-
APP_ERROR_CHECK(retval);
229-
230-
led_state(STATE_WRITING_STARTED);
231-
break;
232-
233-
case STOP_DATA_PACKET:
234-
(void)dfu_image_validate();
235-
(void)dfu_image_activate();
236-
237-
led_state(STATE_WRITING_FINISHED);
238-
239-
// Break the loop by returning.
240-
return;
241-
242-
default:
243-
// No implementation needed.
244-
break;
245-
}
246-
247-
// Free the processed element.
248-
retval = data_queue_element_free(index);
249-
APP_ERROR_CHECK(retval);
214+
case DATA_PACKET:
215+
(void)dfu_data_pkt_handle(packet);
216+
break;
217+
218+
case START_PACKET:
219+
packet->params.start_packet =
220+
(dfu_start_packet_t*)packet->params.data_packet.p_data_packet;
221+
retval = dfu_start_pkt_handle(packet);
222+
APP_ERROR_CHECK(retval);
223+
break;
224+
225+
case INIT_PACKET:
226+
(void)dfu_init_pkt_handle(packet);
227+
retval = dfu_init_pkt_complete();
228+
APP_ERROR_CHECK(retval);
229+
230+
led_state(STATE_WRITING_STARTED);
231+
break;
232+
233+
case STOP_DATA_PACKET:
234+
(void)dfu_image_validate();
235+
(void)dfu_image_activate();
236+
237+
led_state(STATE_WRITING_FINISHED);
238+
239+
// Break the loop by returning.
240+
return;
241+
242+
default:
243+
// No implementation needed.
244+
break;
250245
}
246+
247+
// Free the processed element.
248+
retval = data_queue_element_free(index);
249+
APP_ERROR_CHECK(retval);
251250
}
252251
}
252+
}
253253
}
254254

255255

0 commit comments

Comments
 (0)