From 5b7bfcf0c69eaf5a78808aa74d086bc1981df224 Mon Sep 17 00:00:00 2001 From: Hongquan Li Date: Mon, 28 Oct 2024 16:44:43 +0800 Subject: [PATCH] drivers: wifi: esp_at: Fix serial receive interrupt can't exit If a character is received immediately after modem_iface_uart_init called, the modem_iface_uart_isr function will not read the data in the serial port fifo register as the context has not been registered at this time, which will result in the program not being able to exit the interrupt, so the context should registered before the serial port is initialised. Signed-off-by: Hongquan Li --- drivers/wifi/esp_at/esp.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/wifi/esp_at/esp.c b/drivers/wifi/esp_at/esp.c index 203991900a25e..0dfe0bfb9d439 100644 --- a/drivers/wifi/esp_at/esp.c +++ b/drivers/wifi/esp_at/esp.c @@ -1606,6 +1606,14 @@ static int esp_init(const struct device *dev) .hw_flow_control = DT_PROP(ESP_BUS, hw_flow_control), }; + /* The context must be registered before the serial port is initialised. */ + data->mctx.driver_data = data; + ret = modem_context_register(&data->mctx); + if (ret < 0) { + LOG_ERR("Error registering modem context: %d", ret); + goto error; + } + ret = modem_iface_uart_init(&data->mctx.iface, &data->iface_data, &uart_config); if (ret < 0) { goto error; @@ -1627,14 +1635,6 @@ static int esp_init(const struct device *dev) } #endif - data->mctx.driver_data = data; - - ret = modem_context_register(&data->mctx); - if (ret < 0) { - LOG_ERR("Error registering modem context: %d", ret); - goto error; - } - /* start RX thread */ k_thread_create(&esp_rx_thread, esp_rx_stack, K_KERNEL_STACK_SIZEOF(esp_rx_stack),