xTaskNotifyFromISR / xTaskNotifyWait pair causes error

x_arrange
Posts: 12
Joined: Sat May 20, 2017 10:32 am

xTaskNotifyFromISR / xTaskNotifyWait pair causes error

Postby x_arrange » Thu Feb 08, 2024 8:48 pm

Hi all,

I want to make my ESP32-C3 to restart when I press button connected to GPIO4. Here is my code

Code: Select all

static TaskHandle_t taskBTNReset;

static void IRAM_ATTR reset_button_isr_handler(void* arg)
{
	xTaskNotifyFromISR( taskBTNReset, 0, eNoAction, NULL);
}

static void task_btn_reset(void* param) 
{	
	printf("Wating for notification\n");
	xTaskNotifyWait( 0,0, NULL, portMAX_DELAY );	
	
	printf("Restarting...\n");	
	
	esp_restart();
}
void app_main(void)
{

	gpio_config_t io_conf;
	io_conf.intr_type = GPIO_INTR_POSEDGE;
	io_conf.mode = GPIO_MODE_INPUT;
	io_conf.pin_bit_mask = (uint64_t)((uint64_t)(((uint64_t)1)<<4));
	io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
	io_conf.pull_up_en = GPIO_PULLUP_DISABLE ;
	gpio_config(&io_conf);
	
	gpio_set_intr_type(4, GPIO_INTR_POSEDGE);
	
	gpio_install_isr_service(ESP_INTR_FLAG_EDGE | ESP_INTR_FLAG_IRAM);    
	gpio_isr_handler_add(4, reset_button_isr_handler, NULL);
	
	xTaskCreate( task_btn_reset, "reset_task", 2048, NULL, 28, &taskBTNReset);
}
But this causes errors
0x403868f4: vPortClearInterruptMask at C:/Espressif/frameworks/esp-idf-v5.1.2/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:385
0x4038691e: vPortExitCritical at C:/Espressif/frameworks/esp-idf-v5.1.2/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:339
0x42005724: console_write at C:/Espressif/frameworks/esp-idf-v5.1.2/components/vfs/vfs_console.c:71
0x40386284: xTaskGenericNotifyWait at C:/Espressif/frameworks/esp-idf-v5.1.2/components/freertos/FreeRTOS-Kernel/tasks.c:5913

Do I do something wrong?
Here is full log:

[Codebox]Wating for notification
E (14917) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (14917) task_wdt: - IDLE (CPU 0)
E (14917) task_wdt: Tasks currently running:
E (14917) task_wdt: CPU 0: reset_task
E (14917) task_wdt: Print CPU 0 (current core) registers
Core T8 register dump:
MEPC : 0x403868f4 RA : 0x4038691e SP : 0x3fc939c0 GP : 0x3fc8c000
0x403868f4: vPortClearInterruptMask at C:/Espressif/frameworks/esp-idf-v5.1.2/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:385
0x4038691e: vPortExitCritical at C:/Espressif/frameworks/esp-idf-v5.1.2/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:339

TP : 0x3fc8ac10 T0 : 0x00000000 T1 : 0x00000000 T2 : 0x00000000
S0/FP : 0x00000000 S1 : 0xffffffff A0 : 0x00000001 A1 : 0x00000001
A2 : 0x00000000 A3 : 0x00000004 A4 : 0x3fc8f000 A5 : 0x600c2000
A6 : 0x42005724 A7 : 0x00000000 S2 : 0x00000000 S3 : 0x00000000
0x42005724: console_write at C:/Espressif/frameworks/esp-idf-v5.1.2/components/vfs/vfs_console.c:71

S4 : 0xffffffff S5 : 0x00000000 S6 : 0x00000000 S7 : 0x00000000
S8 : 0x00000000 S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000
T3 : 0x00000000 T4 : 0x00000000 T5 : 0x00000000 T6 : 0x00000000
MSTATUS : 0x00000000 MTVEC : 0xffffffff MCAUSE : 0x00000000 MTVAL : 0x40386284
0x40386284: xTaskGenericNotifyWait at C:/Espressif/frameworks/esp-idf-v5.1.2/components/freertos/FreeRTOS-Kernel/tasks.c:5913[/Codebox]

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

Re: xTaskNotifyFromISR / xTaskNotifyWait pair causes error

Postby ESP_Sprite » Fri Feb 09, 2024 2:19 am

You install the ISR before starting the task. This means that the ISR can trigger before TaskBTNReset is initalized.

x_arrange
Posts: 12
Joined: Sat May 20, 2017 10:32 am

Re: xTaskNotifyFromISR / xTaskNotifyWait pair causes error

Postby x_arrange » Fri Feb 09, 2024 7:15 am

ESP_Sprite wrote:
Fri Feb 09, 2024 2:19 am
You install the ISR before starting the task. This means that the ISR can trigger before TaskBTNReset is initalized.
1. No it cann't untill I press the button - I have pulldown.
2. Same error if I start task before interrupt init.

x_arrange
Posts: 12
Joined: Sat May 20, 2017 10:32 am

Re: xTaskNotifyFromISR / xTaskNotifyWait pair causes error

Postby x_arrange » Fri Feb 09, 2024 12:19 pm

Aparently as suggested by Sudeep (https://github.com/espressif/esp-idf/is ... 1935791232) just need to remove ESP_INTR_FLAG_EDGE flag

Nespressif
Posts: 76
Joined: Tue Sep 12, 2017 11:25 am

Re: xTaskNotifyFromISR / xTaskNotifyWait pair causes error

Postby Nespressif » Fri Feb 09, 2024 1:01 pm

In some of my projects I have used this component and it is very simple and powerful. I hope it helps you. Best regards.

https://docs.espressif.com/projects/esp ... utton.html

Who is online

Users browsing this forum: Bing [Bot], ShinyGlossy and 210 guests