feat(uart): spilt LP and HP uart set_baudrate function
This commit is contained in:
@@ -179,24 +179,24 @@ static void uart_module_enable(uart_port_t uart_num)
|
||||
UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||
if (uart_context[uart_num].hw_enabled != true) {
|
||||
if (uart_num < SOC_UART_HP_NUM) {
|
||||
UART_CLK_ATOMIC() {
|
||||
HP_UART_BUS_CLK_ATOMIC() {
|
||||
uart_ll_enable_bus_clock(uart_num, true);
|
||||
}
|
||||
if (uart_num != CONFIG_ESP_CONSOLE_UART_NUM) {
|
||||
// Workaround for ESP32C3/S3: enable core reset before enabling uart module clock to prevent uart output
|
||||
// garbage value.
|
||||
#if SOC_UART_REQUIRE_CORE_RESET
|
||||
UART_SCLK_ATOMIC(){
|
||||
HP_UART_SRC_CLK_ATOMIC(){
|
||||
uart_hal_set_reset_core(&(uart_context[uart_num].hal), true);
|
||||
}
|
||||
UART_CLK_ATOMIC() {
|
||||
HP_UART_BUS_CLK_ATOMIC() {
|
||||
uart_ll_reset_register(uart_num);
|
||||
}
|
||||
UART_SCLK_ATOMIC(){
|
||||
HP_UART_SRC_CLK_ATOMIC(){
|
||||
uart_hal_set_reset_core(&(uart_context[uart_num].hal), false);
|
||||
}
|
||||
#else
|
||||
UART_CLK_ATOMIC() {
|
||||
HP_UART_BUS_CLK_ATOMIC() {
|
||||
uart_ll_reset_register(uart_num);
|
||||
}
|
||||
#endif
|
||||
@@ -204,7 +204,7 @@ static void uart_module_enable(uart_port_t uart_num)
|
||||
}
|
||||
#if (SOC_UART_LP_NUM >= 1)
|
||||
else {
|
||||
LP_UART_CLK_ATOMIC() {
|
||||
LP_UART_BUS_CLK_ATOMIC() {
|
||||
lp_uart_ll_enable_bus_clock(uart_num - SOC_UART_HP_NUM, true);
|
||||
lp_uart_ll_reset_register(uart_num - SOC_UART_HP_NUM);
|
||||
}
|
||||
@@ -220,13 +220,13 @@ static void uart_module_disable(uart_port_t uart_num)
|
||||
UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||
if (uart_context[uart_num].hw_enabled != false) {
|
||||
if (uart_num != CONFIG_ESP_CONSOLE_UART_NUM && uart_num < SOC_UART_HP_NUM) {
|
||||
UART_CLK_ATOMIC() {
|
||||
HP_UART_BUS_CLK_ATOMIC() {
|
||||
uart_ll_enable_bus_clock(uart_num, false);
|
||||
}
|
||||
}
|
||||
#if (SOC_UART_LP_NUM >= 1)
|
||||
else if (uart_num >= SOC_UART_HP_NUM) {
|
||||
LP_UART_CLK_ATOMIC() {
|
||||
LP_UART_BUS_CLK_ATOMIC() {
|
||||
lp_uart_ll_enable_bus_clock(uart_num - SOC_UART_HP_NUM, false);
|
||||
}
|
||||
}
|
||||
@@ -306,9 +306,18 @@ esp_err_t uart_set_baudrate(uart_port_t uart_num, uint32_t baud_rate)
|
||||
ESP_RETURN_ON_ERROR(esp_clk_tree_src_get_freq_hz(src_clk, ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &sclk_freq), UART_TAG, "Invalid src_clk");
|
||||
|
||||
UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||
UART_SCLK_ATOMIC() {
|
||||
uart_hal_set_baudrate(&(uart_context[uart_num].hal), baud_rate, sclk_freq);
|
||||
|
||||
if (uart_num < SOC_UART_HP_NUM) {
|
||||
HP_UART_SRC_CLK_ATOMIC() {
|
||||
uart_hal_set_baudrate(&(uart_context[uart_num].hal), baud_rate, sclk_freq);
|
||||
}
|
||||
}
|
||||
#if (SOC_UART_LP_NUM >= 1)
|
||||
else {
|
||||
lp_uart_ll_set_baudrate(uart_context[uart_num].hal.dev, baud_rate, sclk_freq);
|
||||
}
|
||||
#endif
|
||||
|
||||
UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -818,20 +827,19 @@ esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_conf
|
||||
UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||
uart_hal_init(&(uart_context[uart_num].hal), uart_num);
|
||||
if (uart_num < SOC_UART_HP_NUM) {
|
||||
UART_SCLK_ATOMIC() {
|
||||
HP_UART_SRC_CLK_ATOMIC() {
|
||||
uart_hal_set_sclk(&(uart_context[uart_num].hal), uart_sclk_sel);
|
||||
uart_hal_set_baudrate(&(uart_context[uart_num].hal), uart_config->baud_rate, sclk_freq);
|
||||
}
|
||||
}
|
||||
#if (SOC_UART_LP_NUM >= 1)
|
||||
else {
|
||||
LP_UART_CLK_ATOMIC() {
|
||||
LP_UART_SRC_CLK_ATOMIC() {
|
||||
lp_uart_ll_set_source_clk(uart_context[uart_num].hal.dev, (soc_periph_lp_uart_clk_src_t)uart_sclk_sel);
|
||||
}
|
||||
lp_uart_ll_set_baudrate(uart_context[uart_num].hal.dev, uart_config->baud_rate, sclk_freq);
|
||||
}
|
||||
#endif
|
||||
UART_SCLK_ATOMIC() {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user