diff --git a/drivers/wifi/esp_at/esp.c b/drivers/wifi/esp_at/esp.c index 203991900a25e36..0dfe0bfb9d43962 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),