Skip to content

drivers: wifi: Add WiFi drivers for ESP hosted firmware. #87685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/wifi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ endif() # CONFIG_BUILD_ONLY_NO_BLOBS

add_subdirectory_ifdef(CONFIG_WIFI_ESP_AT esp_at)
add_subdirectory_ifdef(CONFIG_WIFI_ESP32 esp32)
add_subdirectory_ifdef(CONFIG_WIFI_ESP_HOSTED esp_hosted)
add_subdirectory_ifdef(CONFIG_WIFI_ESWIFI eswifi)
add_subdirectory_ifdef(CONFIG_WIFI_SIMPLELINK simplelink)
add_subdirectory_ifdef(CONFIG_WIFI_WINC1500 winc1500)
Expand Down
1 change: 1 addition & 0 deletions drivers/wifi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ source "drivers/wifi/simplelink/Kconfig.simplelink"
source "drivers/wifi/eswifi/Kconfig.eswifi"
source "drivers/wifi/esp_at/Kconfig.esp_at"
source "drivers/wifi/esp32/Kconfig.esp32"
source "drivers/wifi/esp_hosted/Kconfig.esp_hosted"
source "drivers/wifi/nxp/Kconfig.nxp"
source "drivers/wifi/infineon/Kconfig.airoc"
source "drivers/wifi/nrf_wifi/Kconfig.nrfwifi"
Expand Down
27 changes: 27 additions & 0 deletions drivers/wifi/esp_hosted/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2025 Arduino SA
# SPDX-License-Identifier: Apache-2.0

if (CONFIG_WIFI_ESP_HOSTED)

zephyr_library_named(esp_hosted)

list(APPEND CMAKE_MODULE_PATH ${ZEPHYR_BASE}/modules/nanopb)
include(nanopb)

zephyr_library_sources(
esp_hosted_hal.c
esp_hosted_wifi.c
)

zephyr_nanopb_sources(esp_hosted
esp_hosted_proto.pb
)

zephyr_include_directories(
./
)

zephyr_compile_definitions(
PB_ENABLE_MALLOC=1
)
endif()
44 changes: 44 additions & 0 deletions drivers/wifi/esp_hosted/Kconfig.esp_hosted
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ESP Hosted WiFi driver options

# Copyright (c) 2025 Arduino SA
# SPDX-License-Identifier: Apache-2.0

menuconfig WIFI_ESP_HOSTED
bool "ESP_HOSTED driver support"
depends on DT_HAS_ESPRESSIF_ESP_HOSTED_ENABLED
default y
select GPIO
select SPI
select WIFI_OFFLOAD
select WIFI_NM
select NANOPB
select NET_L2_ETHERNET
select NET_L2_WIFI_MGMT
select WIFI_USE_NATIVE_NETWORKING

if WIFI_ESP_HOSTED

config WIFI_ESP_HOSTED_DEBUG
bool "Extra debugging messages"

config WIFI_ESP_HOSTED_EVENT_TASK_PRIORITY
int "Event task priority"
default 4

config WIFI_ESP_HOSTED_EVENT_TASK_STACK_SIZE
int "Event task stack size"
default 16384

config WIFI_ESP_HOSTED_EVENT_TASK_POLL_MS
int "Event task poll rate in ms"
default 20

config WIFI_ESP_HOSTED_AP_CLIENTS_MAX
int "Max number of AP clients"
default 5

config WIFI_ESP_HOSTED_AP_CHANNEL_DEF
int "Default AP channel"
default 9

endif
85 changes: 85 additions & 0 deletions drivers/wifi/esp_hosted/esp_hosted_hal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2025 Arduino SA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdint.h>
#include <string.h>

#include <zephyr/kernel.h>
#include "esp_hosted_wifi.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(esp_hosted_hal, CONFIG_WIFI_LOG_LEVEL);

int esp_hosted_hal_init(const struct device *dev)
{
const esp_hosted_config_t *config = dev->config;

if (!spi_is_ready_dt(&config->spi_bus)) {
LOG_ERR("SPI device is not ready");
return -ENODEV;
}

/* Configure pins. */
gpio_pin_configure_dt(&config->dataready_gpio, GPIO_OUTPUT);
gpio_pin_configure_dt(&config->reset_gpio, GPIO_OUTPUT);

/* Perform a hard-reset */
gpio_pin_set_dt(&config->dataready_gpio, 1);
gpio_pin_set_dt(&config->reset_gpio, 0);
k_msleep(100);
gpio_pin_set_dt(&config->reset_gpio, 1);
k_msleep(500);

/* Configure handshake/dataready pins. */
gpio_pin_configure_dt(&config->dataready_gpio, GPIO_INPUT);
gpio_pin_configure_dt(&config->handshake_gpio, GPIO_INPUT);

return 0;
}

bool esp_hosted_hal_data_ready(const struct device *dev)
{
const esp_hosted_config_t *config = dev->config;

return gpio_pin_get_dt(&config->dataready_gpio);
}

int esp_hosted_hal_spi_transfer(const struct device *dev, void *tx, void *rx, uint32_t size)
{
int ret = 0;
esp_hosted_data_t *data = dev->data;
const esp_hosted_config_t *config = dev->config;

const struct spi_buf tx_buf = {.buf = tx ? tx : rx, .len = size};
const struct spi_buf_set tx_set = {.buffers = &tx_buf, .count = 1};

const struct spi_buf rx_buf = {.buf = rx ? rx : tx, .len = size};
const struct spi_buf_set rx_set = {.buffers = &rx_buf, .count = 1};

/* Wait for handshake pin to go high. */
for (uint64_t start = k_uptime_get();; k_msleep(1)) {
if (gpio_pin_get_dt(&config->handshake_gpio) &&
(rx == NULL || gpio_pin_get_dt(&config->dataready_gpio))) {
break;
}
if ((k_uptime_get() - start) >= 100) {
return -ETIMEDOUT;
}
}

if (k_sem_take(&data->bus_sem, K_FOREVER) != 0) {
return -1;
}

/* Transfer SPI buffers. */
if (spi_transceive_dt(&config->spi_bus, &tx_set, &rx_set)) {
LOG_ERR("spi_transceive failed");
ret = -EIO;
}

k_sem_give(&data->bus_sem);
return ret;
}
12 changes: 12 additions & 0 deletions drivers/wifi/esp_hosted/esp_hosted_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2025 Arduino SA
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDED_DRIVERS_ESP_HOSTED_HAL_H
#define ZEPHYR_INCLUDED_DRIVERS_ESP_HOSTED_HAL_H
int esp_hosted_hal_init(const struct device *dev);
bool esp_hosted_hal_data_ready(const struct device *dev);
int esp_hosted_hal_spi_transfer(const struct device *dev, void *tx, void *rx, uint32_t size);
#endif /* ZEPHYR_INCLUDED_DRIVERS_ESP_HOSTED_HAL_H */
8 changes: 8 additions & 0 deletions drivers/wifi/esp_hosted/esp_hosted_proto.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.ssid max_size:32 max_length:31
*.bssid max_size:17
*.mac max_size:17
*.pwd max_size:64 max_length:63
*.entries type:FT_POINTER
*.stations type:FT_POINTER
*.init_data max_size:0
esp_hosted_proto.pb max_size:256 max_count:64 anonymous_oneof:true type:FT_STATIC
Loading