Skip to content

Commit

Permalink
Prevent watchdog reset during bootloader operations by feeding the wd…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
JF002 committed Jan 3, 2021
1 parent 3fae264 commit a6aeafc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions libs/pinetime_boot/src/pinetime_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "pinetime_boot/pinetime_boot.h"
#include "pinetime_boot/pinetime_factory.h"
#include "pinetime_boot/pinetime_delay.h"
#include <hal/hal_watchdog.h>

#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
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions libs/pinetime_boot/src/pinetime_factory.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pinetime_boot/pinetime_factory.h"
#include <hal/hal_flash.h>
#include "os/mynewt.h"
#include <hal/hal_watchdog.h>

// Flash Device for Image
#define FLASH_DEVICE 1 // 0 for Internal Flash ROM, 1 for External SPI Flash
Expand All @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion targets/nrf52_boot/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit a6aeafc

Please sign in to comment.