Zephyr Save GPIO output status after reset

Hi All,

I am using a nrf52840 chip with Zephyr OS. I wanted to know if there is a way to save the status of a GPIO output pin after a reset (caused by the Watchdog timer).

I found the initialization GPIO API:

int gpio_pin_configure_dt(const struct gpio_dt_spec *spec, gpio_flags_t extra_flags)

And passing as flag:  “GPIO_OUTPUT" in the documentation it is written "/** Enables pin as output, no change to the output state. */", so I thought that maybe it could save the GPIO output status. 

As soon as the device resets I am experiencing the GPIO pin changing it's status, I thought that maybe the WDT resets the entire SOC (GPIO peripheral included).

Am I doing something wrong? Is there a better way to do it?

Thanks.

  • Sorry, you're right. I forgot the retained registers are cleared through WD resets. Writing to flash is also problematic because you only have 2 32K cycles to perform the write:

    "If the watchdog is configured to generate an interrupt on the TIMEOUT event, the watchdog reset will be postponed with two 32.768 kHz clock cycles after the TIMEOUT event has been generated. Once the TIMEOUT event has been generated, the impending watchdog reset will always be effectuated."

    Watchdog reset 

    The best option is likely to use the Retention System which allocates a non-init section in RAM. Please note that the spec. does not guarantee that RAM will be retained through a WD reset.

Related