espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.72k stars 7.3k forks source link

mcpwm_capture_channel_register_event_callbacks(322): install interrupt service for cap channel failed (IDFGH-8010) #9520

Closed dizcza closed 2 years ago

dizcza commented 2 years ago

Environment

Problem Description

I'm migrating MCPWM capture mode from legacy to mcpwm_cap module using esp-idf master branch. In my code, which I cannot show all, I

and the code fails with

E (00:00:02.317) mcpwm: mcpwm_capture_channel_register_event_callbacks(322): install interrupt service for cap channel failed

If I

mcpwm_capture_channel_register_event_callbacks works fine. As the return code suggests - ESP_ERROR_CHECK, - "No free interrupt found with the specified flags".

Expected Behavior

There is at least one free interrupt with the MCPWM flags specified and mcpwm_capture_channel_register_event_callbacks succeeds.

Actual Behavior

There are no free interrupts with the MCPWM flags specified and mcpwm_capture_channel_register_event_callbacks fails.

Code to reproduce this issue

This is schematic code to perform GPS-RTC sync. It isn't meant to run.


static void shutdown_callback() {
    ESP_LOGW(TAG, "SHUTDOWN");
}

static void eample_i2c_init()
{
    int intr_flag_disable = 0;
    int i2c_port = 0;

    /* I2C master doesn't need buffer */
    size_t i2c_master_rx_buf_disable = 0;
    size_t i2c_master_tx_buf_disable = 0;

    i2c_config_t conf = {
        .mode = I2C_MODE_MASTER,
        .sda_io_num = 33,
        .scl_io_num = 32,
        .sda_pullup_en = GPIO_PULLUP_DISABLE,
        .scl_pullup_en = GPIO_PULLUP_DISABLE,
        .master.clk_speed = 400000,  /*!< I2C master clock frequency */
    };

    ESP_ERROR_CHECK(i2c_param_config(i2c_port, &conf));

    ESP_ERROR_CHECK(
            i2c_driver_install(i2c_port, conf.mode,
                    i2c_master_rx_buf_disable, i2c_master_tx_buf_disable,
                    intr_flag_disable));
    ESP_LOGI(TAG, "I2C%d initialized, clk=%lu", i2c_port, conf.master.clk_speed);
}

/**
 * Initialize and mount the SD card with MMC interface
 *
 * @return err code
 */
esp_err_t sdcard_mount_mmc() {
    ESP_LOGI(TAG, "Mounting SD MMC...");

    esp_vfs_fat_sdmmc_mount_config_t mount_config = SDCARD_MOUNT_CONFIG_DEFAULT();

    sdmmc_host_t host = SDMMC_HOST_DEFAULT();
    host.max_freq_khz = SDMMC_FREQ_HIGHSPEED;

    // This initializes the slot without card detect (CD) and write protect (WP) signals.
    // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
    sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();

    // Use 1-line SD mode
    slot_config.width = 1;

    // Enable internal pullups on enabled pins. The internal pullups
    // are insufficient however, please make sure 10k external pullups are
    // connected on the bus. This is for debug / example purpose only.
    slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP;

    esp_err_t err = esp_vfs_fat_sdmmc_mount(sdcard_mount_point, &host,
            &slot_config, &mount_config, &m_card);

    return err;
}

static void syncman_mcpwm_init(syncman_handle_t *shandle) {
    mcpwm_capture_timer_config_t cap_timer_conf = {
        .clk_src = MCPWM_CAPTURE_CLK_SRC_DEFAULT,
        .group_id = 0,
    };
    ESP_ERROR_CHECK(mcpwm_new_capture_timer(&cap_timer_conf, &shandle->cap_timer));
    ESP_ERROR_CHECK(mcpwm_capture_timer_enable(shandle->cap_timer));
}

static void syncman_mcpwm_enable(syncman_handle_t *shandle) {
    const Board_t *board = board_get();
    ESP_LOGI(TAG, ">>> syncman_mcpwm_enable ENTER");
    mcpwm_capture_channel_config_t channel_gps_conf = {
        .gpio_num = board->gps_gpio.pps,
        .prescale = 1,
        .flags.neg_edge = false,
        .flags.pos_edge = true,
        .flags.pull_up = false,
    .flags.pull_down = true,
    };
    ESP_ERROR_CHECK(mcpwm_new_capture_channel(shandle->cap_timer, &channel_gps_conf, &shandle->channel_gps));

    mcpwm_capture_channel_config_t channel_rtc_conf = {
        .gpio_num = board->rtc_gpio.sqw,
        .prescale = 1,
        .flags.neg_edge = true,
        .flags.pos_edge = false,
        .flags.pull_up = false,
    .flags.pull_down = false,
    };
    ESP_ERROR_CHECK(mcpwm_new_capture_channel(shandle->cap_timer, &channel_rtc_conf, &shandle->channel_rtc));

    mcpwm_capture_event_callbacks_t cbs = {
        .on_cap = ...,  // the callback function does not matter
    };
    vTaskDelay(pdMS_TO_TICKS(1000));
    ESP_ERROR_CHECK(mcpwm_capture_channel_register_event_callbacks(shandle->channel_gps, &cbs, (void*) handle));   //!<<< HERE IT FAILS
    ESP_ERROR_CHECK(mcpwm_capture_channel_register_event_callbacks(shandle->channel_rtc, &cbs, (void*) shandle));

    ESP_ERROR_CHECK(mcpwm_capture_timer_start(shandle->cap_timer));
    shandle->mcpwm_running = true;
    ESP_LOGI(TAG, "syncman_mcpwm_enable OK");
}

static void syncman_task() {
    syncman_handle_t *shandle = &m_synchandle;
    gps_init();
    syncman_mcpwm_init(shandle);
    syncman_mcpwm_enable(shandle);  //!<<< HERE IT FAILS
}

void app_main()
{
    esp_register_shutdown_handler(shutdown_callback);
    ESP_ERROR_CHECK(gpio_install_isr_service(ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL3));
    eample_i2c_init();
    sdcard_mount_mmc();
    syncman_task();
}

Debug Logs

I (0) cpu_start: App cpu up.
D (179) clk: RTC_SLOW_CLK calibration value: 16430899
I (184) cpu_start: Pro cpu start user code
I (184) cpu_start: cpu freq: 240000000 Hz
I (184) cpu_start: Application information:
I (189) cpu_start: Project name:     esp32-sdpsensor
I (195) cpu_start: App version:      34bac49-dirty
I (200) cpu_start: Compile time:     Aug  7 2022 20:37:16
I (206) cpu_start: ELF file SHA256:  78db116e17a2a5ab...
I (212) cpu_start: ESP-IDF:          v5.0-dev-4723-g30e8f19f5a-dirty
D (219) memory_layout: Checking 7 reserved memory ranges:
D (225) memory_layout: Reserved memory range 0x3ffae000 - 0x3ffae6e0
D (231) memory_layout: Reserved memory range 0x3ffb0000 - 0x3ffb75c8
D (238) memory_layout: Reserved memory range 0x3ffe0000 - 0x3ffe0440
D (244) memory_layout: Reserved memory range 0x3ffe3f20 - 0x3ffe4350
D (250) memory_layout: Reserved memory range 0x40070000 - 0x40078000
D (257) memory_layout: Reserved memory range 0x40078000 - 0x40080000
0x40080000: _WindowOverflow4 at /home/dizcza/tools/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/xtensa_vectors.S:1742

D (263) memory_layout: Reserved memory range 0x40080000 - 0x4008ff68
0x40080000: _WindowOverflow4 at /home/dizcza/tools/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/xtensa_vectors.S:1742

D (270) memory_layout: Building list of available memory regions:
D (276) memory_layout: Available memory region 0x3ffae6e0 - 0x3ffb0000
D (282) memory_layout: Available memory region 0x3ffb75c8 - 0x3ffb8000
D (289) memory_layout: Available memory region 0x3ffb8000 - 0x3ffc0000
D (296) memory_layout: Available memory region 0x3ffc0000 - 0x3ffc2000
D (302) memory_layout: Available memory region 0x3ffc2000 - 0x3ffc4000
D (309) memory_layout: Available memory region 0x3ffc4000 - 0x3ffc6000
D (315) memory_layout: Available memory region 0x3ffc6000 - 0x3ffc8000
D (322) memory_layout: Available memory region 0x3ffc8000 - 0x3ffca000
D (329) memory_layout: Available memory region 0x3ffca000 - 0x3ffcc000
D (335) memory_layout: Available memory region 0x3ffcc000 - 0x3ffce000
D (342) memory_layout: Available memory region 0x3ffce000 - 0x3ffd0000
D (348) memory_layout: Available memory region 0x3ffd0000 - 0x3ffd2000
D (355) memory_layout: Available memory region 0x3ffd2000 - 0x3ffd4000
D (362) memory_layout: Available memory region 0x3ffd4000 - 0x3ffd6000
D (368) memory_layout: Available memory region 0x3ffd6000 - 0x3ffd8000
D (375) memory_layout: Available memory region 0x3ffd8000 - 0x3ffda000
D (381) memory_layout: Available memory region 0x3ffda000 - 0x3ffdc000
D (388) memory_layout: Available memory region 0x3ffdc000 - 0x3ffde000
D (395) memory_layout: Available memory region 0x3ffde000 - 0x3ffe0000
D (401) memory_layout: Available memory region 0x3ffe0440 - 0x3ffe3f20
D (408) memory_layout: Available memory region 0x3ffe4350 - 0x3ffe8000
D (414) memory_layout: Available memory region 0x3ffe8000 - 0x3fff0000
D (421) memory_layout: Available memory region 0x3fff0000 - 0x3fff8000
D (428) memory_layout: Available memory region 0x3fff8000 - 0x3fffc000
D (434) memory_layout: Available memory region 0x3fffc000 - 0x40000000
D (441) memory_layout: Available memory region 0x4008ff68 - 0x40090000
D (447) memory_layout: Available memory region 0x40090000 - 0x40092000
D (454) memory_layout: Available memory region 0x40092000 - 0x40094000
D (461) memory_layout: Available memory region 0x40094000 - 0x40096000
D (467) memory_layout: Available memory region 0x40096000 - 0x40098000
D (474) memory_layout: Available memory region 0x40098000 - 0x4009a000
D (480) memory_layout: Available memory region 0x4009a000 - 0x4009c000
D (487) memory_layout: Available memory region 0x4009c000 - 0x4009e000
D (494) memory_layout: Available memory region 0x4009e000 - 0x400a0000
I (500) heap_init: Initializing. RAM available for dynamic allocation:
D (507) heap_init: New heap initialised at 0x3ffae6e0
I (512) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
D (519) heap_init: New heap initialised at 0x3ffb75c8
I (524) heap_init: At 3FFB75C8 len 00028A38 (162 KiB): DRAM
I (530) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (536) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
D (543) heap_init: New heap initialised at 0x4008ff68
I (548) heap_init: At 4008FF68 len 00010098 (64 KiB): IRAM
D (554) intr_alloc: Connected src 46 to int 2 (cpu 0)
D (559) spi_flash: trying chip: issi
D (563) spi_flash: trying chip: gd
D (566) spi_flash: trying chip: mxic
D (570) spi_flash: trying chip: winbond
I (574) spi_flash: detected chip: winbond
I (579) spi_flash: flash io: qio
D (582) chip_generic: set_io_mode: status before 0x200
W (588) spi_flash: Detected size(16384k) larger than the size in the binary image header(4096k). Using the size in the binary image header.
D (601) cpu_start: calling init function: 0x400f0f44
0x400f0f44: _GLOBAL__sub_I__ZN9__gnu_cxx9__freeresEv at eh_alloc.cc:?

D (606) cpu_start: calling init function: 0x400f0f08
0x400f0f08: _GLOBAL__sub_I___cxa_get_globals_fast at eh_globals.cc:?

D (611) cpu_start: calling init function: 0x400f0ac4
0x400f0ac4: s_set_default_wifi_log_level at /home/dizcza/tools/esp-idf/components/esp_wifi/src/wifi_init.c:62

D (616) cpu_start: calling init function: 0x400ee4d4
0x400ee4d4: esp_ipc_init at /home/dizcza/tools/esp-idf/components/esp_system/esp_ipc.c:115

D (621) cpu_start: calling init function: 0x400ece90
0x400ece90: check_rmt_legacy_driver_conflict at /home/dizcza/tools/esp-idf/components/driver/deprecated/rmt_legacy.c:1382

W (626) rmt(legacy): legacy driver is deprecated, please migrate to `driver/rmt_tx.h` and/or `driver/rmt_rx.h`
D (637) cpu_start: calling init function: 0x400d2e80
0x400d2e80: esp_reset_reason_init at /home/dizcza/tools/esp-idf/components/esp_system/port/soc/esp32/reset_reason.c:68

D (642) cpu_start: calling init function: 0x400d2480
0x400d2480: esp_ota_init_app_elf_sha256 at /home/dizcza/tools/esp-idf/components/app_update/esp_app_desc.c:68

D (647) cpu_start: calling init function: 0x400e44a0 on core: 0
0x400e44a0: __esp_system_init_fn_esp_timer_startup_init at /home/dizcza/tools/esp-idf/components/esp_timer/src/esp_timer.c:464

D (653) intr_alloc: Connected src 17 to int 3 (cpu 0)
D (658) cpu_start: calling init function: 0x40103528 on core: 0
0x40103528: __esp_system_init_fn_init_components0 at /home/dizcza/tools/esp-idf/components/esp_system/startup.c:462

D (664) intr_alloc: Connected src 24 to int 9 (cpu 0)
I (669) cpu_start: Starting scheduler on PRO CPU.
D (0) intr_alloc: Connected src 25 to int 2 (cpu 1)
I (0) cpu_start: Starting scheduler on APP CPU.
D (694) heap_init: New heap initialised at 0x3ffe0440
D (694) heap_init: New heap initialised at 0x3ffe4350
D (704) intr_alloc: Connected src 16 to int 12 (cpu 0)
D (804) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 8 bit
D (804) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 0 bit
D (804) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 24 bit
D (804) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 16 bit
D (814) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 8 bit
D (824) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 0 bit
D (834) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 16 bit
I (00:00:00.653) board: Board MAC 0xC098631C5210
I (00:00:00.659) gpio: GPIO[21]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (00:00:00.669) board: Initialized LED at GPIO 21
D (854) intr_alloc: Connected src 22 to int 23 (cpu 0)
I (00:00:00.679) sdcard: Mounting SD MMC...
D (00:00:00.684) sdmmc_periph: peripheral version 5342270a, hardware config 03c44c83
D (874) intr_alloc: Connected src 37 to int 13 (cpu 0)
D (00:00:00.697) sdmmc_periph: slot=1 host_div=10 card_div=20 freq=400kHz
D (00:00:00.704) sdmmc_periph: slot=1 width=1
D (00:00:00.709) sdmmc_req: process_command_response: error 0x107  (status=00000100)
D (00:00:00.736) sdmmc_sd: SDHC/SDXC card
D (00:00:00.737) sdmmc_req: process_command_response: error 0x107  (status=00000100)
D (00:00:00.737) sdmmc_io: sdmmc_init_io: io_send_op_cond (1) returned 0x107; not IO card
D (00:00:00.756) sdmmc_common: host_ocr=0x40ff8000 card_ocr=0xc0ff8000
D (00:00:00.756) sdmmc_common: sdmmc_card_init: host_ocr=40ff8000, card_ocr=c0ff8000
D (00:00:00.762) sdmmc_init: sdmmc_card_init: card type is SD
D (00:00:00.776) sdmmc_common: sdmmc_init_host_bus_width: using 1-bit bus
D (00:00:00.778) sdmmc_common: sdmmc_init_host_frequency: using 40000 kHz bus frequency
D (00:00:00.782) sdmmc_periph: slot=1 host_div=4 card_div=0 freq=40000kHz
D (00:00:00.790) vfs_fat_sdmmc: using pdrv=0
I (00:00:00.796) sdcard: SD card mounted at /sd
Name: SD16G
Type: SDHC/SDXC
Speed: 40 MHz
Size: 14916MB
CSD: ver=2, sector_size=512, capacity=30547968 read_bl_len=9
SSR: bus_width=1
Free: 13086MB
D (994) intr_alloc: Connected src 49 to int 17 (cpu 0)
I (00:00:00.817) main: I2C0 initialized, clk=400000
I (00:00:00.823) uart: queue free spaces: 10
D (1014) intr_alloc: Connected src 35 to int 18 (cpu 0)
D (00:00:00.926) mcpwm: new group(0) at 0x3ffc8f4c
D (00:00:00.926) mcpwm: new capture timer at 0x3ffc8e7c, in group (0)
I (00:00:00.926) syncman: >>> syncman_mcpwm_enable ENTER
I (00:00:00.932) gpio: GPIO[18]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 1| Intr:0 
D (00:00:00.942) mcpwm: new capture channel (0,0) at 0x3ffc8fa0
I (00:00:00.948) gpio: GPIO[22]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
D (00:00:00.958) mcpwm: new capture channel (0,1) at 0x3ffc8fc0
I (00:00:00.964) GPS: gps_uart_task started
D (2144) intr_alloc: get_available_int: try to find existing. Cpu: 0, Source: 39
D (2144) intr_alloc: get_free_int: start looking. Current cpu: 0
D (2144) intr_alloc: Int 0 reserved 2 priority 1 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: Int 1 reserved 2 priority 1 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: Int 2 reserved 0 priority 1 LEVEL hasIsr 1
D (2144) intr_alloc: ....Unusable: already in (non-shared) use.
D (2144) intr_alloc: Int 3 reserved 0 priority 1 LEVEL hasIsr 1
D (2144) intr_alloc: ....Unusable: already in (non-shared) use.
D (2144) intr_alloc: Int 4 reserved 2 priority 1 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: Int 5 reserved 2 priority 1 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: Int 6 reserved 2 priority 1 EDGE hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: Int 7 reserved 0 priority 1 EDGE hasIsr 0
D (2144) intr_alloc: ....Unusable: special-purpose int
D (2144) intr_alloc: Int 8 reserved 2 priority 1 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: Int 9 reserved 0 priority 1 LEVEL hasIsr 1
D (2144) intr_alloc: ....Unusable: already in (non-shared) use.
D (2144) intr_alloc: Int 10 reserved 0 priority 1 EDGE hasIsr 0
D (2144) intr_alloc: ....Unusable: incompatible trigger type
D (2144) intr_alloc: Int 11 reserved 0 priority 3 EDGE hasIsr 0
D (2144) intr_alloc: ....Unusable: special-purpose int
D (2144) intr_alloc: Int 12 reserved 0 priority 1 LEVEL hasIsr 1
D (2144) intr_alloc: ....Unusable: already in (non-shared) use.
D (2144) intr_alloc: Int 13 reserved 0 priority 1 LEVEL hasIsr 1
D (2144) intr_alloc: ....Unusable: already in (non-shared) use.
D (2144) intr_alloc: Int 14 reserved 2 priority 7 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: Int 15 reserved 0 priority 3 EDGE hasIsr 0
D (2144) intr_alloc: ....Unusable: special-purpose int
D (2144) intr_alloc: Int 16 reserved 0 priority 5 EDGE hasIsr 0
D (2144) intr_alloc: ....Unusable: special-purpose int
D (2144) intr_alloc: Int 17 reserved 0 priority 1 LEVEL hasIsr 1
D (2144) intr_alloc: ....Unusable: already in (non-shared) use.
D (2144) intr_alloc: Int 18 reserved 0 priority 1 LEVEL hasIsr 1
D (2144) intr_alloc: ....Unusable: already in (non-shared) use.
D (2144) intr_alloc: Int 19 reserved 0 priority 2 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: incompatible priority
D (2144) intr_alloc: Int 20 reserved 0 priority 2 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: incompatible priority
D (2144) intr_alloc: Int 21 reserved 0 priority 2 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: incompatible priority
D (2144) intr_alloc: Int 22 reserved 2 priority 3 EDGE hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: Int 23 reserved 0 priority 3 LEVEL hasIsr 1
D (2144) intr_alloc: ....Unusable: incompatible priority
D (2144) intr_alloc: Int 24 reserved 2 priority 4 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: Int 25 reserved 2 priority 4 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: Int 26 reserved 0 priority 5 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: incompatible priority
D (2144) intr_alloc: Int 27 reserved 2 priority 3 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: Int 28 reserved 0 priority 4 EDGE hasIsr 0
D (2144) intr_alloc: ....Unusable: incompatible priority
D (2144) intr_alloc: Int 29 reserved 0 priority 3 EDGE hasIsr 0
D (2144) intr_alloc: ....Unusable: special-purpose int
D (2144) intr_alloc: Int 30 reserved 2 priority 4 EDGE hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: Int 31 reserved 2 priority 5 LEVEL hasIsr 0
D (2144) intr_alloc: ....Unusable: reserved
D (2144) intr_alloc: get_available_int: using int -1
E (00:00:02.317) mcpwm: mcpwm_capture_channel_register_event_callbacks(322): install interrupt service for cap channel failed
ESP_ERROR_CHECK failed: esp_err_t 0x105 (ESP_ERR_NOT_FOUND) at 0x400d75d1
0x400d75d1: syncman_mcpwm_enable at /home/dizcza/Projects/Embedded/eclipse-workspace/esp32-sdpsensor/main/syncman.c:619

file: "./main/syncman.c" line 619
func: syncman_mcpwm_enable
expression: mcpwm_capture_channel_register_event_callbacks(shandle->channel_gps, &cbs, (void*) shandle)

abort() was called at PC 0x40088fcb on core 0
0x40088fcb: _esp_error_check_failed at /home/dizcza/tools/esp-idf/components/esp_system/esp_err.c:47

Backtrace: 0x40081fde:0x3ffc7f40 0x40088fd5:0x3ffc7f60 0x4008eade:0x3ffc7f80 0x40088fcb:0x3ffc7ff0 0x400d75d1:0x3ffc8020 0x400d7ae5:0x3ffc8060
0x40081fde: panic_abort at /home/dizcza/tools/esp-idf/components/esp_system/panic.c:412

0x40088fd5: esp_system_abort at /home/dizcza/tools/esp-idf/components/esp_system/esp_system.c:135

0x4008eade: abort at /home/dizcza/tools/esp-idf/components/newlib/abort.c:38

0x40088fcb: _esp_error_check_failed at /home/dizcza/tools/esp-idf/components/esp_system/esp_err.c:47

0x400d75d1: syncman_mcpwm_enable at /home/dizcza/Projects/Embedded/eclipse-workspace/esp32-sdpsensor/main/syncman.c:619

0x400d7ae5: syncman_task at /home/dizcza/Projects/Embedded/eclipse-workspace/esp32-sdpsensor/main/syncman.c:951

Update 1

If I call gps_init after I initialize MCPWM and enable it,

static void syncman_task() {
    syncman_handle_t *shandle = &m_synchandle;
    syncman_mcpwm_init(shandle);
    syncman_mcpwm_enable(shandle);
    gps_init();
}

everything works fine.

Update 2

However, if I enable & disable MCPWM, the error appears again.


static void syncman_mcpwm_disable(syncman_handle_t *shandle) {
    ESP_ERROR_CHECK(mcpwm_del_capture_channel(shandle->channel_gps));
    ESP_ERROR_CHECK(mcpwm_del_capture_channel(shandle->channel_rtc));
    ESP_ERROR_CHECK(mcpwm_capture_timer_stop(shandle->cap_timer));
}

static void syncman_task() {
    syncman_handle_t *shandle = &m_synchandle;
    syncman_mcpwm_init(shandle);
    syncman_mcpwm_enable(shandle);
    syncman_mcpwm_disable(shandle);
    gps_init();
    syncman_mcpwm_enable(shandle);  //!<<< HERE IT FAILS
}

Legacy MCPWM code

For the reference, the legacy code I'm porting is

#define GPS_CAP_CHANNEL               MCPWM_SELECT_CAP0
#define RTC_CAP_CHANNEL               MCPWM_SELECT_CAP1
#define SYNCMAN_MCPWM_UNIT            MCPWM_UNIT_0

static void syncman_mcpwm_enable(syncman_handle_t *shandle) {
    cap_isr_cb_t callback = ...;
    mcpwm_capture_config_t gps_cap_conf = {
        .cap_edge = MCPWM_POS_EDGE,
        .cap_prescale = 1,
        .capture_cb = callback,
    };
    ESP_ERROR_CHECK(mcpwm_capture_enable_channel(SYNCMAN_MCPWM_UNIT, GPS_CAP_CHANNEL, &gps_cap_conf));
    mcpwm_capture_config_t rtc_cap_conf = {
        .cap_edge = MCPWM_NEG_EDGE,
        .cap_prescale = 1,
        .capture_cb = callback,
    };
    ESP_ERROR_CHECK(mcpwm_capture_enable_channel(SYNCMAN_MCPWM_UNIT, RTC_CAP_CHANNEL, &rtc_cap_conf));
}

static void syncman_mcpwm_disable(syncman_handle_t *shandle) {
    mcpwm_capture_disable_channel(SYNCMAN_MCPWM_UNIT, GPS_CAP_CHANNEL);
    mcpwm_capture_disable_channel(SYNCMAN_MCPWM_UNIT, RTC_CAP_CHANNEL);
}

And it's very annoying to see logs flooded with GPIO messages each time I "enable" and "disable" the new mcpwm_cap driver. I'll perhaps open a discussion on this matter later on to avoid calling mcpwm_new_capture_channel and mcpwm_del_capture_channel explicitly as the documentation suggests at the moment.

static void syncman_reset(syncman_handle_t *shandle) {
    // each call of syncman_reset prints 4 GPIO logs now
    syncman_mcpwm_disable(shandle);
    syncman_mcpwm_enable(shandle);
}

------

I (00:00:01.553) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (00:00:01.561) gpio: GPIO[22]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (00:00:01.571) gpio: GPIO[18]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 1| Intr:0 
I (00:00:01.581) gpio: GPIO[22]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (00:00:02.590) syncman: syncman_mcpwm_enable OK
I (00:00:02.850) syncman: syncman reset
I (00:00:02.853) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (00:00:02.857) gpio: GPIO[22]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (00:00:02.867) gpio: GPIO[18]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 1| Intr:0 
I (00:00:02.877) gpio: GPIO[22]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (00:00:03.880) syncman: syncman_mcpwm_enable OK
I (00:00:03.980) syncman: syncman reset
I (00:00:03.983) syncman: GPS validity gained
I (00:00:03.987) syncman: GPS 1659899506, RTC 1659899506 s
I (00:00:03.991) syncman: RTC set time skipped
I (00:00:03.995) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (00:00:04.005) gpio: GPIO[22]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (00:00:04.013) gpio: GPIO[18]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 1| Intr:0 
I (00:00:04.023) gpio: GPIO[22]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (00:00:05.030) syncman: syncman_mcpwm_enable OK

Other items if possible

sdkconfig.txt

suda-morris commented 2 years ago

@dizcza Thanks for the detailed debug log, could you help to check if the following fix can help?

diff --git a/components/driver/mcpwm/mcpwm_private.h b/components/driver/mcpwm/mcpwm_private.h
index b5881280f8..eb176fc29e 100644
--- a/components/driver/mcpwm/mcpwm_private.h
+++ b/components/driver/mcpwm/mcpwm_private.h
@@ -29,9 +29,9 @@ extern "C" {
 #endif

 #if CONFIG_MCPWM_ISR_IRAM_SAFE
-#define MCPWM_INTR_ALLOC_FLAG     (ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM)
+#define MCPWM_INTR_ALLOC_FLAG     (ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM)
 #else
-#define MCPWM_INTR_ALLOC_FLAG     (ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_INTRDISABLED)
+#define MCPWM_INTR_ALLOC_FLAG     (ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_INTRDISABLED)
 #endif

 #define MCPWM_PERIPH_CLOCK_PRE_SCALE (2)
dizcza commented 2 years ago

@dizcza Thanks for the detailed debug log, could you help to check if the following fix can help?

diff --git a/components/driver/mcpwm/mcpwm_private.h b/components/driver/mcpwm/mcpwm_private.h
index b5881280f8..eb176fc29e 100644
--- a/components/driver/mcpwm/mcpwm_private.h
+++ b/components/driver/mcpwm/mcpwm_private.h
@@ -29,9 +29,9 @@ extern "C" {
 #endif

 #if CONFIG_MCPWM_ISR_IRAM_SAFE
-#define MCPWM_INTR_ALLOC_FLAG     (ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM)
+#define MCPWM_INTR_ALLOC_FLAG     (ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM)
 #else
-#define MCPWM_INTR_ALLOC_FLAG     (ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_INTRDISABLED)
+#define MCPWM_INTR_ALLOC_FLAG     (ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_INTRDISABLED)
 #endif

 #define MCPWM_PERIPH_CLOCK_PRE_SCALE (2)

Yes, the fix solves the issue. Checked for both options for the CONFIG_MCPWM_ISR_IRAM_SAFE.