@@ -153,13 +153,19 @@ static int pwm_led_esp32_timer_config(struct pwm_ledc_esp32_channel_config *chan
153
153
*/
154
154
for (int i = 0 ; i < clock_src_num ; i ++ ) {
155
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 ;
156
+ uint32_t rc_fast_freq = periph_rtc_dig_clk8m_get_freq ();
157
+
158
+ if (!rtc_dig_8m_enabled () || rc_fast_freq == 0 ) {
159
+ /* RC_FAST requires enabling and calibrating */
160
+ if (!periph_rtc_dig_clk8m_enable ()) {
161
+ /* skip RC_FAST as clock source */
162
+ continue ;
163
+ }
164
+ rc_fast_freq = periph_rtc_dig_clk8m_get_freq ();
160
165
}
166
+
161
167
channel -> clock_src = clock_src [i ];
162
- channel -> clock_src_hz = periph_rtc_dig_clk8m_get_freq () ;
168
+ channel -> clock_src_hz = rc_fast_freq ;
163
169
} else {
164
170
channel -> clock_src = clock_src [i ];
165
171
esp_clk_tree_src_get_freq_hz (channel -> clock_src ,
@@ -198,12 +204,27 @@ static int pwm_led_esp32_timer_set(const struct device *dev,
198
204
}
199
205
200
206
if (channel -> speed_mode == LEDC_LOW_SPEED_MODE ) {
201
- ledc_hal_set_slow_clk_sel (& data -> hal , channel -> clock_src );
207
+ #if SOC_LEDC_SUPPORT_REF_TICK
208
+ /* When the source clock of LOW_SPEED timer is timer-specific
209
+ * (REF_TICK), global clock MUST be set to APB_CLK.
210
+ */
211
+ ledc_clk_src_t global_clk = channel -> clock_src == LEDC_REF_TICK
212
+ ? LEDC_SLOW_CLK_APB
213
+ : channel -> clock_src ;
214
+ #else
215
+ ledc_clk_src_t global_clk = channel -> clock_src ;
216
+ #endif
217
+ ledc_hal_set_slow_clk_sel (& data -> hal , global_clk );
202
218
}
203
219
204
220
ledc_hal_set_clock_divider (& data -> hal , channel -> timer_num , prescaler );
205
221
ledc_hal_set_duty_resolution (& data -> hal , channel -> timer_num , channel -> resolution );
206
- ledc_hal_set_clock_source (& data -> hal , channel -> timer_num , channel -> clock_src );
222
+
223
+ #if SOC_LEDC_HAS_TIMER_SPECIFIC_MUX
224
+ ledc_clk_src_t timer_clk =
225
+ channel -> clock_src == LEDC_REF_TICK ? channel -> clock_src : LEDC_SCLK ;
226
+ ledc_hal_set_clock_source (& data -> hal , channel -> timer_num , timer_clk );
227
+ #endif
207
228
208
229
if (channel -> speed_mode == LEDC_LOW_SPEED_MODE ) {
209
230
ledc_hal_ls_timer_update (& data -> hal , channel -> timer_num );
@@ -377,7 +398,9 @@ int pwm_led_esp32_init(const struct device *dev)
377
398
channel -> clock_src = highspd_clks [0 ];
378
399
}
379
400
#endif
401
+ #if SOC_LEDC_HAS_TIMER_SPECIFIC_MUX
380
402
ledc_hal_set_clock_source (& data -> hal , channel -> timer_num , channel -> clock_src );
403
+ #endif
381
404
382
405
esp_clk_tree_src_get_freq_hz (channel -> clock_src ,
383
406
ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED ,
0 commit comments