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

LEDC: Failed to configure timer: ESP_ERR_INVALID_STATE (IDFGH-14812) #15543

Open
ravencarcass opened this issue Mar 9, 2025 · 1 comment
Open
Labels
Status: Opened Issue is new

Comments

@ravencarcass
Copy link

Hello,
I've a problem with the LEDC. I've copied the timer configuration from a simple example but gave me some troubles. While testing it gave it this error;

E (635) ledc: ledc_timer_del(736): LEDC is not initialized
E (645) LEDC: Failed to configure timer: ESP_ERR_INVALID_STATE

The piece of code that results in a error

    ledc_timer_config_t timer;
        timer.speed_mode         = LEDC_MODE;
        timer.timer_num          = LEDC_TIMER;
        timer.freq_hz            = LEDC_FREQUENCY;
        timer.duty_resolution    = LEDC_TIMER_8_BIT;
        timer.clk_cfg            = LEDC_AUTO_CLK;
    esp_err_t retT = ledc_timer_config(&timer);

    if (retT != ESP_OK) {
        ESP_LOGE("LEDC", "Failed to configure timer: %s", esp_err_to_name(retT));
        return;
    }
    
    ledc_channel_config_t channel;
        channel.gpio_num       = LEDC_OUTPUT_IO;
        channel.speed_mode     = LEDC_MODE;
        channel.channel        = LEDC_CHANNEL;
        channel.intr_type      = LEDC_INTR_DISABLE;
        channel.timer_sel      = LEDC_TIMER;
        channel.duty           = LEDC_DUTY;
        channel.hpoint         = 0;
        esp_err_t ret = ledc_channel_config(&channel);

    if (ret != ESP_OK) {
        ESP_LOGE("LEDC", "Failed to configure channel: %s", esp_err_to_name(ret));
        return;
    }
@espressif-bot espressif-bot added the Status: Opened Issue is new label Mar 9, 2025
@github-actions github-actions bot changed the title LEDC: Failed to configure timer: ESP_ERR_INVALID_STATE LEDC: Failed to configure timer: ESP_ERR_INVALID_STATE (IDFGH-14812) Mar 9, 2025
@wanckl
Copy link
Collaborator

wanckl commented Mar 10, 2025

@ravencarcass see the log, you calling ledc_timer_config -> ledc_timer_del(736), menas you set the timer_conf->deconfigure

review your code, ledc_timer_config_t timer; define it without clean all to zero can leader to the resoult.

I guess at first you copy the code the following lines should decorated in a {},

    ledc_timer_config_t timer = {
        timer.speed_mode         = LEDC_MODE,
        timer.timer_num          = LEDC_TIMER,
        timer.freq_hz            = LEDC_FREQUENCY,
        timer.duty_resolution    = LEDC_TIMER_8_BIT,
        timer.clk_cfg            = LEDC_AUTO_CLK,
    };

This way the compiler will help clean the unused members.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new
Projects
None yet
Development

No branches or pull requests

3 participants