Watchdog feed best practices

Hello everybody. The typical sequence for to feed the watchdog onto one LPC17xx is the follow:
LPC_WDT->WDFEED = 0xAA;
LPC_WDT->WDFEED = 0x55;
My question: is It recommended to wrap the upper two lines inside a taskENTERCRITICAL() taskEXITCRITICAL() section? I got very rare watchdog events and I start to believe that they could be caused because one task switch happen between the two rows. Thanks in advance. Diego.

Watchdog feed best practices

Yes, I would wrap the sequence in a critical section if not a full interrupt disable as even with a very high priority interrupt you don’t want to break the pattern and risk getting the dog to trip.

Watchdog feed best practices

Also, try to access the watchdog from only one task. I often have one task that monitors all the other tasks, and kicks the watchdog only if it is happy with everything (for example, it has determined that all the tasks have executed within their expected time frame, etc.). Having only one task access reduces the risk of interleaved writes of the key.

Watchdog feed best practices

One thing worth pointing out is that in my experiance, for most watchdogs the sequence isn’t just first write the first value, and then some time later write the second, but that the two writes need to be very tightly timed to each other, so an interrupt seperating them, even if it doesn’t touch the watchdog, is enough to disrupt the kick of the watchdog. For some processors it needs a very specific instruction sequence, and there is a macro defined that will generate it. This is why I suggest it should be wrapped in a full interrupt disable.

Watchdog feed best practices

Hi Richard. Thank you for your fast reply. If I well understood the macro’s taskENTER_CRITICAL() and taskEXIT_CRITICAL() aren’t enough? Do you suggest to use disableirq() and enableirq() instead? Or not?

Watchdog feed best practices

Thank you Richard. My current implementation triggers the watchdog from only one task. Diego.

Watchdog feed best practices

Hi everybody. I’ve wrapped my watchdog trigger function inside the safe blocks as follows: taskENTERCRITICAL(); { LPCWDT->WDFEED = 0xAA; LPCWDT->WDFEED = 0x55; } taskEXITCRITICAL(); Currently I’m doing an extensive stress test to check if this solution can fixs my issue. I keep you updated. Thank you so much. Diego.

Watchdog feed best practices

taskENTERCRITICAL is good enough IF there are no other interrupts that might happen that don’t use the FreeRTOS Interrupt API that might still happen. If such an interrupt exists in your system then you want to wrap with a total interrupt disable block (not just taskENTERCRITICAL).

Watchdog feed best practices

Hello. After few days of extensive tests I can confirm (on my system) that taskENTERCRITICAL / taskEXITCRITICAL are not enough. I must wrapping the watchdog trigger code with disableirq() / enableirq() macros. Doing so It seems to woks reliable. My system has several interrupts, mostly comes form timers and UART. Thank you so much for the suggestions. Best regards. Diego.