Mair/esp32-course

_10_3_Input_interupt throwing IllegalInstruction

Closed this issue · 2 comments

Hi there, whenever I try to run the program _10_3_Input_interupt, my device crashes. I realized that if there is an infinite loop in app_main or if I add vTaskDelete(NULL); as the last line in the app_main function the code works. I have no clue why. I was hoping you could shine a light on this.

This does not work for me:

void app_main()
{
    gpio_pad_select_gpio(PIN_SWITCH);
    gpio_set_direction(PIN_SWITCH, GPIO_MODE_INPUT);
    gpio_pulldown_en(PIN_SWITCH);
    gpio_pullup_dis(PIN_SWITCH);
    gpio_set_intr_type(PIN_SWITCH, GPIO_INTR_POSEDGE);

    interputQueue = xQueueCreate(10, sizeof(int));
    xTaskCreate(buttonPushedTask, "buttonPushedTask", 2048, NULL, 1, NULL);

    gpio_install_isr_service(0);
    gpio_isr_handler_add(PIN_SWITCH, gpio_isr_handler, (void *)PIN_SWITCH);
}

but oddly enough, this does work:

void app_main()
{
    gpio_pad_select_gpio(PIN_SWITCH);
    gpio_set_direction(PIN_SWITCH, GPIO_MODE_INPUT);
    gpio_pulldown_en(PIN_SWITCH);
    gpio_pullup_dis(PIN_SWITCH);
    gpio_set_intr_type(PIN_SWITCH, GPIO_INTR_POSEDGE);

    interputQueue = xQueueCreate(10, sizeof(int));
    xTaskCreate(buttonPushedTask, "buttonPushedTask", 2048, NULL, 1, NULL);

    gpio_install_isr_service(0);
    gpio_isr_handler_add(PIN_SWITCH, gpio_isr_handler, (void *)PIN_SWITCH);

    vTaskDelete(NULL); // <==== THIS MAKE IT WORK
}

It's my understanding that esp-idf should automatically call vTaskDelete(NULL); after calling app_main(). I don't understand why I had to add it to make it work. Any idea? Thanks.

Output of monitor

I (0) cpu_start: App cpu up.
I (240) heap_init: Initializing. RAM available for dynamic allocation:
I (246) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (252) heap_init: At 3FFB28A0 len 0002D760 (181 KiB): DRAM
I (259) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (265) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (271) heap_init: At 40089FC8 len 00016038 (88 KiB): IRAM
I (278) cpu_start: Pro cpu start user code
I (296) spi_flash: detected chip: generic
I (296) spi_flash: flash io: dio
W (297) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (307) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Guru Meditation Error: Core  0 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400d189c: e5b7f665 00000131 0c004136
0x400d189c: main_task at C:/esp/esp-idf/components/esp32/cpu_start.c:594 (discriminator 2)

Core  0 register dump:
PC      : 0x400d18a2  PS      : 0x00060030  A0      : 0x800846b0  A1      : 0x3ffb4710
0x400d18a2: main_task at cpu_start.c:?

A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00060023  A5      : 0x3ffb22c8
A6      : 0x3ffb47c8  A7      : 0x00000000  A8      : 0x800d18a2  A9      : 0x3ffb46e0
A10     : 0x3ff48000  A11     : 0x00000001  A12     : 0x00000001  A13     : 0x00060023
A14     : 0x00000001  A15     : 0x00060023  SAR     : 0x00000011  EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff

Backtrace:0x400d189f:0x3ffb4710 0x400846ad:0x3ffb4740
0x400d189f: main_task at C:/esp/esp-idf/components/esp32/cpu_start.c:602 (discriminator 2)

0x400846ad: vPortTaskWrapper at C:/esp/esp-idf/components/freertos/xtensa/port.c:143



ELF file SHA256: 84c3f343b23feb95

Rebooting...

Actually, anything that uses tasks fails :(

Turns out my esp-idf library was corrupted. Thanks.