abort() stacktrace when handling an interrupt

simpss
Posts: 2
Joined: Sun Nov 26, 2017 9:25 pm

abort() stacktrace when handling an interrupt

Postby simpss » Sun Nov 26, 2017 10:01 pm

I'm trying to make a simple GPIO input interrupt work as a proof of concept, but can't get the handler to work properly.
The setup is quite simple, I create a task that does the GPIO configuration and interrupt handler registration:

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "driver/gpio.h"

#include "sdkconfig.h"

void input_handler(void *args){
    printf("interrupted");
}

void configure_input(void *pvParameter){
    gpio_config_t gpioConfig;
    gpioConfig.pin_bit_mask = GPIO_SEL_17;
    gpioConfig.mode         = GPIO_MODE_INPUT;
    gpioConfig.pull_up_en   = GPIO_PULLUP_DISABLE;
    gpioConfig.pull_down_en = GPIO_PULLDOWN_ENABLE;
    gpioConfig.intr_type    = GPIO_INTR_POSEDGE;
    gpio_config(&gpioConfig);

    gpio_install_isr_service(0);
    gpio_isr_handler_add(GPIO_NUM_17, input_handler, NULL);
    
    vTaskDelete(NULL);
}

void app_main()
{
    nvs_flash_init();
    xTaskCreate(&configure_input, "configure_input_task", 8000, NULL, 9, NULL);
}
Everything works well, until I actually press the button to trigger the interruption. Then I get an error:

Code: Select all

abort() was called at PC 0x40081e95 on core 1

Backtrace: 0x400858a8:0x3ffc07d0 0x400859a7:0x3ffc07f0 0x40081e95:0x3ffc0810 0x40081fb5:0x3ffc0840 0x400d6db2:0x3ffc0860 0x400d4115:0x3ffc0b70 0x400d060a:0x3ffc0bc0 0x40080c42:0x3ffc0be0 0x40081a6d:0x3ffc0c00

Rebooting...
So it seems that the interrupt is triggered, but there is an issue with the handler itself. I've tried to make the handler as simple as possible in this example.

I also tried to register the handler with a pointer `gpio_isr_handler_add(GPIO_NUM_17, &input_handler, NULL);` but that didn't really change anything.

Any ideas on how to get it sorted?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: abort() stacktrace when handling an interrupt

Postby ESP_Angus » Sun Nov 26, 2017 11:18 pm

Hi simpss,

The answer for the code is:

It's not safe to printf() from an interrupt handler. By default printf() is line buffered, and it uses locking to ensure this is thread-safe (ie if multiple tasks all printf they appear on different lines instead of character soup.) But you can't lock in an ISR.

You can use ets_printf() which is the alternative function (in ESP32 ROM) which is ISR-safe. But generally it's good to avoid things like printing to serial in interrupts at all, if you can.

The answer for understanding the crash is:

You can use IDF monitor or xtensa-esp32-elf-addr2line to decode binary addresses and stack traces to source files, functions and line numbers (although the line numbers are often off the functions and source files are always accurate). See here:
http://esp-idf.readthedocs.io/en/latest ... -addresses

(The command line to manually decode the addresses is also shown there.)

simpss
Posts: 2
Joined: Sun Nov 26, 2017 9:25 pm

Re: abort() stacktrace when handling an interrupt

Postby simpss » Sun Nov 26, 2017 11:42 pm

yes, that makes sense, tried esp_printf() and it's working now. Thank you.

will certainly check out the IDF monitor as debugging tools always come in handy.
On my first baby steps with the platform, so lots to learn still.

Who is online

Users browsing this forum: Google [Bot] and 82 guests