Skip to content

Commit bf4e000

Browse files
committed
remove dfu timeout
1 parent 8b49f47 commit bf4e000

File tree

4 files changed

+51
-128
lines changed

4 files changed

+51
-128
lines changed

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: 3 additions & 81 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

@@ -370,11 +316,7 @@ uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet)
370316
switch (m_dfu_state)
371317
{
372318
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);
376319
m_functions.prepare(m_image_size);
377-
378320
break;
379321

380322
default:
@@ -422,10 +364,6 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet)
422364
return NRF_ERROR_DATA_SIZE;
423365
}
424366

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

431369
if ( is_ota() )
@@ -511,10 +449,6 @@ uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet)
511449
return NRF_ERROR_INVALID_STATE;
512450
}
513451

514-
// Valid peer activity detected. Hence restart the DFU timer.
515-
err_code = dfu_timer_restart();
516-
VERIFY_SUCCESS(err_code);
517-
518452
length = p_packet->params.data_packet.packet_length * sizeof(uint32_t);
519453
if ((m_init_packet_length + length) > sizeof(m_init_packet))
520454
{
@@ -555,16 +489,9 @@ uint32_t dfu_image_validate()
555489
{
556490
m_dfu_state = DFU_STATE_VALIDATE;
557491

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-
}
492+
err_code = dfu_init_postvalidate((uint8_t *)mp_storage_handle_active->block_id, m_image_size);
493+
VERIFY_SUCCESS(err_code);
494+
m_dfu_state = DFU_STATE_WAIT_4_ACTIVATE;
568495
}
569496
break;
570497

@@ -584,11 +511,6 @@ uint32_t dfu_image_activate()
584511
switch (m_dfu_state)
585512
{
586513
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-
592514
err_code = m_functions.activate();
593515
break;
594516

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)