Skip to content

Commit bc48639

Browse files
authored
Add support for PLL_F48M UART clock source on ESP32-H2 (#569)
ESP32-H2 uses PLL_F48M as the default UART clock source, but this was not supported by the HAL, causing panics during UART initialization. This adds PLL_F48M to the SourceClock enum and implements all necessary conversions. The new clock source is conditionally compiled only for chips that don't have other specific clock support flags (currently ESP32-H2). Fixes UART initialization panics on ESP32-H2 with ESP-IDF 5.x.
1 parent 4efb420 commit bc48639

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3838
- Support for esp32c5 and esp32c61
3939
- Removed the modem peripheral for esp32p4
4040
- LDO support for esp32p4
41+
- Support for `PLL_F48M` UART clock source on ESP32-H2
4142

4243
### Fixed
4344
- Fix pcnt_rotary_encoder example for esp32
4445
- Fix the SDMMC driver for ESP-IDF V5.5+
46+
- Fix UART initialization panic on ESP32-H2 with ESP-IDF 5.x due to unsupported `PLL_F48M` clock source
4547
- Replace Arc with Rc in ledc_threads example (#514)
4648
- Fix outdated task docs
4749
- CAN: fix wrong Alert enum indexing / remove wrong TryFromPrimitive derive (#532)

src/uart.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,20 @@ pub mod config {
243243
/// UART source clock from `XTAL`
244244
#[cfg(esp_idf_soc_uart_support_xtal_clk)]
245245
Crystal,
246-
/// UART source clock from `XTAL`
246+
/// UART source clock from `PLL_F80M`
247247
#[allow(non_camel_case_types)]
248248
#[cfg(esp_idf_soc_uart_support_pll_f80m_clk)]
249249
PLL_F80M,
250+
/// UART source clock from `PLL_F48M` (ESP32-H2)
251+
#[allow(non_camel_case_types)]
252+
#[cfg(not(any(
253+
esp_idf_soc_uart_support_apb_clk,
254+
esp_idf_soc_uart_support_pll_f40m_clk,
255+
esp_idf_soc_uart_support_pll_f80m_clk,
256+
esp_idf_soc_uart_support_ref_tick,
257+
esp_idf_version_major = "4"
258+
)))]
259+
PLL_F48M,
250260
/// UART source clock from `REF_TICK`
251261
#[cfg(esp_idf_soc_uart_support_ref_tick)]
252262
RefTick,
@@ -275,6 +285,14 @@ pub mod config {
275285
XTAL_SCLK => SourceClock::Crystal,
276286
#[cfg(esp_idf_soc_uart_support_pll_f80m_clk)]
277287
PLL_F80M_SCLK => SourceClock::PLL_F80M,
288+
#[cfg(not(any(
289+
esp_idf_soc_uart_support_apb_clk,
290+
esp_idf_soc_uart_support_pll_f40m_clk,
291+
esp_idf_soc_uart_support_pll_f80m_clk,
292+
esp_idf_soc_uart_support_ref_tick,
293+
esp_idf_version_major = "4"
294+
)))]
295+
PLL_F48M_SCLK => SourceClock::PLL_F48M,
278296
#[cfg(esp_idf_soc_uart_support_ref_tick)]
279297
REF_TICK_SCLK => SourceClock::RefTick,
280298
_ => unreachable!(),
@@ -320,6 +338,17 @@ pub mod config {
320338
#[cfg(all(esp_idf_version_major = "4", esp_idf_soc_uart_support_pll_f80m_clk))]
321339
const PLL_F80M_SCLK: uart_sclk_t = uart_sclk_t_UART_SCLK_PLL_F80M;
322340

341+
#[cfg(all(
342+
not(esp_idf_version_major = "4"),
343+
not(any(
344+
esp_idf_soc_uart_support_apb_clk,
345+
esp_idf_soc_uart_support_pll_f40m_clk,
346+
esp_idf_soc_uart_support_pll_f80m_clk,
347+
esp_idf_soc_uart_support_ref_tick
348+
))
349+
))]
350+
const PLL_F48M_SCLK: uart_sclk_t = soc_periph_uart_clk_src_legacy_t_UART_SCLK_PLL_F48M;
351+
323352
#[cfg(all(not(esp_idf_version_major = "4"), esp_idf_soc_uart_support_ref_tick))]
324353
const REF_TICK_SCLK: uart_sclk_t = soc_periph_uart_clk_src_legacy_t_UART_SCLK_REF_TICK;
325354
#[cfg(all(esp_idf_version_major = "4", esp_idf_soc_uart_support_ref_tick))]
@@ -346,6 +375,14 @@ pub mod config {
346375
SourceClock::Crystal => XTAL_SCLK,
347376
#[cfg(esp_idf_soc_uart_support_pll_f80m_clk)]
348377
SourceClock::PLL_F80M => PLL_F80M_SCLK,
378+
#[cfg(not(any(
379+
esp_idf_soc_uart_support_apb_clk,
380+
esp_idf_soc_uart_support_pll_f40m_clk,
381+
esp_idf_soc_uart_support_pll_f80m_clk,
382+
esp_idf_soc_uart_support_ref_tick,
383+
esp_idf_version_major = "4"
384+
)))]
385+
SourceClock::PLL_F48M => PLL_F48M_SCLK,
349386
#[cfg(esp_idf_soc_uart_support_ref_tick)]
350387
SourceClock::RefTick => REF_TICK_SCLK,
351388
}

0 commit comments

Comments
 (0)