Skip to content

Commit 00372dd

Browse files
Raffael Rostagnodanieldegrasse
authored andcommitted
drivers: pwm: ledc: esp32: Enable RC_FAST clock source
RC_FAST needs to be enabled and calibrated in order to be used as clock source. Otherwise, clock source is selected but no PWM is generated. Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
1 parent 709a373 commit 00372dd

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

drivers/pwm/pwm_led_esp32.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <hal/ledc_hal.h>
1111
#include <hal/ledc_types.h>
1212
#include <esp_clk_tree.h>
13+
#include <soc/rtc.h>
14+
#include <clk_ctrl_os.h>
1315

1416
#include <soc.h>
1517
#include <errno.h>
@@ -150,10 +152,20 @@ static int pwm_led_esp32_timer_config(struct pwm_ledc_esp32_channel_config *chan
150152
* Try each clock source available depending on the device and channel type.
151153
*/
152154
for (int i = 0; i < clock_src_num; i++) {
153-
channel->clock_src = clock_src[i];
154-
esp_clk_tree_src_get_freq_hz(channel->clock_src,
155-
ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED,
156-
&channel->clock_src_hz);
155+
if (clock_src[i] == LEDC_SLOW_CLK_RC_FAST) {
156+
/* RC_FAST requires enabling and calibrating */
157+
if (!rtc_dig_8m_enabled() && !periph_rtc_dig_clk8m_enable()) {
158+
/* skip RC_FAST as clock source */
159+
continue;
160+
}
161+
channel->clock_src = clock_src[i];
162+
channel->clock_src_hz = periph_rtc_dig_clk8m_get_freq();
163+
} else {
164+
channel->clock_src = clock_src[i];
165+
esp_clk_tree_src_get_freq_hz(channel->clock_src,
166+
ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED,
167+
&channel->clock_src_hz);
168+
}
157169
if (!pwm_led_esp32_calculate_max_resolution(channel)) {
158170
return 0;
159171
}

0 commit comments

Comments
 (0)