uart/driver: Add module reset before enabling

This commit prevents infinite restarts caused due to an interrupt flag
was left uncleared.

Closes: https://github.com/espressif/esp-idf/issues/1981

Closes: IDF-188
This commit is contained in:
Konstantin Kondrashov 2019-04-22 14:09:24 +08:00 committed by bot
parent 90af68bd3c
commit dc63c2e9cb

View File

@ -634,18 +634,31 @@ esp_err_t uart_set_tx_idle_num(uart_port_t uart_num, uint16_t idle_num)
return ESP_OK;
}
static periph_module_t get_periph_module(uart_port_t uart_num)
{
periph_module_t periph_module = PERIPH_UART0_MODULE;
if (uart_num == UART_NUM_0) {
periph_module = PERIPH_UART0_MODULE;
} else if (uart_num == UART_NUM_1) {
periph_module = PERIPH_UART1_MODULE;
} else if (uart_num == UART_NUM_2) {
periph_module = PERIPH_UART2_MODULE;
} else {
assert(0 && "uart_num error");
}
return periph_module;
}
esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_config)
{
esp_err_t r;
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
UART_CHECK((uart_config), "param null", ESP_FAIL);
if(uart_num == UART_NUM_0) {
periph_module_enable(PERIPH_UART0_MODULE);
} else if(uart_num == UART_NUM_1) {
periph_module_enable(PERIPH_UART1_MODULE);
} else if(uart_num == UART_NUM_2) {
periph_module_enable(PERIPH_UART2_MODULE);
periph_module_t periph_module = get_periph_module(uart_num);
if (uart_num != CONFIG_CONSOLE_UART_NUM) {
periph_module_reset(periph_module);
}
periph_module_enable(periph_module);
r = uart_set_hw_flow_ctrl(uart_num, uart_config->flow_ctrl, uart_config->rx_flow_ctrl_thresh);
if (r != ESP_OK) return r;
@ -1430,14 +1443,9 @@ esp_err_t uart_driver_delete(uart_port_t uart_num)
free(p_uart_obj[uart_num]);
p_uart_obj[uart_num] = NULL;
if (uart_num != CONFIG_CONSOLE_UART_NUM ) {
if(uart_num == UART_NUM_0) {
periph_module_disable(PERIPH_UART0_MODULE);
} else if(uart_num == UART_NUM_1) {
periph_module_disable(PERIPH_UART1_MODULE);
} else if(uart_num == UART_NUM_2) {
periph_module_disable(PERIPH_UART2_MODULE);
}
if (uart_num != CONFIG_CONSOLE_UART_NUM) {
periph_module_t periph_module = get_periph_module(uart_num);
periph_module_disable(periph_module);
}
return ESP_OK;
}