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:

Fullscreen
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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.

  • I missed to say that before resetting I put the GPIO status to one of the two logic status, example of operations:

    1. Init GPIO with gpio_pin_configure_dt and "GPIO_OUTPUT" flag;

    2. force GPIO status to "1"

    3. reset by watchdog (or button reset)

    4. The GPIO status changed it's value to "0"

  • Hi,

    It is not possible to retain the GPIO configurations through a WD reset. The reset will reconfigure all pins to their default state.

    Reset behavior

    Default reset state:

    PIN_CNF[n]

    I may be able to suggest another approach if you could provide a bit more information about the use case and what you are trying to achieve.

    Best regards,

    Vidar

  • I wanted to retain the GPIO output status after a reset occurs so that after reset it will recover it's status, and I thought a solution "confined" to the GPIO peripheral without involving any non-volatile memory. But at this point I don't know if it is possible

  • Yes, that will require use of NV memory, or GPREGRET.

  • ok for NV memory, but for GPREGRET I am seeing that a WD reset will clear and reset the value, does it?

1 2