espressif / esp-idf

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

esp32c6-Unable to continuously generate LED PWM in light sleep mode. (IDFGH-12713) #13698

Open hiroshi3117 opened 2 weeks ago

hiroshi3117 commented 2 weeks ago

Answers checklist.

General issue report

Hi, I based it on "led_basic_example" and added "esp_light_sleep_start" function. But when entering light sleep, LED PWM stops generating. I referred to some similar questions and added the following settings before entering light sleep:

  1. clock source select "RC_FAST"
  2. esp_sleep_pd_config(ESP_PD_DOMAIN_RC_FAST, ESP_PD_OPTION_ON);
  3. gpio_sleep_sel_dis(LEDC_OUTPUT_IO);

However, PWM generation cannot be maintained during light sleep. I'm not sure what settings I'm missing in my program that would help me solve this problem. Thanks!

IDF version: (master)5.4.0 Development board: ESP32-C6-DevKitM-1 Development Platform: Windows, VS Code Below are the programs I use.

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/ledc.h"
#include "esp_err.h"
#include "esp_sleep.h"

#define LEDC_TIMER              LEDC_TIMER_0
#define LEDC_MODE               LEDC_LOW_SPEED_MODE
#define LEDC_OUTPUT_IO          (7) // Define the output GPIO
#define LEDC_CHANNEL            LEDC_CHANNEL_0
#define LEDC_DUTY_RES           LEDC_TIMER_10_BIT 
#define LEDC_DUTY               (16) 
#define LEDC_FREQUENCY          (4000) 

static void example_ledc_init(void)
{
    // Prepare and then apply the LEDC PWM timer configuration
    ledc_timer_config_t ledc_timer = {
        .speed_mode       = LEDC_MODE,
        .duty_resolution  = LEDC_DUTY_RES,
        .timer_num        = LEDC_TIMER,
        .freq_hz          = LEDC_FREQUENCY,  
        .clk_cfg          = LEDC_USE_RC_FAST_CLK
    };
    ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));

    // Prepare and then apply the LEDC PWM channel configuration
    ledc_channel_config_t ledc_channel = {
        .speed_mode     = LEDC_MODE,
        .channel        = LEDC_CHANNEL,
        .timer_sel      = LEDC_TIMER,
        .intr_type      = LEDC_INTR_DISABLE,
        .gpio_num       = LEDC_OUTPUT_IO,
        .duty           = 0, 
        .hpoint         = 0
    };
    ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
}

static void ledc_task(void *args)
{
    // Set the LEDC peripheral configuration
    example_ledc_init();
    ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
    ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));

    esp_sleep_pd_config(ESP_PD_DOMAIN_RC_FAST, ESP_PD_OPTION_ON);
    gpio_sleep_sel_dis(LEDC_OUTPUT_IO); 

    while(1) 
    {
        printf("Entering light sleep\n");
         /* Enter sleep mode */
        esp_light_sleep_start();
        vTaskDelay(100/portTICK_PERIOD_MS);
    }
}

void app_main(void)
{
    xTaskCreate(ledc_task, "ledc_task", 4096, NULL, 6, NULL);
}
hiroshi3117 commented 2 weeks ago

Additional my configuration files .

hiroshi3117 commented 1 week ago

I referred to the following post and tested it,but still not work. https://github.com/espressif/arduino-esp32/issues/3534 https://github.com/espressif/esp-idf/issues/12188

Is there any Espressif engineer who can provide a sample program for ESP32-C6 to continuously generate LEDC PWM in light sleep mode for my reference? Thanks.

songruo commented 1 week ago

Hi @hiroshi3117,

Yes, this feature has not yet been supported on C6/H2. Please hang on with us for a few days, I will do some update or give you a workaround as soon as possible.

hiroshi3117 commented 1 week ago

Hi @songruo , Thanks for your reply. My product is about to be mass-produced in the 3Q. If PWM cannot be continuously output in power saving mode, it will cause great trouble to battery life. Please provide this workaround as soon as possible. Thank you very much.