Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run MCPWM and GPIO ISR on the same pin (IDFGH-14058) #14877

Closed
3 tasks done
dizcza opened this issue Nov 13, 2024 · 2 comments
Closed
3 tasks done

Cannot run MCPWM and GPIO ISR on the same pin (IDFGH-14058) #14877

dizcza opened this issue Nov 13, 2024 · 2 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@dizcza
Copy link
Contributor

dizcza commented Nov 13, 2024

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.1.5-143-gdb1c67632a

Espressif SoC revision.

ESP32

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

Development Kit.

TTGO T8

Power Supply used.

USB

What is the expected behavior?

Both MCPWM and GPIO isr functions are executed.

What is the actual behavior?

Only MCPWM callbacks are called.

Steps to reproduce.

typedef struct {
    int sqw_pin;
    time_t time_started;
    int64_t systick;
    int64_t counter;
    QueueHandle_t xQueueRTCTick;
} rtcm_sync_t;

static rtcm_sync_t m_rtcm_sync = { 0 };

static void IRAM_ATTR rtcm_sync_clbk(void *args) {
    m_rtcm_sync.counter++;
    const int64_t t_curr = esp_timer_get_time();
    const syncpoint_t rtc_syncpoint = {
            .time_utc = m_rtcm_sync.time_started + m_rtcm_sync.counter,
            .systick = t_curr,
    };
    xQueueGenericSendFromISR(m_rtcm_sync.xQueueRTCTick, &rtc_syncpoint, NULL, 
}

static bool IRAM_ATTR syncman_mcpwm_callback_1hz(
        mcpwm_cap_channel_handle_t cap_channel,
        const mcpwm_capture_event_data_t *edata,
        void *user_data) {
    syncman_handle_t *shandle = (syncman_handle_t*) user_data;
    BaseType_t task_woken = pdFALSE;

    xQueueSendFromISR(shandle->xQueueRTCPulses, &edata->cap_value, &task_woken);

    return task_woken == pdTRUE;
}


static esp_err_t syncman_mcpwm_enable(syncman_handle_t *shandle) {
    mcpwm_capture_event_callbacks_t cbs = {
        .on_cap = syncman_mcpwm_callback_1hz,
    };
    BSP_SOFTCHECK(mcpwm_capture_channel_register_event_callbacks(shandle->channel_rtc, &cbs, (void*) shandle));
    BSP_SOFTCHECK(mcpwm_capture_channel_enable(shandle->channel_rtc));
    BSP_SOFTCHECK(mcpwm_capture_timer_enable(shandle->cap_timer));
    BSP_SOFTCHECK(mcpwm_capture_timer_start(shandle->cap_timer));
    return ESP_OK;
}


static esp_err_t syncman_mcpwm_start(syncman_handle_t *shandle) {
    mcpwm_capture_timer_config_t cap_timer_conf;
    memset(&cap_timer_conf, 0, sizeof(mcpwm_capture_timer_config_t));
    cap_timer_conf.clk_src = MCPWM_CAPTURE_CLK_SRC_DEFAULT;
    cap_timer_conf.group_id = 0;
    BSP_SOFTCHECK(mcpwm_new_capture_timer(&cap_timer_conf, &shandle->cap_timer));

    mcpwm_capture_channel_config_t chan_rtc_conf;
    memset(&chan_rtc_conf, 0, sizeof(mcpwm_capture_channel_config_t));
    chan_rtc_conf.gpio_num = shandle->rtc_pin;
    chan_rtc_conf.prescale = 1;
    chan_rtc_conf.flags.keep_io_conf_at_exit = true;  // don't reset RTC SQW GPIO
    
    chan_rtc_conf.flags.neg_edge = false;
    chan_rtc_conf.flags.pos_edge = true;
    chan_rtc_conf.flags.pull_up = false;
    chan_rtc_conf.flags.pull_down = false;  // external

    BSP_SOFTCHECK(mcpwm_new_capture_channel(shandle->cap_timer, &chan_rtc_conf, &shandle->channel_rtc));

    syncman_mcpwm_enable(shandle);

    return ESP_OK;
}


...

syncman_mcpwm_start();
ESP_ERROR_CHECK(gpio_isr_handler_add(m_rtcm_sync.sqw_pin, rtcm_sync_clbk, NULL));

The m_rtcm_sync.counter is always zero unless I don't start the MCPWM.

Debug Logs.

No response

More Information.

What's the purpose of keep_io_conf_at_exit if other GPIO ISR callbacks connected to this GPIO pin are not called even when MCPWM is working...

The behavior seems to be the same at least for one year.

@dizcza dizcza added the Type: Bug bugs in IDF label Nov 13, 2024
@dizcza
Copy link
Contributor Author

dizcza commented Nov 13, 2024

In case it helps, sdkconfig.txt

@github-actions github-actions bot changed the title Cannot run MCPWM and GPIO ISR on the same pin Cannot run MCPWM and GPIO ISR on the same pin (IDFGH-14058) Nov 13, 2024
@espressif-bot espressif-bot added the Status: Opened Issue is new label Nov 13, 2024
@dizcza
Copy link
Contributor Author

dizcza commented Nov 13, 2024

Didn't know that after I gpio_isr_handler_remove I need to gpio_config prior to gpio_isr_handler_add. Strangely, no error was thrown - ESP_ERROR_CHECK guard didn't work.

Now it works as expectd.

@dizcza dizcza closed this as completed Nov 13, 2024
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Opened Issue is new labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

2 participants