This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 8be264973d0fe489ce8f103c7f9a7e07f4661d85 Author: Marcio Ribeiro <[email protected]> AuthorDate: Wed Sep 9 17:52:11 2026 -0300 boards/risc-v/esp32c2: add Wi-Fi and BLE board support Add the Wi-Fi board helper, wifi and ble defconfigs, and BLE bring-up for the ESP32-C2 radio. Assisted-by: Claude:claude-opus-5 Signed-off-by: Marcio Ribeiro <[email protected]> --- .../risc-v/esp32c2/common/include/esp_board_wlan.h | 75 ++++++++++++++++++++ .../esp32c2/common/scripts/esp32c2_aliases.ld | 14 ---- .../esp32c2/common/scripts/esp32c2_sections.ld | 16 +++++ boards/risc-v/esp32c2/common/src/CMakeLists.txt | 4 ++ boards/risc-v/esp32c2/common/src/Make.defs | 4 ++ boards/risc-v/esp32c2/common/src/esp_board_wlan.c | 82 ++++++++++++++++++++++ .../esp32c2/esp8684-devkitm/configs/ble/defconfig | 66 +++++++++++++++++ .../esp32c2/esp8684-devkitm/configs/wifi/defconfig | 78 ++++++++++++++++++++ .../esp32c2/esp8684-devkitm/src/esp32c2_bringup.c | 35 +++++++++ 9 files changed, 360 insertions(+), 14 deletions(-) diff --git a/boards/risc-v/esp32c2/common/include/esp_board_wlan.h b/boards/risc-v/esp32c2/common/include/esp_board_wlan.h new file mode 100644 index 00000000000..e086449d388 --- /dev/null +++ b/boards/risc-v/esp32c2/common/include/esp_board_wlan.h @@ -0,0 +1,75 @@ +/**************************************************************************** + * boards/risc-v/esp32c2/common/include/esp_board_wlan.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_RISCV_ESP32C2_COMMON_INCLUDE_ESP_BOARD_WLAN_H +#define __BOARDS_RISCV_ESP32C2_COMMON_INCLUDE_ESP_BOARD_WLAN_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef CONFIG_ESPRESSIF_WIFI + +/**************************************************************************** + * Name: board_wlan_init + * + * Description: + * Configure the wireless subsystem. + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * + ****************************************************************************/ + +int board_wlan_init(void); + +#endif /* CONFIG_ESPRESSIF_WIFI */ + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_RISCV_ESP32C2_COMMON_INCLUDE_ESP_BOARD_WLAN_H */ diff --git a/boards/risc-v/esp32c2/common/scripts/esp32c2_aliases.ld b/boards/risc-v/esp32c2/common/scripts/esp32c2_aliases.ld index 92629ba7483..5b59506a2f9 100644 --- a/boards/risc-v/esp32c2/common/scripts/esp32c2_aliases.ld +++ b/boards/risc-v/esp32c2/common/scripts/esp32c2_aliases.ld @@ -28,17 +28,3 @@ cache_resume_icache = Cache_Resume_ICache; cache_suspend_icache = Cache_Suspend_ICache; cache_invalidate_icache_all = Cache_Invalidate_ICache_All; _interrupt_handler = exception_common; - -#ifdef CONFIG_ESPRESSIF_BLE - -/* Lower-case aliases for BLE library symbols not compliant to nxstyle */ - -api_vhci_host_check_send_available = API_vhci_host_check_send_available; -api_vhci_host_send_packet = API_vhci_host_send_packet; -api_vhci_host_register_callback = API_vhci_host_register_callback; -scan_stack_enable_adv_flow_ctrl_vs_cmd = scan_stack_enableAdvFlowCtrlVsCmd; -adv_stack_enable_clear_legacy_adv_vs_cmd = adv_stack_enableClearLegacyAdvVsCmd; -adv_filter_stack_enable_dup_exc_list_vs_cmd = advFilter_stack_enableDupExcListVsCmd; -chan_sel_stack_enable_set_csa_vs_cmd = chanSel_stack_enableSetCsaVsCmd; - -#endif diff --git a/boards/risc-v/esp32c2/common/scripts/esp32c2_sections.ld b/boards/risc-v/esp32c2/common/scripts/esp32c2_sections.ld index 6818791ec32..e61ad4cc59d 100644 --- a/boards/risc-v/esp32c2/common/scripts/esp32c2_sections.ld +++ b/boards/risc-v/esp32c2/common/scripts/esp32c2_sections.ld @@ -118,6 +118,22 @@ SECTIONS *(.iram1) *(.iram1.*) +#ifdef CONFIG_ESPRESSIF_BLE + /* BLE controller (libble_app.a) uses custom section names for the code + * that must run from IRAM. Collect them here so elf2image does not see + * one ESP segment per input section. + */ + + *(.isr_iram1) + *(.isr_iram1.*) + *(.conn_iram1) + *(.conn_iram1.*) + *(.sleep_iram1) + *(.sleep_iram1.*) + *(.ble_log_iram1) + *(.ble_log_iram1.*) +#endif + *libcoexist.a:(.coexiram .coexiram.*) *libpp.a:wifi_iram.*(.literal .text .literal.* .text.*) diff --git a/boards/risc-v/esp32c2/common/src/CMakeLists.txt b/boards/risc-v/esp32c2/common/src/CMakeLists.txt index db66719071f..50fe3051e02 100644 --- a/boards/risc-v/esp32c2/common/src/CMakeLists.txt +++ b/boards/risc-v/esp32c2/common/src/CMakeLists.txt @@ -52,6 +52,10 @@ if(CONFIG_ARCH_BOARD_COMMON) list(APPEND SRCS esp_board_spiflash.c) endif() + if(CONFIG_ESPRESSIF_WIFI) + list(APPEND SRCS esp_board_wlan.c) + endif() + if(CONFIG_SENSORS_BMP180) list(APPEND SRCS esp_board_bmp180.c) endif() diff --git a/boards/risc-v/esp32c2/common/src/Make.defs b/boards/risc-v/esp32c2/common/src/Make.defs index 3cec1ba59e8..aab3fd4b0a9 100644 --- a/boards/risc-v/esp32c2/common/src/Make.defs +++ b/boards/risc-v/esp32c2/common/src/Make.defs @@ -50,6 +50,10 @@ ifeq ($(CONFIG_ESPRESSIF_SPIFLASH),y) CSRCS += esp_board_spiflash.c endif +ifeq ($(CONFIG_ESPRESSIF_WIFI),y) + CSRCS += esp_board_wlan.c +endif + ifeq ($(CONFIG_SENSORS_BMP180),y) CSRCS += esp_board_bmp180.c endif diff --git a/boards/risc-v/esp32c2/common/src/esp_board_wlan.c b/boards/risc-v/esp32c2/common/src/esp_board_wlan.c new file mode 100644 index 00000000000..2fc7ae3cee0 --- /dev/null +++ b/boards/risc-v/esp32c2/common/src/esp_board_wlan.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * boards/risc-v/esp32c2/common/src/esp_board_wlan.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <sys/stat.h> +#include <syslog.h> +#include <nuttx/debug.h> + +#include <nuttx/wireless/wireless.h> + +#include "espressif/esp_wlan_netdev.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_wlan_init + * + * Description: + * Configure the wireless subsystem. + * + * Input Parameters: + * None. + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * + ****************************************************************************/ + +int board_wlan_init(void) +{ + int ret = OK; + +#ifdef ESP_WLAN_HAS_STA + ret = esp_wlan_sta_initialize(); + if (ret) + { + wlerr("ERROR: Failed to initialize Wi-Fi station\n"); + return ret; + } +#endif /* ESP_WLAN_HAS_STA */ + +#ifdef ESP_WLAN_HAS_SOFTAP + ret = esp_wlan_softap_initialize(); + if (ret) + { + wlerr("ERROR: Failed to initialize Wi-Fi softAP\n"); + return ret; + } +#endif /* ESP_WLAN_HAS_SOFTAP */ + + return ret; +} diff --git a/boards/risc-v/esp32c2/esp8684-devkitm/configs/ble/defconfig b/boards/risc-v/esp32c2/esp8684-devkitm/configs/ble/defconfig new file mode 100644 index 00000000000..5704acedb49 --- /dev/null +++ b/boards/risc-v/esp32c2/esp8684-devkitm/configs/ble/defconfig @@ -0,0 +1,66 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ALLOW_BSD_COMPONENTS=y +CONFIG_ARCH="risc-v" +CONFIG_ARCH_BOARD="esp8684-devkitm" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP8684_DEVKITM=y +CONFIG_ARCH_CHIP="esp32c2" +CONFIG_ARCH_CHIP_ESP32C2=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_IRQ_TO_NDX=y +CONFIG_ARCH_MINIMAL_VECTORTABLE_DYNAMIC=y +CONFIG_ARCH_NUSER_INTERRUPTS=17 +CONFIG_ARCH_RISCV=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARDCTL_RESET=y +CONFIG_BOARD_LOOPSPERMSEC=12000 +CONFIG_BTSAK=y +CONFIG_BUILTIN=y +CONFIG_DRIVERS_BLUETOOTH=y +CONFIG_DRIVERS_IEEE80211=y +CONFIG_DRIVERS_WIRELESS=y +CONFIG_ESPRESSIF_BLE=y +CONFIG_FS_PROCFS=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_LIBC_PERROR_STDOUT=y +CONFIG_LIBC_STRERROR=y +CONFIG_LINE_MAX=64 +CONFIG_NAME_MAX=48 +CONFIG_NETDEV_LATEINIT=y +CONFIG_NET_BLUETOOTH=y +CONFIG_NET_SOCKOPTS=y +CONFIG_NET_TCP=y +CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6 +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_DISABLE_DATE=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_NSH_STRERROR=y +CONFIG_PREALLOC_MQ_MSGS=32 +CONFIG_PREALLOC_TIMERS=0 +CONFIG_PTHREAD_MUTEX_TYPES=y +CONFIG_RR_INTERVAL=200 +CONFIG_RTC_ALARM=y +CONFIG_SCHED_BACKTRACE=y +CONFIG_SCHED_WAITPID=y +CONFIG_SIG_DEFAULT=y +CONFIG_START_DAY=29 +CONFIG_START_MONTH=11 +CONFIG_START_YEAR=2019 +CONFIG_SYSTEM_DUMPSTACK=y +CONFIG_SYSTEM_NSH=y +CONFIG_TESTING_GETPRIME=y +CONFIG_TESTING_OSTEST=y +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_WIRELESS=y +CONFIG_WIRELESS_BLUETOOTH=y diff --git a/boards/risc-v/esp32c2/esp8684-devkitm/configs/wifi/defconfig b/boards/risc-v/esp32c2/esp8684-devkitm/configs/wifi/defconfig new file mode 100644 index 00000000000..b9d96fb765f --- /dev/null +++ b/boards/risc-v/esp32c2/esp8684-devkitm/configs/wifi/defconfig @@ -0,0 +1,78 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +CONFIG_ALLOW_BSD_COMPONENTS=y +CONFIG_ARCH="risc-v" +CONFIG_ARCH_BOARD="esp8684-devkitm" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP8684_DEVKITM=y +CONFIG_ARCH_CHIP="esp32c2" +CONFIG_ARCH_CHIP_ESP32C2=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_IRQ_TO_NDX=y +CONFIG_ARCH_MINIMAL_VECTORTABLE_DYNAMIC=y +CONFIG_ARCH_NUSER_INTERRUPTS=17 +CONFIG_ARCH_RISCV=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARD_LOOPSPERMSEC=12000 +CONFIG_BUILTIN=y +CONFIG_DRIVERS_IEEE80211=y +CONFIG_DRIVERS_WIRELESS=y +CONFIG_ESPRESSIF_SPIFLASH=y +CONFIG_ESPRESSIF_SPIFLASH_SPIFFS=y +CONFIG_ESPRESSIF_WIFI=y +CONFIG_EXAMPLES_RANDOM=y +CONFIG_FS_PROCFS=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=8192 +CONFIG_INTELHEX_BINARY=y +CONFIG_IOB_BUFSIZE=128 +CONFIG_IOB_NBUFFERS=160 +CONFIG_IOB_THROTTLE=24 +CONFIG_LIBC_PERROR_STDOUT=y +CONFIG_LIBC_STRERROR=y +CONFIG_NETDB_DNSCLIENT=y +CONFIG_NETDEV_LATEINIT=y +CONFIG_NETDEV_PHY_IOCTL=y +CONFIG_NETDEV_WIRELESS_IOCTL=y +CONFIG_NETUTILS_CJSON=y +CONFIG_NETUTILS_IPERF=y +CONFIG_NET_BROADCAST=y +CONFIG_NET_ETH_PKTSIZE=1514 +CONFIG_NET_ICMP_SOCKET=y +CONFIG_NET_TCP=y +CONFIG_NET_TCP_DELAYED_ACK=y +CONFIG_NET_TCP_WRITE_BUFFERS=y +CONFIG_NET_UDP=y +CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6 +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_NSH_STRERROR=y +CONFIG_PREALLOC_TIMERS=0 +CONFIG_PTHREAD_MUTEX_TYPES=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_BACKTRACE=y +CONFIG_SCHED_LPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_SIG_DEFAULT=y +CONFIG_START_DAY=29 +CONFIG_START_MONTH=11 +CONFIG_START_YEAR=2019 +CONFIG_SYSTEM_DHCPC_RENEW=y +CONFIG_SYSTEM_DUMPSTACK=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_PING=y +CONFIG_TESTING_GETPRIME=y +CONFIG_TESTING_OSTEST=y +CONFIG_TLS_TASK_NELEM=4 +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_WIRELESS=y +CONFIG_WIRELESS_WAPI=y +CONFIG_WIRELESS_WAPI_CMDTOOL=y +CONFIG_WIRELESS_WAPI_INITCONF=y diff --git a/boards/risc-v/esp32c2/esp8684-devkitm/src/esp32c2_bringup.c b/boards/risc-v/esp32c2/esp8684-devkitm/src/esp32c2_bringup.c index caeb92aaac1..1b8f0aba47d 100644 --- a/boards/risc-v/esp32c2/esp8684-devkitm/src/esp32c2_bringup.c +++ b/boards/risc-v/esp32c2/esp8684-devkitm/src/esp32c2_bringup.c @@ -108,6 +108,18 @@ # include "esp_board_mmcsd.h" #endif +#ifdef CONFIG_ESPRESSIF_BLE +# include "esp_ble.h" +#endif + +#ifdef CONFIG_ESPRESSIF_WIFI_BT_COEXIST +# include "private/esp_coexist_internal.h" +#endif + +#ifdef CONFIG_ESPRESSIF_WIFI +# include "esp_board_wlan.h" +#endif + #include "esp8684-devkitm.h" /**************************************************************************** @@ -328,6 +340,29 @@ int esp_bringup(void) } #endif /* CONFIG_ESPRESSIF_LEDC */ +#ifdef CONFIG_ESPRESSIF_BLE + ret = esp_ble_initialize(); + if (ret) + { + syslog(LOG_ERR, "ERROR: Failed to initialize BLE\n"); + return ret; + } +#endif + +#ifdef CONFIG_ESPRESSIF_WIFI_BT_COEXIST + esp_coex_adapter_register(&g_coex_adapter_funcs); + coex_pre_init(); +#endif + +#ifdef CONFIG_ESPRESSIF_WIFI + ret = board_wlan_init(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to initialize wireless subsystem=%d\n", + ret); + } +#endif + #ifdef CONFIG_PM /* Configure PM */
