From 6b38297e20eb31d837024926033f0abc20ddea66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Redon?= Date: Sun, 17 Jun 2018 22:36:44 +0200 Subject: [PATCH] DFU: incread watchdog timeout and restart watchdog before writing in flash to prevent the watchdog to trigger while flashing --- firmware/apps/dfu/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/firmware/apps/dfu/main.c b/firmware/apps/dfu/main.c index a5b6f74d..578f2f2f 100644 --- a/firmware/apps/dfu/main.c +++ b/firmware/apps/dfu/main.c @@ -10,6 +10,8 @@ #define ALTIF_FLASH 1 unsigned int g_unique_id[4]; +/* remember if the watchdog has been configured in the main loop so we can kick it in the ISR */ +static bool watchdog_configured = false; /*---------------------------------------------------------------------------- * Callbacks @@ -32,6 +34,10 @@ int USBDFU_handle_dnload(uint8_t altif, unsigned int offset, int rc; /* address of the last allocated variable on the stack */ uint32_t stack_addr = (uint32_t)&rc; + /* kick the dog to have enough time to flash */ + if (watchdog_configured) { + WDT_Restart(WDT); + } printf("dnload(altif=%u, offset=%u, len=%u)\n\r", altif, offset, len); @@ -186,9 +192,10 @@ extern int main(void) led_blink(LED_RED, BLINK_3O_30F); #endif - /* Enable watchdog for 500ms, with no window */ + /* Enable watchdog for 2000ms, with no window */ WDT_Enable(WDT, WDT_MR_WDRSTEN | WDT_MR_WDDBGHLT | WDT_MR_WDIDLEHLT | - (WDT_GetPeriod(500) << 16) | WDT_GetPeriod(500)); + (WDT_GetPeriod(2000) << 16) | WDT_GetPeriod(2000)); + watchdog_configured = true; PIO_InitializeInterrupts(0);