This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to light an LED to notify when a serious error has occurred?

I'm digging my way through the examples, SDK code, etc, and I'm curious if it's possible to light an LED if the nRF52832 is reaching an error status. This is mainly so I can quickly realize something went wrong and I don't waste time waiting for an event to happen.

From what I'm seeing, an error will work its way down to app_error_fault_handler, where the final log flush, etc, happens. Is it possible to reliably set a pin from here so that an LED can light up? Something such as adding: nrf_gpio_cfg_output( LED_ERROR ); nrf_gpio_pin_clear( LED_ERROR );

These methods appear under the "GPIO abstraction", so I'm wondering there is a more sure-fire (or brute-force) way to set that pin when my little nRF52832 is about to shut down.

Thanks!

  • It seems to me that should be reliable. app_error handler can be less than "serious", things like invalid parameters. It is the handler for exceptions thrown by the SDK. The errors are often programming errors, not that the cpu is totally lost in the weeds.

    OTH you should also do a similar thing in the HardFaultHandler and related handlers (there are more handlers on the 52.) Which are more serious errors, e.g. bugs in the compiler or exhausted stack. It might depend on the kind of fault whether lighting the led would be "reliable."

    Personally, I rely on the debugger instead of LED's. I suppose in later testing or in production, you would want an LED indication that SOME fault occurred. But you usually already known that, and it would take many LEDs to know WHICH fault it was.

  • Hi Chris

    The nrf_gpio_pin_set/clear functions only provide a thin layer of abstraction, and calling them should be equivalent to using the hardware registers (except for the extra branching and register lookups). In other words you can safely use these functions in your error handler(s).

    Best regards
    Torbjørn

Related