From 5b108d8cf0ee6a0783830930d22c6e609dec9734 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 6 Mar 2017 21:51:55 +0100 Subject: DFU: initialize g_dfu during real power up At power-up we need to initialize g_dfu once, to ensure a consistent state. Afterwards we want to keep it across (software) reset, but on power-up the memory would otherwise be filled with random data, causing issues with detection of DFU/Runtime switching. --- firmware/apps/dfu/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'firmware/apps') diff --git a/firmware/apps/dfu/main.c b/firmware/apps/dfu/main.c index 6cdad20..a99c3fd 100644 --- a/firmware/apps/dfu/main.c +++ b/firmware/apps/dfu/main.c @@ -176,6 +176,7 @@ extern int main(void) { uint8_t isUsbConnected = 0; unsigned int i = 0; + uint32_t reset_cause = (RSTC->RSTC_SR & RSTC_SR_RSTTYP_Msk) >> RSTC_SR_RSTTYP_Pos; led_init(); led_blink(LED_GREEN, BLINK_3O_30F); @@ -201,7 +202,11 @@ extern int main(void) TRACE_INFO("Serial Nr. %08x-%08x-%08x-%08x\n\r", g_unique_id[0], g_unique_id[1], g_unique_id[2], g_unique_id[3]); - TRACE_INFO("Reset Cause: 0x%x\n\r", (RSTC->RSTC_SR & RSTC_SR_RSTTYP_Msk) >> RSTC_SR_RSTTYP_Pos); + TRACE_INFO("Reset Cause: 0x%x\n\r", reset_cause); + + /* clear g_dfu on power-up reset */ + if (reset_cause == 0) + memset(g_dfu, 0, sizeof(*g_dfu)); board_main_top(); -- cgit v1.2.3