Page 1 of 1

Error when using IRAM_ATTR

Posted: Tue Aug 16, 2022 1:08 pm
by MyControllab
Hello
I am new to ESP-IDF and I have create my first application with an interrupt handler and the application is working fine (Switching a led on/off based on a button interrupt).

But Visual Studio Code sees 3 problems in my code at line "void IRAM_ATTR button_isr_handler(void *args)".
When i remove IRAM_ATTR a problems are gone but i don't know why IRAM_ATTR gives me problems.

the problems are
- Expected a type specifier
- exptected a '{'
- identifier "button_isr_handler" is undefine (this is in the app_main)

Does anyone know where these IRAM_ATTR errors come from ?
Do i miss a setting in sdkconfig ???

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_log.h"

#define ESP_INR_FLAG_DEFAULT 0
#define BUTTON_PIN GPIO_NUM_25

TaskHandle_t ButtonTask_handle;
TaskHandle_t RedLedTask_handle;
TaskHandle_t GreenLedTask_handle;
TaskHandle_t ISR_handle;
TaskHandle_t volatile NextTask_Handle = NULL;


 void IRAM_ATTR button_isr_handler(void *args)
{
    xTaskResumeFromISR(ISR_handle);
}

void button_task(void *args)
{
    bool led_status = false;

    while (1)
    {
        vTaskSuspend(NULL);
        led_status = !led_status;
        gpio_set_level(GPIO_NUM_26, led_status);
        printf("Button pressed !");
    }
}


void app_main(void)
{
    // Initializeing GPIO25 as input with pull donw resistor.
    // Switch is connected to 3V3
    gpio_set_direction(BUTTON_PIN, GPIO_MODE_INPUT);
    gpio_set_pull_mode(BUTTON_PIN, GPIO_PULLDOWN_ONLY);

    // IO pins 26 and 27 as output
    gpio_set_direction(GPIO_NUM_26, GPIO_MODE_INPUT_OUTPUT);
    gpio_set_direction(GPIO_NUM_27, GPIO_MODE_INPUT_OUTPUT);

    //enable inerrupt on falling edge for the button pin
    gpio_set_intr_type(BUTTON_PIN, GPIO_INTR_NEGEDGE);

    //Install the drivers's GPIO ISR handler service, which allow per-pin GPIO interrupt handlers
    //Install ISR serive with default configuration
    gpio_install_isr_service(ESP_INR_FLAG_DEFAULT);

    //Attach the interrupt routine to the service routine
    gpio_isr_handler_add(BUTTON_PIN, button_isr_handler, NULL);

    xTaskCreate(button_task, "Button task", 1024 * 2, NULL, 5, &ISR_handle);
}


Re: Error when using IRAM_ATTR

Posted: Wed Aug 17, 2022 8:32 am
by cruvus
Try

Code: Select all

#include "esp_system.h"

Re: Error when using IRAM_ATTR

Posted: Sat Aug 20, 2022 2:32 pm
by MyControllab
Hello

Thank for the respons.
I added esp_system.h but that doesn't make any difference

with kind regards
Tonnie