GPIO isr is not working

HEckardt
Posts: 11
Joined: Wed Aug 16, 2023 3:13 pm

GPIO isr is not working

Postby HEckardt » Fri Jan 26, 2024 9:15 am

Dear ESP-Forum Members,

I posted this problem already in the "IoT" chapter of this forum. But I think - I hope, here in the "Hardware Part" I get more resonance.

For my project I need a GPIO interrupt (pressed button). I selected the GPIO25 pin connect it through the switch to the ground. The negative edge should start the isr. Message from the GPIO configurator:
I (2283) gpio: GPIO[25]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2



I adapted the ESP-example-code for my needs:

Code: Select all

[Codebox=c file=Untitled.c]


#define GPIO_OK_Button 25  
#define ESP_INTR_FLAG_DEFAULT 0

static const char *TAG = "HE_Ctrl";

static bool ok_pressed;

static QueueHandle_t gpio_evt_queue = NULL;

static void IRAM_ATTR gpio_isr_handler(void* arg)
{
	ESP_LOGI(TAG, "gpio_isr_before queuesend");
	ESP_LOGI(TAG, "isr_arg: %lX", (uint32_t) arg);
    uint32_t gpio_num = (uint32_t) arg;
    xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
	ESP_LOGI(TAG, "gpio_isr_after queuesend");

}

static void OK_task(void* arg)
{
    uint32_t io_num;
    for(;;) {
        if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
			vTaskDelay(100 / portTICK_PERIOD_MS);
			printf("GPIO[%"PRIu32"] intr, val: %d\n", io_num, gpio_get_level(io_num));
			ok_pressed = true;
        }
    }
}

static void init_ok_button(void)
{
	ok_pressed = false;
    //zero-initialize the config structure.
    gpio_config_t io_conf = {};
    io_conf.intr_type = GPIO_INTR_NEGEDGE;
    io_conf.pin_bit_mask = 1ULL<<GPIO_OK_Button;
    io_conf.mode = GPIO_MODE_INPUT;
    io_conf.pull_up_en = 1;
    gpio_config(&io_conf);


	ESP_LOGI(TAG, "BitMask: %LX", io_conf.pin_bit_mask);

	
    // create a queue to handle gpio event from isr
    gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
    // start gpio task
    xTaskCreate(OK_task, "gpio_task_example", 2048, NULL, 10, NULL);

    //install gpio isr service
    gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
    //hook isr handler for specific gpio pin
    gpio_isr_handler_add(GPIO_OK_Button, gpio_isr_handler, (void*) GPIO_OK_Button);


    printf("Minimum free heap size: %"PRIu32" bytes\n", esp_get_minimum_free_heap_size());
	

	ESP_LOGI(TAG, "gpio_initialized");

}



[/Codebox]



But when I press the switch to trigger the isr, the ESP32 is restarting and the monitor get this printout:

abort() was called at PC 0x40083043 on core 0


Backtrace: 0x40081ac6:0x3ffb1770 0x40089d6d:0x3ffb1790 0x40091686:0x3ffb17b0 0x40083043:0x3ffb1820 0x40083181:0x3ffb1850 0x400831fa:0x3ffb1870 0x4014a23a:0x3ffb18a0 0x4014d3a9:0x3ffb1bc0 0x401597d1:0x3ffb1bf0 0x4009004d:0x3ffb1c20 0x4008379d:0x3ffb1c70 0x400838b2:0x3ffb1ca0 0x40083942:0x3ffb1cd0 0x40082e35:0x3ffb1d00 0x40088b3f:0x3ffbcd00 0x400d370b:0x3ffbcd20 0x4008af41:0x3ffbcd40 0x4008c74d:0x3ffbcd60




ELF file SHA256: 43476a0f78228a12

Rebooting...
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
I added some ESP_LOGs in the isr-handler to find the problem. These outputs are not visible, so the problem accurs before or when the isr-handler is starting.

I have no idea what could be wrong. I assume it could be a storage problem.

I attached the complete monitor printout. Please help me to interprete the error message to find the root cause for the problem.

Thank you for your support.

Greetings
Henry
Attachments
teraterm.log
(12.36 KiB) Downloaded 263 times

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: GPIO isr is not working

Postby ESP_Sprite » Fri Jan 26, 2024 1:00 pm

Suggest you decode that backtrace. Easiest way is to use the built-in terminal emulation in esp-idf ('idf.py monitor -p your_serial_port_here') which automatically does the decoding for you.

HEckardt
Posts: 11
Joined: Wed Aug 16, 2023 3:13 pm

Re: GPIO isr is not working

Postby HEckardt » Fri Jan 26, 2024 3:54 pm

Hi ESP_Sprite,

do you found some mistakes in the code?

I`m using the idf-monitor not in general, because I can`t abort it with "Ctrl+]" (German keyboard, I guss).

But here the outcome from the idf-monitor during the start-up:
ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:7084
ho 0 tail 12 room 4
load:0x40078000,len:15576
ho 0 tail 12 room 4
load:0x40080400,len:4
0x40080400: _init at ??:?

load:0x40080404,len:3876
entry 0x4008064c
I (33) boot: ESP-IDF v5.1-dirty 2nd stage bootloader
I (33) boot: compile time Jan 18 2024 15:19:43
I (33) boot: Multicore bootloader
I (37) boot: chip revision: v1.0
I (41) boot.esp32: SPI Speed : 40MHz
I (46) boot.esp32: SPI Mode : DIO
I (50) boot.esp32: SPI Flash Size : 4MB
I (55) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (64) boot: ## Label Usage Type ST Offset Length
I (71) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (78) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (86) boot: 2 factory factory app 00 00 00010000 00100000
I (93) boot: End of partition table
I (98) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=22b5ch (142172) map
I (157) esp_image: segment 1: paddr=00032b84 vaddr=3ffb0000 size=06014h ( 24596) load
I (167) esp_image: segment 2: paddr=00038ba0 vaddr=40080000 size=07478h ( 29816) load
I (180) esp_image: segment 3: paddr=00040020 vaddr=400d0020 size=8acd8h (568536) map
I (385) esp_image: segment 4: paddr=000cad00 vaddr=40087478 size=0fca0h ( 64672) load
I (425) boot: Loaded app from partition at offset 0x10000
I (425) boot: Disabling RNG early entropy source...
I (436) cpu_start: Multicore app
I (437) cpu_start: Pro cpu up.
I (437) cpu_start: Starting app cpu, entry point is 0x40081470
0x40081470: call_start_cpu1 at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_system/port/cpu_start.c:154

I (0) cpu_start: App cpu up.
I (454) cpu_start: Pro cpu start user code
I (454) cpu_start: cpu freq: 160000000 Hz
I (455) cpu_start: Application information:
I (459) cpu_start: Project name: sauna_monitor
I (465) cpu_start: App version: 1
I (469) cpu_start: Compile time: Jan 18 2024 15:19:18
I (475) cpu_start: ELF file SHA256: c27d51eaf2b7dd23...
I (481) cpu_start: ESP-IDF: v5.1-dirty
I (486) cpu_start: Min chip rev: v0.0
I (491) cpu_start: Max chip rev: v3.99
I (496) cpu_start: Chip rev: v1.0
I (501) heap_init: Initializing. RAM available for dynamic allocation:
I (508) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (514) heap_init: At 3FFBA438 len 00025BC8 (150 KiB): DRAM
I (520) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (527) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (533) heap_init: At 40097118 len 00008EE8 (35 KiB): IRAM
I (541) spi_flash: detected chip: generic
I (544) spi_flash: flash io: dio
I (549) app_start: Starting scheduler on CPU0
I (553) app_start: Starting scheduler on CPU1
I (553) main_task: Started on CPU0
I (563) main_task: Calling app_main()
I (563) gpio: GPIO[21]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (573) gpio: GPIO[26]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (583) gpio: GPIO[33]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (2283) gpio: GPIO[32]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:4
I (2283) HE_Ctrl: BitMask: 0
Minimum free heap size: 265764 bytes
I (2283) HE_Ctrl: gpio_initialized
I (2413) wifi:wifi driver task: 3ffc33e8, prio:23, stack:6656, core=0
I (2433) wifi:wifi firmware version: b2f1f86
I (2433) wifi:wifi certification version: v7.0
I (2433) wifi:config NVS flash: enabled
I (2433) wifi:config nano formating: disabled
I (2433) wifi:Init data frame dynamic rx buffer num: 32
I (2443) wifi:Init management frame dynamic rx buffer num: 32
I (2443) wifi:Init management short buffer num: 32
I (2453) wifi:Init dynamic tx buffer num: 32
I (2453) wifi:Init static rx buffer size: 1600
I (2453) wifi:Init static rx buffer num: 10
I (2463) wifi:Init dynamic rx buffer num: 32
I (2463) wifi_init: rx ba win: 6
I (2473) wifi_init: tcpip mbox: 32
I (2473) wifi_init: udp mbox: 6
I (2473) wifi_init: tcp mbox: 6
I (2483) wifi_init: tcp tx win: 5744
I (2483) wifi_init: tcp rx win: 5744
I (2493) wifi_init: tcp mss: 1440
I (2493) wifi_init: WiFi IRAM OP enabled
I (2493) wifi_init: WiFi RX IRAM OP enabled
I (2503) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (2603) wifi:mode : sta (fc:f5:c4:3d:38:54)
I (2603) wifi:enable tsf
I (2603) HE_Ctrl: WIFI_EVENT_STA_START
I (2603) HE_Ctrl: Connecting to known WLAN: "H+GE_WoKn".
I (2623) wifi:new:<11,0>, old:<1,0>, ap:<255,255>, sta:<11,0>, prof:1
I (2623) wifi:state: init -> auth (b0)
I (2623) wifi:state: auth -> init (8a0)
I (2623) wifi:new:<11,0>, old:<11,0>, ap:<255,255>, sta:<11,0>, prof:1
I (2633) HE_Ctrl: WIFI_EVENT_STA_DISCONNECTED
I (5053) HE_Ctrl: WIFI_EVENT_STA_DISCONNECTED
I (5063) wifi:new:<11,0>, old:<11,0>, ap:<255,255>, sta:<11,0>, prof:1
I (5063) wifi:state: init -> auth (b0)
I (5063) wifi:state: auth -> assoc (0)
I (5073) wifi:state: assoc -> run (10)
I (5103) wifi:connected with H+GE_WoKn, aid = 2, channel 11, BW20, bssid = 2c:91:ab:2d:f0:a6
I (5103) wifi:security: WPA2-PSK, phy: bgn, rssi: -65
I (5113) wifi:pm start, type: 1

I (5113) wifi:<ba-add>idx:0 (ifx:0, 2c:91:ab:2d:f0:a6), tid:6, ssn:2, winSize:64
I (5133) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (6113) HE_Ctrl: ip handler: got ip: 192.168.178.54
I (6113) HE_Ctrl: connected to WLAN: H+GE_WoKn
I (6113) esp_netif_handlers: sta ip: 192.168.178.54, mask: 255.255.255.0, gw: 192.168.178.1
I (8553) HE_Ctrl: Broadcast sent
E (8553) HE_Ctrl: broadcast recieved failure
I (10553) HE_Ctrl: Broadcast sent
I (10553) HE_Ctrl: Receive udp unicast from 192.168.178.55:3333, data is HE_Sauna_Monitor
I (10553) HE_Ctrl: BroadcastAnswer recieved successfully
I (10563) HE_Ctrl: 192.168.178.55 was loaded to sauna_mon_ipadr.
I (10563) HE_Ctrl: Sauna Monitor found successfully
There is a strange information at line 12 "0x40080400: _init at ??:?"
Could it point to the problem?

after I pressed the buttom (GPIO 32 - I changed it in the meantime just for test) I got this from the idf-monitor:
abort() was called at PC 0x40083043 on core 0
0x40083043: lock_acquire_generic at C:/Espressif/frameworks/esp-idf-v5.1/components/newlib/locks.c:130



Backtrace: 0x40081ac6:0x3ffb1770 0x40089d6d:0x3ffb1790 0x40091686:0x3ffb17b0 0x40083043:0x3ffb1820 0x40083181:0x3ffb1850 0x400831fa:0x3ffb1870 0x4014a23e:0x3ffb18a0 0x4014d3ad:0x3ffb1bc0 0x401597d5:0x3ffb1bf0 0x4009004d:0x3ffb1c20 0x4008379d:0x3ffb1c70 0x400838b2:0x3ffb1ca0 0x40083983:0x3ffb1cd0 0x40082e35:0x3ffb1d00 0x40088b3f:0x3ffbcd00 0x400d370f:0x3ffbcd20 0x4008af41:0x3ffbcd40 0x4008c74d:0x3ffbcd60
0x40081ac6: panic_abort at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_system/panic.c:452

0x40089d6d: esp_system_abort at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_system/port/esp_system_chip.c:84

0x40091686: abort at C:/Espressif/frameworks/esp-idf-v5.1/components/newlib/abort.c:38

0x40083043: lock_acquire_generic at C:/Espressif/frameworks/esp-idf-v5.1/components/newlib/locks.c:130

0x40083181: _lock_acquire_recursive at C:/Espressif/frameworks/esp-idf-v5.1/components/newlib/locks.c:158

0x400831fa: __retarget_lock_acquire_recursive at C:/Espressif/frameworks/esp-idf-v5.1/components/newlib/locks.c:314

0x4014a23e: _vfprintf_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:849 (discriminator 2)

0x4014d3ad: vprintf at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vprintf.c:34 (discriminator 5)

0x401597d5: esp_log_writev at C:/Espressif/frameworks/esp-idf-v5.1/components/log/log.c:200

0x4009004d: esp_log_write at C:/Espressif/frameworks/esp-idf-v5.1/components/log/log.c:210

0x4008379d: gpio_isr_handler at C:/ESP32_Projects/Sauna_Ctrl/main/he_ok_button_part.h:31

0x400838b2: gpio_isr_loop at C:/Espressif/frameworks/esp-idf-v5.1/components/driver/gpio/gpio.c:462

0x40083983: gpio_intr_service at C:/Espressif/frameworks/esp-idf-v5.1/components/driver/gpio/gpio.c:492

0x40082e35: _xt_lowint1 at C:/Espressif/frameworks/esp-idf-v5.1/components/freertos/FreeRTOS-Kernel/portable/xtensa/xtensa_vectors.S:1226

0x40088b3f: xt_utils_wait_for_intr at C:/Espressif/frameworks/esp-idf-v5.1/components/xtensa/include/xt_utils.h:81
(inlined by) esp_cpu_wait_for_intr at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_hw_support/cpu.c:111

0x400d370f: esp_vApplicationIdleHook at C:/Espressif/frameworks/esp-idf-v5.1/components/esp_system/freertos_hooks.c:59

0x4008af41: prvIdleTask at C:/Espressif/frameworks/esp-idf-v5.1/components/freertos/FreeRTOS-Kernel/tasks.c:4327 (discriminator 1)

0x4008c74d: vPortTaskWrapper at C:/Espressif/frameworks/esp-idf-v5.1/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162





ELF file SHA256: c27d51eaf2b7dd23

Rebooting... (SW-CPU Reset)
ets Jun 8 2016 00:22:57
.
.
.
.
.
.
.
To be honest, I`ve no idea to interprete these messages. Who can help?

Greetings
Henry

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: GPIO isr is not working

Postby ESP_Sprite » Sat Jan 27, 2024 5:10 am

It tells you the call stack, that is what function crashed it, what function called that function, what function called that function etc. In this particular case, it clearly tells me what you're doing wrong: you're calling a blocking function in an ISR, and you're not allowed to do that. In particular:

Code: Select all

0x4009004d: esp_log_write at C:/Espressif/frameworks/esp-idf-v5.1/components/log/log.c:210
0x4008379d: gpio_isr_handler at C:/ESP32_Projects/Sauna_Ctrl/main/he_ok_button_part.h:31
The thing that ctrl+] doesn't work on a German keyboard is weird... looking at the layout, perhaps ctrl+* would work? Can you tell me a bit more about what exactly you're using there? It's not in our interest to exclude an entire country from using the monitor :P so I'd like to investigate.

JoeSensoric
Posts: 29
Joined: Fri Mar 03, 2017 10:31 am

Re: GPIO isr is not working

Postby JoeSensoric » Sat Jan 27, 2024 10:24 am

Hint: On a German keyboard you can abort the idf-monitor with STRG-AltGr-9.
AltGr-9 is the combination for "]", "STRG" is "CTRL".

HEckardt
Posts: 11
Joined: Wed Aug 16, 2023 3:13 pm

Re: GPIO isr is not working

Postby HEckardt » Sat Jan 27, 2024 11:13 am

Hi Joe,

exactly this combination with a German keyboard is NOT working. I tryed some other combinations, as suggested by ESP_Sprite, and found out, the "Cntr+plus_sign" is working. Ther is on an English keyboard the bracket "]" lokated.

HEckardt
Posts: 11
Joined: Wed Aug 16, 2023 3:13 pm

Re: GPIO isr is not working

Postby HEckardt » Sat Jan 27, 2024 11:20 am

Hello ESP_Sprite,

seems, I had too much stuff in the "gpio_isr_handler". When I removed it, then it works. I assume, only the queue should be served in the isr-handler. The rest must be done in the "xTaskCreate" created task.

For the idf-monitor:
please see my post below to Joe. Seems, the idf-monitor is not using the Windows-OS char-code-mapping.

Thank you for your support.

Greetings
Henry

HEckardt
Posts: 11
Joined: Wed Aug 16, 2023 3:13 pm

Re: GPIO isr is not working

Postby HEckardt » Sat Jan 27, 2024 4:19 pm

Hello ESP_Sprite,

again for the idf-monitor abort:

if I press "Ctrl+plus_sign" the console is printing "^]". This is the correct char-code for the abort. When I press "Ctrl+AltGr+9" the console is just printing "]", it´s equal to "AltGr+9". So, it is not a fault by the idf-monitor. The Windows-OS makes no differents between "Ctrl+AltGr+9" and "AltGr+9" in case a German keyboard is used.

Greetings
Henry

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: GPIO isr is not working

Postby ESP_Sprite » Mon Jan 29, 2024 3:45 am

HEckardt wrote:
Sat Jan 27, 2024 4:19 pm
again for the idf-monitor abort:

if I press "Ctrl+plus_sign" the console is printing "^]". This is the correct char-code for the abort. When I press "Ctrl+AltGr+9" the console is just printing "]", it´s equal to "AltGr+9". So, it is not a fault by the idf-monitor. The Windows-OS makes no differents between "Ctrl+AltGr+9" and "AltGr+9" in case a German keyboard is used.
FWIW, I just heard from my colleagues we have an additional shortcut for situations like this: Ctrl-T and then X should also exit the program.

JoeSensoric
Posts: 29
Joined: Fri Mar 03, 2017 10:31 am

Re: GPIO isr is not working

Postby JoeSensoric » Mon Jan 29, 2024 8:10 am

Thank you, "Ctrl-T and X" is working for me.

The reason why "Ctrl+AltGr+9" is working for me and not for Henry: I'm using Linux for the development environment, not Windows. So it's a different keyboard driver implementation. Perhaps the "Ctrl-T and then X" workaround should be mentioned in the documentation.

Who is online

Users browsing this forum: No registered users and 177 guests