diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-03-06 21:51:55 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-03-06 21:51:55 +0100 |
commit | 5b108d8cf0ee6a0783830930d22c6e609dec9734 (patch) | |
tree | 8efea73b842c29c2744a8f223ca381794d93dcd9 /firmware/apps | |
parent | 96065cacd7c59e3d72d6d3cfae4f6b06654511f0 (diff) |
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.
Diffstat (limited to 'firmware/apps')
-rw-r--r-- | firmware/apps/dfu/main.c | 7 |
1 files changed, 6 insertions, 1 deletions
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(); |