diff --git a/components/driver/test_apps/uart/main/test_app_main.c b/components/driver/test_apps/uart/main/test_app_main.c index c1070bd94d..5db843a059 100644 --- a/components/driver/test_apps/uart/main/test_app_main.c +++ b/components/driver/test_apps/uart/main/test_app_main.c @@ -10,7 +10,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#define TEST_MEMORY_LEAK_THRESHOLD (200) +#define TEST_MEMORY_LEAK_THRESHOLD (250) static size_t before_free_8bit; static size_t before_free_32bit; diff --git a/components/driver/uart/include/driver/uart.h b/components/driver/uart/include/driver/uart.h index dbf93da299..502012d53d 100644 --- a/components/driver/uart/include/driver/uart.h +++ b/components/driver/uart/include/driver/uart.h @@ -214,7 +214,7 @@ esp_err_t uart_get_sclk_freq(uart_sclk_t sclk, uint32_t* out_freq_hz); * @param baudrate UART baud rate. * * @return - * - ESP_FAIL Parameter error + * - ESP_FAIL Parameter error, such as baud rate unachievable * - ESP_OK Success */ esp_err_t uart_set_baudrate(uart_port_t uart_num, uint32_t baudrate); @@ -444,7 +444,7 @@ esp_err_t uart_set_tx_idle_num(uart_port_t uart_num, uint16_t idle_num); * * @return * - ESP_OK Success - * - ESP_FAIL Parameter error + * - ESP_FAIL Parameter error, such as baud rate unachievable */ esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_config); diff --git a/components/driver/uart/uart.c b/components/driver/uart/uart.c index 7db7ee7e1c..27d56b3658 100644 --- a/components/driver/uart/uart.c +++ b/components/driver/uart/uart.c @@ -278,9 +278,11 @@ esp_err_t uart_set_baudrate(uart_port_t uart_num, uint32_t baud_rate) uart_hal_get_sclk(&(uart_context[uart_num].hal), &src_clk); ESP_RETURN_ON_ERROR(uart_get_sclk_freq(src_clk, &sclk_freq), UART_TAG, "Invalid src_clk"); + bool success = false; UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock)); - uart_hal_set_baudrate(&(uart_context[uart_num].hal), baud_rate, sclk_freq); + success = uart_hal_set_baudrate(&(uart_context[uart_num].hal), baud_rate, sclk_freq); UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock)); + ESP_RETURN_ON_FALSE(success, ESP_FAIL, UART_TAG, "baud rate unachievable"); return ESP_OK; } @@ -703,10 +705,11 @@ esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_conf uint32_t sclk_freq; ESP_RETURN_ON_ERROR(uart_get_sclk_freq(clk_src, &sclk_freq), UART_TAG, "Invalid src_clk"); + bool success = false; UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock)); uart_hal_init(&(uart_context[uart_num].hal), uart_num); uart_hal_set_sclk(&(uart_context[uart_num].hal), clk_src); - uart_hal_set_baudrate(&(uart_context[uart_num].hal), uart_config->baud_rate, sclk_freq); + success = uart_hal_set_baudrate(&(uart_context[uart_num].hal), uart_config->baud_rate, sclk_freq); uart_hal_set_parity(&(uart_context[uart_num].hal), uart_config->parity); uart_hal_set_data_bit_num(&(uart_context[uart_num].hal), uart_config->data_bits); uart_hal_set_stop_bits(&(uart_context[uart_num].hal), uart_config->stop_bits); @@ -715,6 +718,7 @@ esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_conf UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock)); uart_hal_rxfifo_rst(&(uart_context[uart_num].hal)); uart_hal_txfifo_rst(&(uart_context[uart_num].hal)); + ESP_RETURN_ON_FALSE(success, ESP_FAIL, UART_TAG, "baud rate unachievable"); return ESP_OK; } diff --git a/components/esp_hw_support/port/esp32s2/io_mux.c b/components/esp_hw_support/port/esp32s2/io_mux.c index 4dc0131cf1..979cd55489 100644 --- a/components/esp_hw_support/port/esp32s2/io_mux.c +++ b/components/esp_hw_support/port/esp32s2/io_mux.c @@ -31,6 +31,7 @@ static rtc_io_status_t s_rtc_io_status = { void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable) { + assert(gpio_num != GPIO_NUM_NC); portENTER_CRITICAL(&s_io_mux_spinlock); if (enable) { if (s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] == 0) { @@ -55,6 +56,7 @@ void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable) void io_mux_force_disable_lp_io_clock(gpio_num_t gpio_num) { + assert(gpio_num != GPIO_NUM_NC); portENTER_CRITICAL(&s_io_mux_spinlock); s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] = 0; s_rtc_io_status.rtc_io_using_mask &= ~(1ULL << gpio_num); diff --git a/components/esp_hw_support/port/esp32s3/io_mux.c b/components/esp_hw_support/port/esp32s3/io_mux.c index 4dc0131cf1..979cd55489 100644 --- a/components/esp_hw_support/port/esp32s3/io_mux.c +++ b/components/esp_hw_support/port/esp32s3/io_mux.c @@ -31,6 +31,7 @@ static rtc_io_status_t s_rtc_io_status = { void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable) { + assert(gpio_num != GPIO_NUM_NC); portENTER_CRITICAL(&s_io_mux_spinlock); if (enable) { if (s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] == 0) { @@ -55,6 +56,7 @@ void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable) void io_mux_force_disable_lp_io_clock(gpio_num_t gpio_num) { + assert(gpio_num != GPIO_NUM_NC); portENTER_CRITICAL(&s_io_mux_spinlock); s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] = 0; s_rtc_io_status.rtc_io_using_mask &= ~(1ULL << gpio_num); diff --git a/components/hal/esp32/include/hal/uart_ll.h b/components/hal/esp32/include/hal/uart_ll.h index a3a62fc0eb..25b12cebb7 100644 --- a/components/hal/esp32/include/hal/uart_ll.h +++ b/components/hal/esp32/include/hal/uart_ll.h @@ -88,17 +88,23 @@ FORCE_INLINE_ATTR void uart_ll_get_sclk(uart_dev_t *hw, uart_sclk_t* source_clk) * @param baud The baud-rate to be set. When the source clock is APB, the max baud-rate is `UART_LL_BITRATE_MAX` * @param sclk_freq Frequency of the clock source of UART, in Hz. - * @return None + * @return True if baud-rate set successfully; False if baud-rate requested cannot be achieved */ -FORCE_INLINE_ATTR void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) +FORCE_INLINE_ATTR bool uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) { - uint32_t clk_div; - - clk_div = ((sclk_freq) << 4) / baud; - // The baud-rate configuration register is divided into - // an integer part and a fractional part. - hw->clk_div.div_int = clk_div >> 4; - hw->clk_div.div_frag = clk_div & 0xf; + if (baud == 0) { + return false; + } + uint32_t clk_div = ((sclk_freq) << 4) / baud; + // The baud-rate configuration register is divided into an integer part and a fractional part. + uint32_t clkdiv_int = clk_div >> 4; + if (clkdiv_int > UART_CLKDIV_V) { + return false; // unachievable baud-rate + } + uint32_t clkdiv_frag = clk_div & 0xf; + hw->clk_div.div_int = clkdiv_int; + hw->clk_div.div_frag = clkdiv_frag; + return true; } /** diff --git a/components/hal/esp32c2/include/hal/uart_ll.h b/components/hal/esp32c2/include/hal/uart_ll.h index 2a7e3b257c..0a72e65097 100644 --- a/components/hal/esp32c2/include/hal/uart_ll.h +++ b/components/hal/esp32c2/include/hal/uart_ll.h @@ -152,23 +152,28 @@ FORCE_INLINE_ATTR void uart_ll_get_sclk(uart_dev_t *hw, uart_sclk_t *source_clk) * @param baud The baud rate to be set. * @param sclk_freq Frequency of the clock source of UART, in Hz. * - * @return None + * @return True if baud-rate set successfully; False if baud-rate requested cannot be achieved */ -FORCE_INLINE_ATTR void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) +FORCE_INLINE_ATTR bool uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) { #define DIV_UP(a, b) (((a) + (b) - 1) / (b)) - const uint32_t max_div = BIT(12) - 1; // UART divider integer part only has 12 bits + if (baud == 0) { + return false; + } + const uint32_t max_div = UART_CLKDIV_V; // UART divider integer part only has 12 bits uint32_t sclk_div = DIV_UP(sclk_freq, (uint64_t)max_div * baud); +#undef DIV_UP - if (sclk_div == 0) abort(); + if (sclk_div == 0 || sclk_div > (UART_SCLK_DIV_NUM_V + 1)) { + return false; // unachievable baud-rate + } uint32_t clk_div = ((sclk_freq) << 4) / (baud * sclk_div); - // The baud rate configuration register is divided into - // an integer part and a fractional part. + // The baud rate configuration register is divided into an integer part and a fractional part. hw->clk_div.div_int = clk_div >> 4; hw->clk_div.div_frag = clk_div & 0xf; HAL_FORCE_MODIFY_U32_REG_FIELD(hw->clk_conf, sclk_div_num, sclk_div - 1); -#undef DIV_UP + return true; } /** diff --git a/components/hal/esp32c3/include/hal/uart_ll.h b/components/hal/esp32c3/include/hal/uart_ll.h index a35c5b1792..a3b276edad 100644 --- a/components/hal/esp32c3/include/hal/uart_ll.h +++ b/components/hal/esp32c3/include/hal/uart_ll.h @@ -153,23 +153,28 @@ FORCE_INLINE_ATTR void uart_ll_get_sclk(uart_dev_t *hw, uart_sclk_t *source_clk) * @param baud The baud rate to be set. * @param sclk_freq Frequency of the clock source of UART, in Hz. * - * @return None + * @return True if baud-rate set successfully; False if baud-rate requested cannot be achieved */ -FORCE_INLINE_ATTR void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) +FORCE_INLINE_ATTR bool uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) { #define DIV_UP(a, b) (((a) + (b) - 1) / (b)) - const uint32_t max_div = BIT(12) - 1; // UART divider integer part only has 12 bits + if (baud == 0) { + return false; + } + const uint32_t max_div = UART_CLKDIV_V; // UART divider integer part only has 12 bits uint32_t sclk_div = DIV_UP(sclk_freq, (uint64_t)max_div * baud); +#undef DIV_UP - if (sclk_div == 0) abort(); + if (sclk_div == 0 || sclk_div > (UART_SCLK_DIV_NUM_V + 1)) { + return false; // unachievable baud-rate + } uint32_t clk_div = ((sclk_freq) << 4) / (baud * sclk_div); - // The baud rate configuration register is divided into - // an integer part and a fractional part. + // The baud rate configuration register is divided into an integer part and a fractional part. hw->clk_div.div_int = clk_div >> 4; hw->clk_div.div_frag = clk_div & 0xf; HAL_FORCE_MODIFY_U32_REG_FIELD(hw->clk_conf, sclk_div_num, sclk_div - 1); -#undef DIV_UP + return true; } /** diff --git a/components/hal/esp32c6/include/hal/uart_ll.h b/components/hal/esp32c6/include/hal/uart_ll.h index 99e812b554..f67767a7fb 100644 --- a/components/hal/esp32c6/include/hal/uart_ll.h +++ b/components/hal/esp32c6/include/hal/uart_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -17,6 +17,7 @@ #include "soc/uart_periph.h" #include "soc/uart_struct.h" #include "soc/pcr_struct.h" +#include "soc/pcr_reg.h" #ifdef __cplusplus extern "C" { @@ -185,24 +186,29 @@ FORCE_INLINE_ATTR void uart_ll_get_sclk(uart_dev_t *hw, uart_sclk_t *source_clk) * @param baud The baud rate to be set. * @param sclk_freq Frequency of the clock source of UART, in Hz. * - * @return None + * @return True if baud-rate set successfully; False if baud-rate requested cannot be achieved */ -FORCE_INLINE_ATTR void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) +FORCE_INLINE_ATTR bool uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) { #define DIV_UP(a, b) (((a) + (b) - 1) / (b)) - const uint32_t max_div = BIT(12) - 1; // UART divider integer part only has 12 bits + if (baud == 0) { + return false; + } + const uint32_t max_div = UART_CLKDIV_V; // UART divider integer part only has 12 bits uint32_t sclk_div = DIV_UP(sclk_freq, (uint64_t)max_div * baud); +#undef DIV_UP - if (sclk_div == 0) abort(); + if (sclk_div == 0 || sclk_div > (PCR_UART0_SCLK_DIV_NUM_V + 1)) { + return false; // unachievable baud-rate + } uint32_t clk_div = ((sclk_freq) << 4) / (baud * sclk_div); - // The baud rate configuration register is divided into - // an integer part and a fractional part. + // The baud rate configuration register is divided into an integer part and a fractional part. hw->clkdiv_sync.clkdiv_int = clk_div >> 4; hw->clkdiv_sync.clkdiv_frag = clk_div & 0xf; UART_LL_PCR_REG_U32_SET(hw, sclk_conf, sclk_div_num, sclk_div - 1); -#undef DIV_UP uart_ll_update(hw); + return true; } /** diff --git a/components/hal/esp32h2/include/hal/uart_ll.h b/components/hal/esp32h2/include/hal/uart_ll.h index 98c67ba125..fb9de7049a 100644 --- a/components/hal/esp32h2/include/hal/uart_ll.h +++ b/components/hal/esp32h2/include/hal/uart_ll.h @@ -17,6 +17,7 @@ #include "soc/uart_periph.h" #include "soc/uart_struct.h" #include "soc/pcr_struct.h" +#include "soc/pcr_reg.h" #include "esp_attr.h" #ifdef __cplusplus @@ -186,24 +187,29 @@ FORCE_INLINE_ATTR void uart_ll_get_sclk(uart_dev_t *hw, uart_sclk_t *source_clk) * @param baud The baud rate to be set. * @param sclk_freq Frequency of the clock source of UART, in Hz. * - * @return None + * @return True if baud-rate set successfully; False if baud-rate requested cannot be achieved */ -FORCE_INLINE_ATTR void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) +FORCE_INLINE_ATTR bool uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) { #define DIV_UP(a, b) (((a) + (b) - 1) / (b)) - const uint32_t max_div = BIT(12) - 1; // UART divider integer part only has 12 bits + if (baud == 0) { + return false; + } + const uint32_t max_div = UART_CLKDIV_V; // UART divider integer part only has 12 bits uint32_t sclk_div = DIV_UP(sclk_freq, (uint64_t)max_div * baud); +#undef DIV_UP - if (sclk_div == 0) abort(); + if (sclk_div == 0 || sclk_div > (PCR_UART0_SCLK_DIV_NUM_V + 1)) { + return false; // unachievable baud-rate + } uint32_t clk_div = ((sclk_freq) << 4) / (baud * sclk_div); - // The baud rate configuration register is divided into - // an integer part and a fractional part. + // The baud rate configuration register is divided into an integer part and a fractional part. hw->clkdiv_sync.clkdiv_int = clk_div >> 4; hw->clkdiv_sync.clkdiv_frag = clk_div & 0xf; UART_LL_PCR_REG_U32_SET(hw, sclk_conf, sclk_div_num, sclk_div - 1); -#undef DIV_UP uart_ll_update(hw); + return true; } /** diff --git a/components/hal/esp32s2/include/hal/uart_ll.h b/components/hal/esp32s2/include/hal/uart_ll.h index a3c3486ffe..35674080e9 100644 --- a/components/hal/esp32s2/include/hal/uart_ll.h +++ b/components/hal/esp32s2/include/hal/uart_ll.h @@ -86,17 +86,23 @@ FORCE_INLINE_ATTR void uart_ll_get_sclk(uart_dev_t *hw, uart_sclk_t* source_clk) * @param baud The baud rate to be set. When the source clock is APB, the max baud rate is `UART_LL_BITRATE_MAX` * @param sclk_freq Frequency of the clock source of UART, in Hz. - * @return None + * @return True if baud-rate set successfully; False if baud-rate requested cannot be achieved */ -FORCE_INLINE_ATTR void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) +FORCE_INLINE_ATTR bool uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) { - uint32_t clk_div; - - clk_div = ((sclk_freq) << 4) / baud; - // The baud rate configuration register is divided into - // an integer part and a fractional part. - hw->clk_div.div_int = clk_div >> 4; - hw->clk_div.div_frag = clk_div & 0xf; + if (baud == 0) { + return false; + } + uint32_t clk_div = ((sclk_freq) << 4) / baud; + // The baud-rate configuration register is divided into an integer part and a fractional part. + uint32_t clkdiv_int = clk_div >> 4; + if (clkdiv_int > UART_CLKDIV_V) { + return false; // unachievable baud-rate + } + uint32_t clkdiv_frag = clk_div & 0xf; + hw->clk_div.div_int = clkdiv_int; + hw->clk_div.div_frag = clkdiv_frag; + return true; } /** diff --git a/components/hal/esp32s3/include/hal/uart_ll.h b/components/hal/esp32s3/include/hal/uart_ll.h index a777aa967c..5e8889c7c7 100644 --- a/components/hal/esp32s3/include/hal/uart_ll.h +++ b/components/hal/esp32s3/include/hal/uart_ll.h @@ -125,23 +125,28 @@ FORCE_INLINE_ATTR void uart_ll_get_sclk(uart_dev_t *hw, uart_sclk_t *source_clk) * @param baud The baud rate to be set. * @param sclk_freq Frequency of the clock source of UART, in Hz. * - * @return None + * @return True if baud-rate set successfully; False if baud-rate requested cannot be achieved */ -FORCE_INLINE_ATTR void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) +FORCE_INLINE_ATTR bool uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq) { #define DIV_UP(a, b) (((a) + (b) - 1) / (b)) - const uint32_t max_div = BIT(12) - 1; // UART divider integer part only has 12 bits + if (baud == 0) { + return false; + } + const uint32_t max_div = UART_CLKDIV_V; // UART divider integer part only has 12 bits uint32_t sclk_div = DIV_UP(sclk_freq, (uint64_t)max_div * baud); +#undef DIV_UP - if (sclk_div == 0) abort(); + if (sclk_div == 0 || sclk_div > (UART_SCLK_DIV_NUM_V + 1)) { + return false; // unachievable baud-rate + } uint32_t clk_div = ((sclk_freq) << 4) / (baud * sclk_div); - // The baud rate configuration register is divided into - // an integer part and a fractional part. + // The baud rate configuration register is divided into an integer part and a fractional part. hw->clkdiv.clkdiv = clk_div >> 4; hw->clkdiv.clkdiv_frag = clk_div & 0xf; HAL_FORCE_MODIFY_U32_REG_FIELD(hw->clk_conf, sclk_div_num, sclk_div - 1); -#undef DIV_UP + return true; } /** diff --git a/components/hal/include/hal/uart_hal.h b/components/hal/include/hal/uart_hal.h index 4b073b9a4a..d5ce542611 100644 --- a/components/hal/include/hal/uart_hal.h +++ b/components/hal/include/hal/uart_hal.h @@ -214,9 +214,9 @@ void uart_hal_get_sclk(uart_hal_context_t *hal, uart_sclk_t *sclk); * @param baud_rate The baud-rate to be set * @param sclk_freq Frequency of the clock source of UART, in Hz. * - * @return None + * @return True if baud-rate set successfully; False if baud-rate requested cannot be achieved */ -void uart_hal_set_baudrate(uart_hal_context_t *hal, uint32_t baud_rate, uint32_t sclk_freq); +bool uart_hal_set_baudrate(uart_hal_context_t *hal, uint32_t baud_rate, uint32_t sclk_freq); /** * @brief Configure the UART stop bit diff --git a/components/hal/uart_hal.c b/components/hal/uart_hal.c index 5656b2def9..df69567bfc 100644 --- a/components/hal/uart_hal.c +++ b/components/hal/uart_hal.c @@ -17,9 +17,9 @@ void uart_hal_get_sclk(uart_hal_context_t *hal, uart_sclk_t *sclk) uart_ll_get_sclk(hal->dev, sclk); } -void uart_hal_set_baudrate(uart_hal_context_t *hal, uint32_t baud_rate, uint32_t sclk_freq) +bool uart_hal_set_baudrate(uart_hal_context_t *hal, uint32_t baud_rate, uint32_t sclk_freq) { - uart_ll_set_baudrate(hal->dev, baud_rate, sclk_freq); + return uart_ll_set_baudrate(hal->dev, baud_rate, sclk_freq); } void uart_hal_get_baudrate(uart_hal_context_t *hal, uint32_t *baud_rate, uint32_t sclk_freq) diff --git a/components/soc/esp32c6/include/soc/lp_uart_reg.h b/components/soc/esp32c6/include/soc/lp_uart_reg.h index b67fa1b59e..9d39f04834 100644 --- a/components/soc/esp32c6/include/soc/lp_uart_reg.h +++ b/components/soc/esp32c6/include/soc/lp_uart_reg.h @@ -1235,48 +1235,6 @@ extern "C" { * UART core clock configuration */ #define LP_UART_CLK_CONF_REG (DR_REG_LP_UART_BASE + 0x88) -/** LP_UART_SCLK_DIV_B : R/W; bitpos: [5:0]; default: 0; - * The denominator of the frequency divider factor. - */ -#define LP_UART_SCLK_DIV_B 0x0000003FU -#define LP_UART_SCLK_DIV_B_M (LP_UART_SCLK_DIV_B_V << LP_UART_SCLK_DIV_B_S) -#define LP_UART_SCLK_DIV_B_V 0x0000003FU -#define LP_UART_SCLK_DIV_B_S 0 -/** LP_UART_SCLK_DIV_A : R/W; bitpos: [11:6]; default: 0; - * The numerator of the frequency divider factor. - */ -#define LP_UART_SCLK_DIV_A 0x0000003FU -#define LP_UART_SCLK_DIV_A_M (LP_UART_SCLK_DIV_A_V << LP_UART_SCLK_DIV_A_S) -#define LP_UART_SCLK_DIV_A_V 0x0000003FU -#define LP_UART_SCLK_DIV_A_S 6 -/** LP_UART_SCLK_DIV_NUM : R/W; bitpos: [19:12]; default: 1; - * The integral part of the frequency divider factor. - */ -#define LP_UART_SCLK_DIV_NUM 0x000000FFU -#define LP_UART_SCLK_DIV_NUM_M (LP_UART_SCLK_DIV_NUM_V << LP_UART_SCLK_DIV_NUM_S) -#define LP_UART_SCLK_DIV_NUM_V 0x000000FFU -#define LP_UART_SCLK_DIV_NUM_S 12 -/** LP_UART_SCLK_SEL : R/W; bitpos: [21:20]; default: 3; - * UART clock source select. 1: 80Mhz. 2: 8Mhz. 3: XTAL. - */ -#define LP_UART_SCLK_SEL 0x00000003U -#define LP_UART_SCLK_SEL_M (LP_UART_SCLK_SEL_V << LP_UART_SCLK_SEL_S) -#define LP_UART_SCLK_SEL_V 0x00000003U -#define LP_UART_SCLK_SEL_S 20 -/** LP_UART_SCLK_EN : R/W; bitpos: [22]; default: 1; - * Set this bit to enable UART Tx/Rx clock. - */ -#define LP_UART_SCLK_EN (BIT(22)) -#define LP_UART_SCLK_EN_M (LP_UART_SCLK_EN_V << LP_UART_SCLK_EN_S) -#define LP_UART_SCLK_EN_V 0x00000001U -#define LP_UART_SCLK_EN_S 22 -/** LP_UART_RST_CORE : R/W; bitpos: [23]; default: 0; - * Write 1 then write 0 to this bit to reset UART Tx/Rx. - */ -#define LP_UART_RST_CORE (BIT(23)) -#define LP_UART_RST_CORE_M (LP_UART_RST_CORE_V << LP_UART_RST_CORE_S) -#define LP_UART_RST_CORE_V 0x00000001U -#define LP_UART_RST_CORE_S 23 /** LP_UART_TX_SCLK_EN : R/W; bitpos: [24]; default: 1; * Set this bit to enable UART Tx clock. */ diff --git a/components/soc/esp32c6/include/soc/lp_uart_struct.h b/components/soc/esp32c6/include/soc/lp_uart_struct.h index dfe2da6e3e..420bce4905 100644 --- a/components/soc/esp32c6/include/soc/lp_uart_struct.h +++ b/components/soc/esp32c6/include/soc/lp_uart_struct.h @@ -792,30 +792,7 @@ typedef union { */ typedef union { struct { - /** sclk_div_b : R/W; bitpos: [5:0]; default: 0; - * The denominator of the frequency divider factor. - */ - uint32_t sclk_div_b:6; - /** sclk_div_a : R/W; bitpos: [11:6]; default: 0; - * The numerator of the frequency divider factor. - */ - uint32_t sclk_div_a:6; - /** sclk_div_num : R/W; bitpos: [19:12]; default: 1; - * The integral part of the frequency divider factor. - */ - uint32_t sclk_div_num:8; - /** sclk_sel : R/W; bitpos: [21:20]; default: 3; - * UART clock source select. 1: 80Mhz. 2: 8Mhz. 3: XTAL. - */ - uint32_t sclk_sel:2; - /** sclk_en : R/W; bitpos: [22]; default: 1; - * Set this bit to enable UART Tx/Rx clock. - */ - uint32_t sclk_en:1; - /** rst_core : R/W; bitpos: [23]; default: 0; - * Write 1 then write 0 to this bit to reset UART Tx/Rx. - */ - uint32_t rst_core:1; + uint32_t reserved_20:24; /** tx_sclk_en : R/W; bitpos: [24]; default: 1; * Set this bit to enable UART Tx clock. */ diff --git a/components/soc/esp32c6/include/soc/uart_reg.h b/components/soc/esp32c6/include/soc/uart_reg.h index abac8d92b1..0dc6d23355 100644 --- a/components/soc/esp32c6/include/soc/uart_reg.h +++ b/components/soc/esp32c6/include/soc/uart_reg.h @@ -1471,6 +1471,40 @@ extern "C" { #define UART_RXD_EDGE_CNT_V 0x000003FFU #define UART_RXD_EDGE_CNT_S 0 + +/** UART_CLK_CONF_REG register + * UART core clock configuration + */ +#define UART_CLK_CONF_REG(i) (REG_UART_BASE(i) + 0x88) +/** UART_TX_SCLK_EN : R/W; bitpos: [24]; default: 1; + * Set this bit to enable UART Tx clock. + */ +#define UART_TX_SCLK_EN (BIT(24)) +#define UART_TX_SCLK_EN_M (UART_TX_SCLK_EN_V << UART_TX_SCLK_EN_S) +#define UART_TX_SCLK_EN_V 0x00000001U +#define UART_TX_SCLK_EN_S 24 +/** UART_RX_SCLK_EN : R/W; bitpos: [25]; default: 1; + * Set this bit to enable UART Rx clock. + */ +#define UART_RX_SCLK_EN (BIT(25)) +#define UART_RX_SCLK_EN_M (UART_RX_SCLK_EN_V << UART_RX_SCLK_EN_S) +#define UART_RX_SCLK_EN_V 0x00000001U +#define UART_RX_SCLK_EN_S 25 +/** UART_TX_RST_CORE : R/W; bitpos: [26]; default: 0; + * Write 1 then write 0 to this bit to reset UART Tx. + */ +#define UART_TX_RST_CORE (BIT(26)) +#define UART_TX_RST_CORE_M (UART_TX_RST_CORE_V << UART_TX_RST_CORE_S) +#define UART_TX_RST_CORE_V 0x00000001U +#define UART_TX_RST_CORE_S 26 +/** UART_RX_RST_CORE : R/W; bitpos: [27]; default: 0; + * Write 1 then write 0 to this bit to reset UART Rx. + */ +#define UART_RX_RST_CORE (BIT(27)) +#define UART_RX_RST_CORE_M (UART_RX_RST_CORE_V << UART_RX_RST_CORE_S) +#define UART_RX_RST_CORE_V 0x00000001U +#define UART_RX_RST_CORE_S 27 + /** UART_DATE_REG register * UART Version register */ diff --git a/components/soc/esp32c6/include/soc/uart_struct.h b/components/soc/esp32c6/include/soc/uart_struct.h index 467f86ff5a..8554a231d1 100644 --- a/components/soc/esp32c6/include/soc/uart_struct.h +++ b/components/soc/esp32c6/include/soc/uart_struct.h @@ -1,5 +1,5 @@ /** - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -875,6 +875,33 @@ typedef union { uint32_t val; } uart_rs485_conf_sync_reg_t; +/** Type of clk_conf register + * UART core clock configuration + */ +typedef union { + struct { + uint32_t reserved_0:24; + /** tx_sclk_en : R/W; bitpos: [24]; default: 1; + * Set this bit to enable UART Tx clock. + */ + uint32_t tx_sclk_en:1; + /** rx_sclk_en : R/W; bitpos: [25]; default: 1; + * Set this bit to enable UART Rx clock. + */ + uint32_t rx_sclk_en:1; + /** tx_rst_core : R/W; bitpos: [26]; default: 0; + * Write 1 then write 0 to this bit to reset UART Tx. + */ + uint32_t tx_rst_core:1; + /** rx_rst_core : R/W; bitpos: [27]; default: 0; + * Write 1 then write 0 to this bit to reset UART Rx. + */ + uint32_t rx_rst_core:1; + uint32_t reserved_28:4; + }; + uint32_t val; +} uart_clk_conf_reg_t; + /** Group: Status Register */ /** Type of status register @@ -1218,12 +1245,12 @@ typedef struct uart_dev_s { volatile uart_mem_tx_status_reg_t mem_tx_status; volatile uart_mem_rx_status_reg_t mem_rx_status; volatile uart_fsm_status_reg_t fsm_status; - volatile uart_pospulse_reg_t pospulse; - volatile uart_negpulse_reg_t negpulse; - volatile uart_lowpulse_reg_t lowpulse; - volatile uart_highpulse_reg_t highpulse; - volatile uart_rxd_cnt_reg_t rxd_cnt; - uint32_t reserved_088; + volatile uart_pospulse_reg_t pospulse; /* LP_UART instance has this register reserved */ + volatile uart_negpulse_reg_t negpulse; /* LP_UART instance has this register reserved */ + volatile uart_lowpulse_reg_t lowpulse; /* LP_UART instance has this register reserved */ + volatile uart_highpulse_reg_t highpulse; /* LP_UART instance has this register reserved */ + volatile uart_rxd_cnt_reg_t rxd_cnt; /* LP_UART instance has this register reserved */ + volatile uart_clk_conf_reg_t clk_conf; volatile uart_date_reg_t date; volatile uart_afifo_status_reg_t afifo_status; uint32_t reserved_094;