Enable watchdog in early boot

I've been trying to enable the watchdog as early as possible during boot. I haven't been able to find any way to configure the nrf52832 watchdog to enable itself prior to code execution (nothing in the nrf52832 manual indicates this is possible).

My next step was to try to enable it as early as possible in the bootloader (mcuboot).

Mcuboot has KConfig CONFIG_BOOT_WATCHDOG_FEED which i've enabled, however mcuboot doesn't provide any option to enable the watchdog. I assume this must be done via zephyr instead. I've seen some zephyr drivers support enabling the watchdog at the end of the watchdog driver initialisation, but wdt_nrfx.c doesn't appear to support this.

Instead I thought i'd try adding a source file into the mcuboot build which uses SYS_INIT to configure the watchdog in PRE_KERNEL_2 (wdt_nrfx is initialised in PRE_KERNEL_1). However I can't figure out how to get this source file into the mcuboot build without modifying the CMakelists.txt in the mcuboot repository (I don't want to maintain my own fork of mcuboot).

How can I enable the watchdog as soon as possible in mcuboot, have mcuboot feed it, then once the application jump happens, feed from the application (I know how to feed from application normally, but zephyrs feeding api requires a watchdog_channel, which even if I did have it in mcuboot, won't be available to the application).

Parents Reply
  • I had a meeting with some people from nordic. They were also suggesting the same thing, but they weren't sure of whether it was possible to pass an additional source file to the mcuboot build via application cmakelists or additional args to west build. They said they were going to check with colleagues who knew a bit more about how the multi-image build system works. Probably if there isn't any way to do that, then as you say, modifying mcuboot would be the only way.

Children
  • Got an email indicating there is a lot of interest in answer to this.

    Can do without modifying mcuboot, by modifying zephyr's board files instead. The board file is built into both the zephyr app and mcuboot.

    Copied board to our apps folder (so we're not modifying zephyr's repo) then add a new source file to zephyr board's CMakeLists.txt.
    Add a function to init watchdog in the source file.
    Use zephyr's sys init to call it where you want during OS startup.
    i.e. SYS_INIT(your_fn, POST_KERNEL, 41);

    The board file is built by both application and bootloader, we only wanted in bootloader, so wrapped the sys_init call in #ifdef CONFIG_MCUBOOT.

    Wrt feeding from application after doing this, zephyr's wdt_feed call works fine with this setup.

Related