From 2fc2928fa595c321a70a0026227d6496d3f30331 Mon Sep 17 00:00:00 2001 From: Andrei-Edward Popa Date: Thu, 3 Feb 2022 14:44:41 +0200 Subject: [PATCH] drivers: serial: rpi_pico: check if baudrate was set by the API function if peripheral clock is not configured, uart init API function returns 0, so we need to check the return value of this function Signed-off-by: Andrei-Edward Popa --- drivers/serial/uart_rpi_pico.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/serial/uart_rpi_pico.c b/drivers/serial/uart_rpi_pico.c index b0f4e280345..7b0af519f1f 100644 --- a/drivers/serial/uart_rpi_pico.c +++ b/drivers/serial/uart_rpi_pico.c @@ -40,14 +40,21 @@ static void uart_rpi_poll_out(const struct device *dev, unsigned char c) static int uart_rpi_init(const struct device *dev) { const struct uart_rpi_config *config = dev->config; - int ret; + uart_inst_t * const uart_inst = config->uart_dev; + uart_hw_t * const uart_hw = config->uart_regs; + struct uart_rpi_data * const data = dev->data; + int ret, baudrate; ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); if (ret < 0) { return ret; } - uart_init(config->uart_dev, config->baudrate); + baudrate = uart_init(uart_inst, data->baudrate); + /* Check if baudrate adjustment returned by 'uart_init' function is a positive value */ + if (baudrate <= 0) { + return -EINVAL; + } return 0; }