From a6aeafcbb8fea1f0b115b3074f36118ed3d71e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 3 Jan 2021 18:16:20 +0100 Subject: [PATCH] Prevent watchdog reset during bootloader operations by feeding the wdt during transfer of the recovery firmware and during mcuboot processing. This is needed because the bootloader is NOT disabled by a softreset (NVIC_systemReset()) or by a reset via the debug interface. --- libs/pinetime_boot/src/pinetime_boot.c | 2 ++ libs/pinetime_boot/src/pinetime_factory.c | 3 +++ targets/nrf52_boot/syscfg.yml | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/pinetime_boot/src/pinetime_boot.c b/libs/pinetime_boot/src/pinetime_boot.c index 64484e3..0411f22 100644 --- a/libs/pinetime_boot/src/pinetime_boot.c +++ b/libs/pinetime_boot/src/pinetime_boot.c @@ -29,6 +29,7 @@ #include "pinetime_boot/pinetime_boot.h" #include "pinetime_boot/pinetime_factory.h" #include "pinetime_boot/pinetime_delay.h" +#include #define PUSH_BUTTON_IN 13 // GPIO Pin P0.13: PUSH BUTTON_IN #define PUSH_BUTTON_OUT 15 // GPIO Pin P0.15/TRACEDATA2: PUSH BUTTON_OUT @@ -71,6 +72,7 @@ void pinetime_boot_init(void) { } if(i % 64 == 0) { console_printf("step %d - %d\n", (i / (64)) + 1, (int)button_samples); console_flush(); + hal_watchdog_tickle(); } if(i % 8 == 0) { diff --git a/libs/pinetime_boot/src/pinetime_factory.c b/libs/pinetime_boot/src/pinetime_factory.c index f954cf5..804db06 100644 --- a/libs/pinetime_boot/src/pinetime_factory.c +++ b/libs/pinetime_boot/src/pinetime_factory.c @@ -1,6 +1,7 @@ #include "pinetime_boot/pinetime_factory.h" #include #include "os/mynewt.h" +#include // Flash Device for Image #define FLASH_DEVICE 1 // 0 for Internal Flash ROM, 1 for External SPI Flash @@ -18,9 +19,11 @@ void restore_factory(void) { int rc; for (uint32_t erased = 0; erased < FACTORY_SIZE; erased += 0x1000) { rc = hal_flash_erase_sector(FLASH_DEVICE, FACTORY_OFFSET_DESTINATION + erased); + hal_watchdog_tickle(); } for(uint32_t offset = 0; offset < FACTORY_SIZE; offset += BATCH_SIZE) { + hal_watchdog_tickle(); rc = hal_flash_read(FLASH_DEVICE, FACTORY_OFFSET_SOURCE + offset, flash_buffer, BATCH_SIZE); assert(rc == 0); rc = hal_flash_write(FLASH_DEVICE, FACTORY_OFFSET_DESTINATION + offset, flash_buffer, BATCH_SIZE); diff --git a/targets/nrf52_boot/syscfg.yml b/targets/nrf52_boot/syscfg.yml index cb4a9d5..8bd6eb7 100644 --- a/targets/nrf52_boot/syscfg.yml +++ b/targets/nrf52_boot/syscfg.yml @@ -49,4 +49,8 @@ syscfg.vals: OS_SYSVIEW_TRACE_CALLOUT: 0 # Disable trace of callouts OS_SYSVIEW_TRACE_EVENTQ: 0 # Disable trace of event queues OS_SYSVIEW_TRACE_MUTEX: 0 # Disable trace of mutex - OS_SYSVIEW_TRACE_SEM: 0 # Disable trace of semaphores \ No newline at end of file + OS_SYSVIEW_TRACE_SEM: 0 # Disable trace of semaphores + BOOTUTIL_FEED_WATCHDOG: 1 # Enable watchdog feeding while performing a swap upgrade + SANITY_INTERVAL: 1000 # The interval (in milliseconds) at which the sanity checks should run, should be at least 200ms prior to watchdog + WATCHDOG_INTERVAL: 2000 # The interval (in milliseconds) at which the watchdog should reset if not tickled, in ms +