【问题标题】:Visual studio code Espressif IDF IRAM_ATTRVisual Studio 代码 Espressif IDF IRAM_ATTR
【发布时间】:2022-11-03 10:06:42
【问题描述】:

我已经在 Visual Studio 代码中安装了 Espressif IDF(1.5.0)。

当我在 Espressif IDE 中运行此代码时,我没有任何问题,但是当我使用 Visual Studio 代码时,我在 IRAM_ATTR 上收到一个错误,提示“需要一个类型说明符”,并且同一行中的第二个错误“需要一个 {”。 我在 portTICK_PERIOD_MS 上也收到一个错误,说“标识符 portTICK_PERIOD_MS 未定义”

有什么问题?

#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include "driver/uart.h"
#include "esp_log.h"
#include "esp_intr_alloc.h"
#include "soc/uart_reg.h"
#include "soc/uart_struct.h"
#include "driver/gpio.h"



#define TXD_PIN                         (GPIO_NUM_17)
#define RXD_PIN                         (GPIO_NUM_16)
#define UART                            UART_NUM_2
#define BUF_SIZE                        (1024)
#define RD_BUF_SIZE                     (BUF_SIZE)

static intr_handle_t                    handle_console;

static const char *TAG = "uart_events";
char rxbuf[256];

static void IRAM_ATTR uart_intr_handler(void *arg)
{
    uint16_t rx_fifo_len, i=0;

    ESP_EARLY_LOGI(TAG,"%s", "Interrupt entered...");

   
}


void app_main(void)
{

        esp_log_level_set(TAG, ESP_LOG_INFO);
        

        /* Configure parameters of an UART driver,
        * communication pins and install the driver */
        uart_config_t uart_config = {
            .baud_rate = 115200,
            .data_bits = UART_DATA_8_BITS,
            .parity = UART_PARITY_DISABLE,
            .stop_bits = UART_STOP_BITS_1,
            .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
            .source_clk = UART_SCLK_APB,
        };

        ESP_ERROR_CHECK(uart_param_config(UART, &uart_config));

        //Set UART log level
        esp_log_level_set(TAG, ESP_LOG_INFO);

        //Set UART pins (using UART0 default pins ie no changes.)
        ESP_ERROR_CHECK(uart_set_pin(UART, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));

        //Install UART driver, and get the queue.
        ESP_ERROR_CHECK(uart_driver_install(UART, BUF_SIZE * 2, 0, 0, NULL, 0));

        // release the pre registered UART handler/subroutine
        ESP_ERROR_CHECK(uart_isr_free(UART));

        // register new UART subroutine
        ESP_ERROR_CHECK(uart_isr_register(UART,uart_intr_handler, NULL, ESP_INTR_FLAG_IRAM, &handle_console));

        // enable RX interrupt
        ESP_ERROR_CHECK(uart_enable_rx_intr(UART));

        

        while(1)
        {
              vTaskDelay(2000 / portTICK_PERIOD_MS);
        }
}

【问题讨论】:

  • 嗨@Softtoon - 请编辑您的问题以发布一个证明问题的minimal, reproducible example。在这种情况下,使用IRAM_ATTR 定义一个函数应该很简单。查看已演示该问题的整个程序会很有帮助。在这种情况下,我们不知道您包含哪些头文件或哪些其他代码可能影响了您的问题。

标签: visual-studio-code esp32 esp-idf


【解决方案1】:

缺少包含文件引用。在您的 .vscode 文件夹中查找 c_cpp_properties.json。如果没有找到,创建一个。

按此更新包含路径之类的属性: https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference

【讨论】:

    猜你喜欢
    • 2021-12-31
    • 2017-02-19
    • 1970-01-01
    • 2021-10-01
    • 2016-09-07
    • 2019-04-03
    • 2015-08-04
    • 2018-05-01
    • 2020-09-07
    相关资源
    最近更新 更多