求解!!Core1 Panic'ed 与 xQueueRecieve问题[VSCode][ESP-IDF v5.4.2][Raspberry Pi OS]

George Xiao
Posts: 2
Joined: Wed Aug 06, 2025 1:41 am

求解!!Core1 Panic'ed 与 xQueueRecieve问题[VSCode][ESP-IDF v5.4.2][Raspberry Pi OS]

Postby George Xiao » Thu Aug 07, 2025 3:18 am

这是一个驱动EC11的小程序,通过ISR检测EC11 A端的下降沿读取B端电平从而判断正反转,并发送信息至任务处理队列进行ESP_LOGI输出处理.具体代码如下

Code: Select all

# include "freertos/FreeRTOS.h"
# include "freertos/task.h"
# include "freertos/queue.h"

# include "driver/gpio.h"
# include "driver/ledc.h"

# include "esp_log.h"
# include "cstring"

const char *TAG = "Da capo al Fine";

// Main Flow Control
QueueHandle_t app_core_queue;
QueueHandle_t prg_core_queue;

enum app_core_event {
    app_no_event = 0b00000000,
    ec11_twist_pc = 0b00010001,
    ec11_twist_nc = 0b00010010,
    ec11_press_btn = 0b00010011,
};

TaskHandle_t app_core_event_handle;

// EC11 Configurations
const gpio_num_t ec11_io_a = GPIO_NUM_7;
const gpio_num_t ec11_io_b = GPIO_NUM_8;
const gpio_num_t ec11_io_d = GPIO_NUM_12;
const gpio_pullup_t ec11_pullup_enable = GPIO_PULLUP_DISABLE ;

// Metronome Configurations
const gpio_num_t mtnm_led_io = GPIO_NUM_10;
const ledc_timer_bit_t mtnm_led_timer_duty_resolution = LEDC_TIMER_10_BIT;
const ledc_timer_t mtnm_led_timer_num = LEDC_TIMER_0;
const ledc_channel_t mtnm_led_channel_num = LEDC_CHANNEL_0;
const uint32_t mtnm_led_duty = (1 << mtnm_led_timer_duty_resolution) * 0.5;
uint16_t bpm = 0;

static IRAM_ATTR void ec11_twist_intr_handle(void *args){
    QueueHandle_t *queue = (QueueHandle_t *)args;

    BaseType_t state = pdFALSE;
    if (gpio_get_level(ec11_io_b) == 1){
        xQueueSendFromISR(*queue, (void *)ec11_twist_pc, &state);
    }
    else {
        xQueueSendFromISR(*queue, (void *)ec11_twist_nc, &state);
    }

    portYIELD_FROM_ISR(state);
}

static IRAM_ATTR void ec11_press_intr_handle(void *args){
    QueueHandle_t *queue = (QueueHandle_t *)args;

    BaseType_t state = pdFALSE;
    if (gpio_get_level(ec11_io_d) == 0){
        xQueueSendFromISR(*queue, (void *)ec11_press_btn, &state);
    }

    portYIELD_FROM_ISR (state);
}

/// @brief 
/// @param args 
static void app_core_event_dispose(void *args){
    QueueHandle_t *queue = (QueueHandle_t *)args;
    app_core_event buffer;

    while (true){
        if (xQueueReceive(*queue, &buffer, portMAX_DELAY)){
            switch (buffer){
                case ec11_twist_pc:
                    ESP_LOGI(TAG, "EC11 Twist Positive Clock\r\n");
                    break;
                case ec11_twist_nc:
                    ESP_LOGI(TAG, "EC11 Twist Negetive Clock\r\n");
                    break;
                case ec11_press_btn:
                    ESP_LOGI(TAG, "EC11 Button Pressed\r\n");
                    break;
                case app_no_event:
                    break;
            }
        }

    }
}

extern "C" void app_main(){

    app_core_queue = xQueueCreate(16, sizeof(app_core_event));

    gpio_config_t ec11_io_config_a = {
        .pin_bit_mask = 1UL << ec11_io_a,
        .mode = GPIO_MODE_INPUT,
        .pull_up_en = ec11_pullup_enable,
        .pull_down_en = GPIO_PULLDOWN_DISABLE,
        .intr_type = GPIO_INTR_NEGEDGE
    };
    gpio_config(&ec11_io_config_a);

    gpio_config_t ec11_io_config_b = {
        .pin_bit_mask = 1UL << ec11_io_b,
        .mode = GPIO_MODE_INPUT,
        .pull_up_en = ec11_pullup_enable,
        .pull_down_en = GPIO_PULLDOWN_DISABLE,
        .intr_type = GPIO_INTR_DISABLE
    };
    gpio_config(&ec11_io_config_b);

    gpio_config_t ec11_io_config_d = {
        .pin_bit_mask = 1UL << ec11_io_d,
        .mode = GPIO_MODE_INPUT,
        .pull_up_en = ec11_pullup_enable,
        .pull_down_en = GPIO_PULLDOWN_DISABLE,
        .intr_type = GPIO_INTR_NEGEDGE
    };
    gpio_config(&ec11_io_config_d);

    gpio_install_isr_service(0);

    gpio_isr_handler_add(ec11_io_a, ec11_twist_intr_handle, (void *)app_core_queue);
    gpio_isr_handler_add(ec11_io_d, ec11_press_intr_handle, (void *)app_core_queue);
    
    xTaskCreatePinnedToCore(app_core_event_dispose, 
                            "app_core_event", 
                            4096, 
                            (void *)app_core_queue, 
                            8, 
                            &app_core_event_handle,
                            APP_CPU_NUM);

    while (true){
        ;
    }
}
编译与烧录均成功,可上电之后报错,具体如下:

Code: Select all

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xa (SPI_FAST_FLASH_BOOT)
Saved PC:0x420022cb
--- 0x420022cb: panic_handler at /home/george/esp/v5.4.2/esp-idf/components/esp_system/port/panic_handler.c:176
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce2810,len:0x1564
load:0x403c8700,len:0x4
load:0x403c8704,len:0xd24
load:0x403cb700,len:0x2ed4
entry 0x403c8928
I (31) boot: ESP-IDF v5.4.2-dirty 2nd stage bootloader
I (31) boot: compile time Aug  7 2025 09:38:19
I (31) boot: Multicore bootloader
I (32) boot: chip revision: v0.2
I (35) boot: efuse block revision: v1.3
I (38) boot.esp32s3: Boot SPI Speed : 80MHz
I (42) boot.esp32s3: SPI Mode       : DIO
I (46) boot.esp32s3: SPI Flash Size : 2MB
I (50) boot: Enabling RNG early entropy source...
I (54) boot: Partition Table:
I (57) boot: ## Label            Usage          Type ST Offset   Length
I (63) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (70) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (76) boot:  2 factory          factory app      00 00 00010000 00100000
I (83) boot: End of partition table
I (86) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=0a850h ( 43088) map
I (101) esp_image: segment 1: paddr=0001a878 vaddr=3fc92700 size=02a48h ( 10824) load
I (104) esp_image: segment 2: paddr=0001d2c8 vaddr=40374000 size=02d50h ( 11600) load
I (111) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=18bbch (101308) map
I (134) esp_image: segment 4: paddr=00038be4 vaddr=40376d50 size=0b994h ( 47508) load
I (145) esp_image: segment 5: paddr=00044580 vaddr=600fe000 size=0001ch (    28) load
I (150) boot: Loaded app from partition at offset 0x10000
I (151) boot: Disabling RNG early entropy source...
I (162) cpu_start: Multicore app
I (172) cpu_start: Pro cpu start user code
I (172) cpu_start: cpu freq: 160000000 Hz
I (172) app_init: Application information:
I (172) app_init: Project name:     Dacapo_al_Fine
I (176) app_init: App version:      1
I (180) app_init: Compile time:     Aug  7 2025 09:37:29
I (185) app_init: ELF file SHA256:  4aa190328...
I (189) app_init: ESP-IDF:          v5.4.2-dirty
I (194) efuse_init: Min chip rev:     v0.0
I (197) efuse_init: Max chip rev:     v0.99 
I (201) efuse_init: Chip rev:         v0.2
I (205) heap_init: Initializing. RAM available for dynamic allocation:
I (212) heap_init: At 3FC95A30 len 00053CE0 (335 KiB): RAM
I (217) heap_init: At 3FCE9710 len 00005724 (21 KiB): RAM
I (222) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (227) heap_init: At 600FE01C len 00001FCC (7 KiB): RTCRAM
I (233) spi_flash: detected chip: generic
I (236) spi_flash: flash io: dio
W (239) spi_flash: Detected size(16384k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (251) sleep_gpio: Configure to isolate all GPIO pins in sleep state
I (258) sleep_gpio: Enable automatic switching of GPIO sleep configuration
I (265) main_task: Started on CPU0
I (285) main_task: Calling app_main()
I (285) gpio: GPIO[7]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:2 
I (285) gpio: GPIO[8]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (295) gpio: GPIO[12]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:2 
Guru Meditation Error: Core  1 panic'ed (Interrupt wdt timeout on CPU1). 

Core  1 register dump:
PC      : 0x40378385  PS      : 0x00060034  A0      : 0x8037aa50  A1      : 0x3fc9a670  
--- 0x40378385: xt_utils_compare_and_set at /home/george/esp/v5.4.2/esp-idf/components/xtensa/include/xt_utils.h:223
--- (inlined by) esp_cpu_compare_and_set at /home/george/esp/v5.4.2/esp-idf/components/esp_hw_support/cpu.c:232
A2      : 0x3fc996f4  A3      : 0xb33fffff  A4      : 0x00000000  A5      : 0x3fc99200  
A6      : 0x4037b780  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x00000000  
--- 0x4037b780: prvIdleTask at /home/george/esp/v5.4.2/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:4276
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x3fc99200  A13     : 0x3fc991e0  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x00000000  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  


Backtrace: 0x40378382:0x3fc9a670 0x4037aa4d:0x3fc9a690 0x4037a5bf:0x3fc9a6c0 0x42009e1a:0x3fc9a700 0x4037a849:0x3fc9a730
--- 0x40378382: xt_utils_compare_and_set at /home/george/esp/v5.4.2/esp-idf/components/xtensa/include/xt_utils.h:216
--- (inlined by) esp_cpu_compare_and_set at /home/george/esp/v5.4.2/esp-idf/components/esp_hw_support/cpu.c:232
--- 0x4037aa4d: spinlock_acquire at /home/george/esp/v5.4.2/esp-idf/components/esp_hw_support/include/spinlock.h:132
--- (inlined by) xPortEnterCriticalTimeout at /home/george/esp/v5.4.2/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:479
--- 0x4037a5bf: vPortEnterCritical at /home/george/esp/v5.4.2/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:567
--- (inlined by) xQueueReceive at /home/george/esp/v5.4.2/esp-idf/components/freertos/FreeRTOS-Kernel/queue.c:1549
--- 0x42009e1a: app_core_event_dispose(void*) at /home/george/Desktop/Programming/ESP32_S3/Dacapo_al_Fine/main/Dacapo_al_Fine.cpp:72
--- 0x4037a849: vPortTaskWrapper at /home/george/esp/v5.4.2/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:139


Core  0 register dump:
PC      : 0x42009f1c  PS      : 0x00060334  A0      : 0x82018486  A1      : 0x3fc98290  
--- 0x42009f1c: app_main at /home/george/Desktop/Programming/ESP32_S3/Dacapo_al_Fine/main/Dacapo_al_Fine.cpp:135
A2      : 0x00000003  A3      : 0x3c0241b4  A4      : 0x3c024228  A5      : 0x3fc982d0  
A6      : 0x00000018  A7      : 0x3fc9584c  A8      : 0x82009f1c  A9      : 0x3fc98250  
A10     : 0x00000001  A11     : 0x3c0254e8  A12     : 0x00001000  A13     : 0x00000001  
A14     : 0x3fc9a89c  A15     : 0x3fc99898  SAR     : 0x00000019  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x400570e8  LEND    : 0x400570f3  LCOUNT  : 0x00000000  
--- 0x400570e8: memset in ROM
--- 0x400570f3: memset in ROM


Backtrace: 0x42009f19:0x3fc98290 0x42018483:0x3fc98310 0x4037a849:0x3fc98340
--- 0x42009f19: app_main at /home/george/Desktop/Programming/ESP32_S3/Dacapo_al_Fine/main/Dacapo_al_Fine.cpp:127
--- 0x42018483: main_task at /home/george/esp/v5.4.2/esp-idf/components/freertos/app_startup.c:208
--- 0x4037a849: vPortTaskWrapper at /home/george/esp/v5.4.2/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:139




ELF file SHA256: 4aa190328

Rebooting...
OpenOCD调试过也看不出什么问题,翻阅书籍资料也看不出,望哪位大佬能够发现并指出问题,必将感激不尽 :D :D :D

Who is online

Users browsing this forum: No registered users and 3 guests