From 8482f530c798adf6ae889ed47c2cf17c30e35fbf Mon Sep 17 00:00:00 2001 From: Eren Terzioglu Date: Mon, 25 May 2026 12:01:17 +0200 Subject: [PATCH 1/3] arch/risc-v/espressif: Add BLE support for esp32[-c6|-h2] Add BLE support for esp32c6 and esp32h2 Signed-off-by: Eren Terzioglu --- .../src/common/espressif/CMakeLists.txt | 8 +- arch/risc-v/src/common/espressif/Kconfig | 2 +- arch/risc-v/src/common/espressif/Make.defs | 8 +- .../src/common/espressif/Wireless.cmake | 80 ++++- arch/risc-v/src/common/espressif/Wireless.mk | 55 ++- arch/risc-v/src/esp32c6/CMakeLists.txt | 5 + arch/risc-v/src/esp32c6/Make.defs | 5 + arch/risc-v/src/esp32c6/esp_ble.c | 333 ++++++++++++++++++ arch/risc-v/src/esp32c6/esp_ble.h | 52 +++ arch/risc-v/src/esp32h2/CMakeLists.txt | 5 + arch/risc-v/src/esp32h2/Make.defs | 5 + arch/risc-v/src/esp32h2/esp_ble.c | 333 ++++++++++++++++++ arch/risc-v/src/esp32h2/esp_ble.h | 52 +++ 13 files changed, 931 insertions(+), 12 deletions(-) create mode 100644 arch/risc-v/src/esp32c6/esp_ble.c create mode 100644 arch/risc-v/src/esp32c6/esp_ble.h create mode 100644 arch/risc-v/src/esp32h2/esp_ble.c create mode 100644 arch/risc-v/src/esp32h2/esp_ble.h diff --git a/arch/risc-v/src/common/espressif/CMakeLists.txt b/arch/risc-v/src/common/espressif/CMakeLists.txt index 470bbfe525448..7a347b2ea13a7 100644 --- a/arch/risc-v/src/common/espressif/CMakeLists.txt +++ b/arch/risc-v/src/common/espressif/CMakeLists.txt @@ -157,7 +157,9 @@ if(CONFIG_ESPRESSIF_WIRELESS) list(APPEND SRCS esp_wifi_api.c) list(APPEND SRCS esp_wlan_netdev.c) endif() - list(APPEND SRCS esp_wifi_utils.c) + if(NOT CONFIG_ARCH_CHIP_ESP32H2) + list(APPEND SRCS esp_wifi_utils.c) + endif() endif() if(CONFIG_ESP_MCPWM) @@ -221,7 +223,7 @@ if(DEFINED ENV{ESP_HAL_3RDPARTY_VERSION}) CACHE STRING "ESP HAL 3rdparty version") else() set(ESP_HAL_3RDPARTY_VERSION - e8d8638febf5310bf5b8f9bd04cf7fab9e9a4cb0 + 0eb59f7e02a4735f2b9a78797e691b66740fcadb CACHE STRING "ESP HAL 3rdparty version") endif() @@ -321,6 +323,8 @@ if(NOT IS_DIRECTORY "${ESP_HAL_3RDPARTY_REPO}") COMMAND git submodule --quiet update --init --depth=1 components/esp_phy/lib components/esp_wifi/lib components/bt/controller/lib_esp32c3_family + components/bt/controller/lib_esp32c6/esp32c6-bt-lib + components/bt/controller/lib_esp32h2/esp32h2-bt-lib components/esp_coex/lib WORKING_DIRECTORY ${ESP_HAL_3RDPARTY_REPO} RESULT_VARIABLE GIT_SUBMODULE_RESULT) diff --git a/arch/risc-v/src/common/espressif/Kconfig b/arch/risc-v/src/common/espressif/Kconfig index 4aca18ec6f0d5..d983b2264e4a3 100644 --- a/arch/risc-v/src/common/espressif/Kconfig +++ b/arch/risc-v/src/common/espressif/Kconfig @@ -2062,7 +2062,7 @@ config ESPRESSIF_WIFI config ESPRESSIF_BLE bool "BLE" - depends on ARCH_CHIP_ESP32C3 + depends on !ARCH_CHIP_ESP32P4 default n select ESPRESSIF_WIRELESS ---help--- diff --git a/arch/risc-v/src/common/espressif/Make.defs b/arch/risc-v/src/common/espressif/Make.defs index 56edce0830143..bb6327201f098 100644 --- a/arch/risc-v/src/common/espressif/Make.defs +++ b/arch/risc-v/src/common/espressif/Make.defs @@ -162,7 +162,9 @@ ifeq ($(CONFIG_ESPRESSIF_WIRELESS),y) CHIP_CSRCS += esp_wifi_api.c CHIP_CSRCS += esp_wlan_netdev.c endif - CHIP_CSRCS += esp_wifi_utils.c + ifneq ($(CONFIG_ARCH_CHIP_ESP32H2),y) + CHIP_CSRCS += esp_wifi_utils.c + endif endif ifeq ($(CONFIG_ESP_MCPWM),y) @@ -233,7 +235,7 @@ endif ESP_HAL_3RDPARTY_REPO = esp-hal-3rdparty ifndef ESP_HAL_3RDPARTY_VERSION - ESP_HAL_3RDPARTY_VERSION = e8d8638febf5310bf5b8f9bd04cf7fab9e9a4cb0 + ESP_HAL_3RDPARTY_VERSION = 0eb59f7e02a4735f2b9a78797e691b66740fcadb endif ifndef ESP_HAL_3RDPARTY_URL @@ -283,7 +285,7 @@ endif ifeq ($(CONFIG_ESPRESSIF_WIRELESS),y) ifneq ($(USE_NXTMPDIR_ESP_REPO_DIRECTLY),y) $(Q) echo "Espressif HAL for 3rd Party Platforms: initializing submodules..." - $(Q) git -C chip/$(ESP_HAL_3RDPARTY_REPO) submodule --quiet update --init $(GIT_DEPTH_PARAMETER) components/esp_phy/lib components/esp_wifi/lib components/bt/controller/lib_esp32c3_family components/esp_coex/lib + $(Q) git -C chip/$(ESP_HAL_3RDPARTY_REPO) submodule --quiet update --init $(GIT_DEPTH_PARAMETER) components/esp_phy/lib components/esp_wifi/lib components/bt/controller/lib_esp32c3_family components/bt/controller/lib_esp32c6/esp32c6-bt-lib components/bt/controller/lib_esp32h2/esp32h2-bt-lib components/esp_coex/lib $(Q) git -C chip/$(ESP_HAL_3RDPARTY_REPO)/components/mbedtls/mbedtls reset --quiet --hard endif $(Q) echo "Applying patches..." diff --git a/arch/risc-v/src/common/espressif/Wireless.cmake b/arch/risc-v/src/common/espressif/Wireless.cmake index 1ca12b142707a..cfd6a486b6539 100644 --- a/arch/risc-v/src/common/espressif/Wireless.cmake +++ b/arch/risc-v/src/common/espressif/Wireless.cmake @@ -40,15 +40,86 @@ target_include_directories( nuttx_add_extra_library( ${ESP_HAL_3RDPARTY_REPO}/components/esp_phy/lib/${CHIP_SERIES}/libphy.a - ${ESP_HAL_3RDPARTY_REPO}/components/esp_coex/lib/${CHIP_SERIES}/libcoexist.a - ${ESP_HAL_3RDPARTY_REPO}/components/esp_wifi/lib/${CHIP_SERIES}/libmesh.a) + ${ESP_HAL_3RDPARTY_REPO}/components/esp_coex/lib/${CHIP_SERIES}/libcoexist.a) + +if(NOT CONFIG_ARCH_CHIP_ESP32H2) + nuttx_add_extra_library( + ${ESP_HAL_3RDPARTY_REPO}/components/esp_wifi/lib/${CHIP_SERIES}/libmesh.a + ${ESP_HAL_3RDPARTY_REPO}/components/esp_wifi/lib/${CHIP_SERIES}/libespnow.a) +endif() + +# ############################################################################## +# ESP32-C6 / ESP32-H2 BLE host and controller sources +# ############################################################################## + +if((CONFIG_ARCH_CHIP_ESP32C6 OR CONFIG_ARCH_CHIP_ESP32H2) + AND CONFIG_ESPRESSIF_BLE) + target_include_directories( + arch + PRIVATE + ${ESP_HAL_3RDPARTY_REPO}/components/bt/common/osi/include + ${ESP_HAL_3RDPARTY_REPO}/components/bt/common/tinycrypt/include + ${ESP_HAL_3RDPARTY_REPO}/components/bt/common/tinycrypt/port + ${ESP_HAL_3RDPARTY_REPO}/components/bt/host/nimble/nimble/porting/nimble/include + ${ESP_HAL_3RDPARTY_REPO}/components/bt/host/nimble/port/include + ${ESP_HAL_3RDPARTY_REPO}/components/bt/include/${CHIP_SERIES}/include + ${ESP_HAL_3RDPARTY_REPO}/components/bt/porting/include + ${ESP_HAL_3RDPARTY_REPO}/components/bt/porting/transport/include + ${ESP_HAL_3RDPARTY_REPO}/components/esp_common/include + ${ESP_HAL_3RDPARTY_REPO}/components/esp_phy/include + ${ESP_HAL_3RDPARTY_REPO}/components/esp_phy/${CHIP_SERIES}/include + ${ESP_HAL_3RDPARTY_REPO}/nuttx/src/platform/nimble/include) + + set(ESP_BLE_HOST_SRCS + ${ESP_HAL_3RDPARTY_REPO}/components/bt/common/tinycrypt/src/ecc.c + ${ESP_HAL_3RDPARTY_REPO}/components/bt/common/tinycrypt/src/ecc_dh.c + ${ESP_HAL_3RDPARTY_REPO}/components/bt/common/tinycrypt/src/ecc_platform_specific.c + ${ESP_HAL_3RDPARTY_REPO}/components/bt/common/tinycrypt/port/esp_tinycrypt_port.c + ${ESP_HAL_3RDPARTY_REPO}/components/bt/common/tinycrypt/src/sha256.c + ${ESP_HAL_3RDPARTY_REPO}/components/bt/common/tinycrypt/src/utils.c + ${ESP_HAL_3RDPARTY_REPO}/components/bt/porting/mem/bt_osi_mem.c + ${ESP_HAL_3RDPARTY_REPO}/components/bt/porting/mem/os_msys_init.c + ${ESP_HAL_3RDPARTY_REPO}/components/bt/porting/transport/src/hci_transport.c + ${ESP_HAL_3RDPARTY_REPO}/components/bt/porting/transport/driver/vhci/hci_driver_standard.c + ${ESP_HAL_3RDPARTY_REPO}/components/bt/controller/${CHIP_SERIES}/ble.c + ${ESP_HAL_3RDPARTY_REPO}/components/bt/controller/${CHIP_SERIES}/bt.c + ${ESP_HAL_3RDPARTY_REPO}/components/esp_hal_security/ecc_hal.c + ${ESP_HAL_3RDPARTY_REPO}/components/esp_phy/src/btbb_init.c + ${ESP_HAL_3RDPARTY_REPO}/nuttx/src/platform/nimble/src/npl_os.c) + + target_sources(arch PRIVATE ${ESP_BLE_HOST_SRCS}) + + target_compile_definitions(arch PRIVATE ESP_PLATFORM=1) + + if(CONFIG_ARCH_CHIP_ESP32H2) + target_sources( + arch + PRIVATE + ${ESP_HAL_3RDPARTY_REPO}/components/esp_phy/src/lib_printf.c + ${ESP_HAL_3RDPARTY_REPO}/components/esp_phy/src/phy_common.c + ${ESP_HAL_3RDPARTY_REPO}/components/esp_phy/src/phy_init_esp32hxx.c) + endif() +endif() + +# ############################################################################## +# BLE prebuilt libraries (Wireless.mk lines 30-32, 65-72; chip Make.defs) +# ############################################################################## if(CONFIG_ESPRESSIF_BLE) nuttx_add_extra_library( ${ESP_HAL_3RDPARTY_REPO}/components/esp_phy/lib/${CHIP_SERIES}/libbtbb.a) + if(CONFIG_ARCH_CHIP_ESP32C3) nuttx_add_extra_library( - ${ESP_HAL_3RDPARTY_REPO}/components/bt/controller/lib_esp32c3_family/esp32c3/libbtdm_app.a + ${ESP_HAL_3RDPARTY_REPO}/components/bt/controller/lib_esp32c3_family/${CHIP_SERIES}/libbtdm_app.a + ) + elseif(CONFIG_ARCH_CHIP_ESP32C6) + nuttx_add_extra_library( + ${ESP_HAL_3RDPARTY_REPO}/components/bt/controller/lib_esp32c6/esp32c6-bt-lib/esp32c6/libble_app.a + ) + elseif(CONFIG_ARCH_CHIP_ESP32H2) + nuttx_add_extra_library( + ${ESP_HAL_3RDPARTY_REPO}/components/bt/controller/lib_esp32h2/esp32h2-bt-lib/libble_app.a ) endif() endif() @@ -57,8 +128,7 @@ if(CONFIG_ESPRESSIF_WIFI) nuttx_add_extra_library( ${ESP_HAL_3RDPARTY_REPO}/components/esp_wifi/lib/${CHIP_SERIES}/libcore.a ${ESP_HAL_3RDPARTY_REPO}/components/esp_wifi/lib/${CHIP_SERIES}/libnet80211.a - ${ESP_HAL_3RDPARTY_REPO}/components/esp_wifi/lib/${CHIP_SERIES}/libpp.a - ${ESP_HAL_3RDPARTY_REPO}/components/esp_wifi/lib/${CHIP_SERIES}/libespnow.a) + ${ESP_HAL_3RDPARTY_REPO}/components/esp_wifi/lib/${CHIP_SERIES}/libpp.a) if(CONFIG_WPA_WAPI_PSK) nuttx_add_extra_library( ${ESP_HAL_3RDPARTY_REPO}/components/esp_wifi/lib/${CHIP_SERIES}/libwapi.a) diff --git a/arch/risc-v/src/common/espressif/Wireless.mk b/arch/risc-v/src/common/espressif/Wireless.mk index a30f6527c6dc2..d3c1389d31a82 100644 --- a/arch/risc-v/src/common/espressif/Wireless.mk +++ b/arch/risc-v/src/common/espressif/Wireless.mk @@ -27,12 +27,65 @@ INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)$(CHIP_SERIES)$(DELIM)include INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)include$(DELIM)esp_wifi +ifeq ($(CONFIG_ARCH_CHIP_ESP32C3),y) EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)controller$(DELIM)lib_esp32c3_family$(DELIM)$(CHIP_SERIES) +endif +ifneq ($(filter y,$(CONFIG_ARCH_CHIP_ESP32C6) $(CONFIG_ARCH_CHIP_ESP32H2)),) +ifeq ($(CONFIG_ESPRESSIF_BLE),y) +INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)common$(DELIM)osi$(DELIM)include +INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)common$(DELIM)tinycrypt$(DELIM)include +INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)common$(DELIM)tinycrypt$(DELIM)port +INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)host$(DELIM)nimble$(DELIM)nimble$(DELIM)porting$(DELIM)nimble$(DELIM)include +INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)host$(DELIM)nimble$(DELIM)port$(DELIM)include +INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)include$(DELIM)$(CHIP_SERIES)$(DELIM)include +INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)porting$(DELIM)include +INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)porting$(DELIM)transport$(DELIM)include +INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_common$(DELIM)include +INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_phy$(DELIM)include +INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_phy$(DELIM)$(CHIP_SERIES)$(DELIM)include +INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)src$(DELIM)platform$(DELIM)nimble$(DELIM)include + +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)common$(DELIM)tinycrypt$(DELIM)src$(DELIM)ecc.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)common$(DELIM)tinycrypt$(DELIM)src$(DELIM)ecc_dh.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)common$(DELIM)tinycrypt$(DELIM)src$(DELIM)ecc_platform_specific.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)common$(DELIM)tinycrypt$(DELIM)port$(DELIM)esp_tinycrypt_port.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)common$(DELIM)tinycrypt$(DELIM)src$(DELIM)sha256.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)common$(DELIM)tinycrypt$(DELIM)src$(DELIM)utils.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)porting$(DELIM)mem$(DELIM)bt_osi_mem.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)porting$(DELIM)mem$(DELIM)os_msys_init.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)porting$(DELIM)transport$(DELIM)src$(DELIM)hci_transport.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)porting$(DELIM)transport$(DELIM)driver$(DELIM)vhci$(DELIM)hci_driver_standard.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)controller$(DELIM)$(CHIP_SERIES)$(DELIM)ble.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)controller$(DELIM)$(CHIP_SERIES)$(DELIM)bt.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hal_security$(DELIM)ecc_hal.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_phy$(DELIM)src$(DELIM)btbb_init.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)src$(DELIM)platform$(DELIM)nimble$(DELIM)src$(DELIM)npl_os.c + +CFLAGS += $(DEFINE_PREFIX)ESP_PLATFORM=1 + +ifeq ($(CONFIG_ARCH_CHIP_ESP32C6),y) +EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)controller$(DELIM)lib_esp32c6$(DELIM)esp32c6-bt-lib$(DELIM)esp32c6 +endif + +ifeq ($(CONFIG_ARCH_CHIP_ESP32H2),y) +EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)controller$(DELIM)lib_esp32h2$(DELIM)esp32h2-bt-lib + +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_phy$(DELIM)src$(DELIM)lib_printf.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_phy$(DELIM)src$(DELIM)phy_common.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_phy$(DELIM)src$(DELIM)phy_init_esp32hxx.c +endif +endif +endif + EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_coex$(DELIM)lib$(DELIM)$(CHIP_SERIES) EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_phy$(DELIM)lib$(DELIM)$(CHIP_SERIES) EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_wifi$(DELIM)lib$(DELIM)$(CHIP_SERIES) -EXTRA_LIBS += -lphy -lcoexist -lmesh -lespnow +EXTRA_LIBS += -lphy -lcoexist + +ifneq ($(CONFIG_ARCH_CHIP_ESP32H2),y) +EXTRA_LIBS += -lmesh -lespnow +endif ifeq ($(CONFIG_ESPRESSIF_WIFI),y) diff --git a/arch/risc-v/src/esp32c6/CMakeLists.txt b/arch/risc-v/src/esp32c6/CMakeLists.txt index 877cf78ae45a7..12a654ea07dd6 100644 --- a/arch/risc-v/src/esp32c6/CMakeLists.txt +++ b/arch/risc-v/src/esp32c6/CMakeLists.txt @@ -29,6 +29,11 @@ if(CONFIG_ESPRESSIF_WIFI) list(APPEND SRCS esp_coex_adapter.c esp_wifi_adapter.c) endif() +if(CONFIG_ESPRESSIF_BLE) + list(APPEND SRCS esp_ble.c) + target_compile_definitions(arch PRIVATE ESP_PLATFORM) +endif() + target_compile_definitions(arch PRIVATE _RETARGETABLE_LOCKING) if(SRCS) diff --git a/arch/risc-v/src/esp32c6/Make.defs b/arch/risc-v/src/esp32c6/Make.defs index 13a3e6bf65767..925d542db489d 100644 --- a/arch/risc-v/src/esp32c6/Make.defs +++ b/arch/risc-v/src/esp32c6/Make.defs @@ -32,4 +32,9 @@ CHIP_CSRCS += esp_coex_adapter.c esp_wifi_adapter.c EXTRA_LIBS += -lcore -lnet80211 -lpp endif +ifeq ($(CONFIG_ESPRESSIF_BLE),y) +CHIP_CSRCS += esp_ble.c +EXTRA_LIBS += -lbtbb -lble_app +endif + CFLAGS += ${DEFINE_PREFIX}_RETARGETABLE_LOCKING diff --git a/arch/risc-v/src/esp32c6/esp_ble.c b/arch/risc-v/src/esp32c6/esp_ble.c new file mode 100644 index 0000000000000..02c177efb1d88 --- /dev/null +++ b/arch/risc-v/src/esp32c6/esp_ble.c @@ -0,0 +1,333 @@ +/**************************************************************************** + * arch/risc-v/src/esp32c6/esp_ble.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 + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#if defined(CONFIG_UART_BTH4) +# include +#endif + +#include "esp_bt.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* BLE packet buffer max size */ + +#define BLE_BUF_SIZE 1024 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct esp_ble_priv_s +{ + struct bt_driver_s drv; /* NuttX BT/BLE driver data */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int esp_ble_open(struct bt_driver_s *drv); +static int esp_ble_send(struct bt_driver_s *drv, + enum bt_buf_type_e type, + void *data, size_t len); +static void esp_ble_close(struct bt_driver_s *drv); +static void esp_ble_send_ready(void); +static int esp_ble_recv_cb(uint8_t *data, uint16_t len); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct esp_ble_priv_s g_ble_priv = +{ + .drv = + { + .head_reserve = H4_HEADER_SIZE, + .open = esp_ble_open, + .send = esp_ble_send, + .close = esp_ble_close + } +}; + +static esp_vhci_host_callback_t vhci_host_cb = +{ + .notify_host_send_available = esp_ble_send_ready, + .notify_host_recv = esp_ble_recv_cb +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp_ble_send_ready + * + * Description: + * If the controller could send HCI command will callback this function. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void esp_ble_send_ready(void) +{ +} + +/**************************************************************************** + * Name: esp_ble_recv_cb + * + * Description: + * BLE receive callback function when BLE hardware receive packet + * + * Input Parameters: + * data - BLE packet data pointer + * len - BLE packet length + * + * Returned Value: + * 0 on success or a negated value on failure. + * + ****************************************************************************/ + +static int esp_ble_recv_cb(uint8_t *data, uint16_t len) +{ + int ret; + bool valid; + enum bt_buf_type_e type; + struct esp_ble_priv_s *priv = &g_ble_priv; + + switch (data[0]) + { + case H4_EVT: + type = BT_EVT; + valid = true; + break; + case H4_ACL: + type = BT_ACL_IN; + valid = true; + break; + case H4_ISO: + type = BT_ISO_IN; + valid = true; + break; + default: + valid = false; + break; + } + + if (!valid) + { + ret = ERROR; + } + else + { + /* send packet to host */ + + ret = bt_netdev_receive(&priv->drv, type, + &data[H4_HEADER_SIZE], + len - H4_HEADER_SIZE); + if (ret < 0) + { + wlerr("Failed to receive ret=%d\n", ret); + } + } + + return ret; +} + +/**************************************************************************** + * Name: esp_ble_send + * + * Description: + * ESP32-C6 BLE send callback function for BT driver. + * + * Input Parameters: + * drv - BT driver pointer + * type - BT packet type + * data - BT packet data buffer pointer + * len - BT packet length + * + * Returned Value: + * Sent bytes on success or a negated value on failure. + * + ****************************************************************************/ + +static int esp_ble_send(struct bt_driver_s *drv, + enum bt_buf_type_e type, + void *data, size_t len) +{ + uint8_t *hdr = (uint8_t *)data - drv->head_reserve; + + if ((len + H4_HEADER_SIZE) > BLE_BUF_SIZE) + { + return -EINVAL; + } + + if (type == BT_CMD) + { + *hdr = H4_CMD; + } + else if (type == BT_ACL_OUT) + { + *hdr = H4_ACL; + } + else if (type == BT_ISO_OUT) + { + *hdr = H4_ISO; + } + else + { + return -EINVAL; + } + + if (esp_vhci_host_check_send_available()) + { + esp_vhci_host_send_packet(hdr, len + drv->head_reserve); + } + + return len; +} + +/**************************************************************************** + * Name: esp_ble_close + * + * Description: + * ESP32-C6 BLE close callback function for BT driver. + * + * Input Parameters: + * drv - BT driver pointer + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void esp_ble_close(struct bt_driver_s *drv) +{ +} + +/**************************************************************************** + * Name: esp_ble_open + * + * Description: + * ESP32-C6 BLE open callback function for BT driver. + * + * Input Parameters: + * drv - BT driver pointer + * + * Returned Value: + * OK on success or a negated value on failure. + * + ****************************************************************************/ + +static int esp_ble_open(struct bt_driver_s *drv) +{ + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp_ble_initialize + * + * Description: + * Init BT controller + * + * Input Parameters: + * None + * + * Returned Value: + * success or fail + * + ****************************************************************************/ + +int esp_ble_initialize(void) +{ + int ret; + esp_bt_controller_config_t cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); + + cfg.controller_task_stack_size = CONFIG_ESPRESSIF_BLE_TASK_STACK_SIZE; + cfg.controller_task_prio = CONFIG_ESPRESSIF_BLE_TASK_PRIORITY; + cfg.controller_run_cpu = CONFIG_BT_CTRL_PINNED_TO_CORE; + + if (esp_bt_controller_init(&cfg) != ESP_OK) + { + wlerr("Failed to initialize BLE\n"); + return ERROR; + } + + if (esp_bt_controller_enable(ESP_BT_MODE_BLE) != ESP_OK) + { + wlerr("Failed to Enable BLE\n"); + return ERROR; + } + + ret = esp_vhci_host_register_callback(&vhci_host_cb); + if (ret != ESP_OK) + { + esp_bt_controller_disable(); + wlerr("Failed to register BLE callback ret=%d\n", ret); + return ERROR; + } + +#if defined(CONFIG_UART_BTH4) + ret = uart_bth4_register(CONFIG_ESPRESSIF_BLE_TTY_NAME, &g_ble_priv.drv); +#else + ret = bt_netdev_register(&g_ble_priv.drv); +#endif + if (ret < 0) + { + wlerr("bt_netdev_register error: %d\n", ret); + return ret; + } + + return OK; +} diff --git a/arch/risc-v/src/esp32c6/esp_ble.h b/arch/risc-v/src/esp32c6/esp_ble.h new file mode 100644 index 0000000000000..4413c53ea6767 --- /dev/null +++ b/arch/risc-v/src/esp32c6/esp_ble.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * arch/risc-v/src/esp32c6/esp_ble.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 __ARCH_RISCV_SRC_ESP32C6_ESP_BLE_H +#define __ARCH_RISCV_SRC_ESP32C6_ESP_BLE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: esp_ble_initialize + * + * Description: + * Init BT controller + * + * Input Parameters: + * None + * + * Returned Value: + * success or fail + * + ****************************************************************************/ + +int esp_ble_initialize(void); + +#endif /* __ARCH_RISCV_SRC_ESP32C6_ESP_BLE_H */ diff --git a/arch/risc-v/src/esp32h2/CMakeLists.txt b/arch/risc-v/src/esp32h2/CMakeLists.txt index fa39d89da0707..ac555ff464a6b 100644 --- a/arch/risc-v/src/esp32h2/CMakeLists.txt +++ b/arch/risc-v/src/esp32h2/CMakeLists.txt @@ -25,6 +25,11 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../common/espressif espressif) set(SRCS esp_chip_rev.c) +if(CONFIG_ESPRESSIF_BLE) + list(APPEND SRCS esp_ble.c) + target_compile_definitions(arch PRIVATE ESP_PLATFORM) +endif() + target_compile_definitions(arch PRIVATE _RETARGETABLE_LOCKING) if(SRCS) diff --git a/arch/risc-v/src/esp32h2/Make.defs b/arch/risc-v/src/esp32h2/Make.defs index 25416b30e9593..06c36319668bf 100644 --- a/arch/risc-v/src/esp32h2/Make.defs +++ b/arch/risc-v/src/esp32h2/Make.defs @@ -25,4 +25,9 @@ include common/espressif/Make.defs CHIP_CSRCS += esp_chip_rev.c +ifeq ($(CONFIG_ESPRESSIF_BLE),y) +CHIP_CSRCS += esp_ble.c +EXTRA_LIBS += -lbtbb -lble_app +endif + CFLAGS += ${DEFINE_PREFIX}_RETARGETABLE_LOCKING diff --git a/arch/risc-v/src/esp32h2/esp_ble.c b/arch/risc-v/src/esp32h2/esp_ble.c new file mode 100644 index 0000000000000..013e79e365d2a --- /dev/null +++ b/arch/risc-v/src/esp32h2/esp_ble.c @@ -0,0 +1,333 @@ +/**************************************************************************** + * arch/risc-v/src/esp32h2/esp_ble.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 + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#if defined(CONFIG_UART_BTH4) +# include +#endif + +#include "esp_bt.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* BLE packet buffer max size */ + +#define BLE_BUF_SIZE 1024 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct esp_ble_priv_s +{ + struct bt_driver_s drv; /* NuttX BT/BLE driver data */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int esp_ble_open(struct bt_driver_s *drv); +static int esp_ble_send(struct bt_driver_s *drv, + enum bt_buf_type_e type, + void *data, size_t len); +static void esp_ble_close(struct bt_driver_s *drv); +static void esp_ble_send_ready(void); +static int esp_ble_recv_cb(uint8_t *data, uint16_t len); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct esp_ble_priv_s g_ble_priv = +{ + .drv = + { + .head_reserve = H4_HEADER_SIZE, + .open = esp_ble_open, + .send = esp_ble_send, + .close = esp_ble_close + } +}; + +static esp_vhci_host_callback_t vhci_host_cb = +{ + .notify_host_send_available = esp_ble_send_ready, + .notify_host_recv = esp_ble_recv_cb +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp_ble_send_ready + * + * Description: + * If the controller could send HCI command will callback this function. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void esp_ble_send_ready(void) +{ +} + +/**************************************************************************** + * Name: esp_ble_recv_cb + * + * Description: + * BLE receive callback function when BLE hardware receive packet + * + * Input Parameters: + * data - BLE packet data pointer + * len - BLE packet length + * + * Returned Value: + * 0 on success or a negated value on failure. + * + ****************************************************************************/ + +static int esp_ble_recv_cb(uint8_t *data, uint16_t len) +{ + int ret; + bool valid; + enum bt_buf_type_e type; + struct esp_ble_priv_s *priv = &g_ble_priv; + + switch (data[0]) + { + case H4_EVT: + type = BT_EVT; + valid = true; + break; + case H4_ACL: + type = BT_ACL_IN; + valid = true; + break; + case H4_ISO: + type = BT_ISO_IN; + valid = true; + break; + default: + valid = false; + break; + } + + if (!valid) + { + ret = ERROR; + } + else + { + /* send packet to host */ + + ret = bt_netdev_receive(&priv->drv, type, + &data[H4_HEADER_SIZE], + len - H4_HEADER_SIZE); + if (ret < 0) + { + wlerr("Failed to receive ret=%d\n", ret); + } + } + + return ret; +} + +/**************************************************************************** + * Name: esp_ble_send + * + * Description: + * ESP32-C6 BLE send callback function for BT driver. + * + * Input Parameters: + * drv - BT driver pointer + * type - BT packet type + * data - BT packet data buffer pointer + * len - BT packet length + * + * Returned Value: + * Sent bytes on success or a negated value on failure. + * + ****************************************************************************/ + +static int esp_ble_send(struct bt_driver_s *drv, + enum bt_buf_type_e type, + void *data, size_t len) +{ + uint8_t *hdr = (uint8_t *)data - drv->head_reserve; + + if ((len + H4_HEADER_SIZE) > BLE_BUF_SIZE) + { + return -EINVAL; + } + + if (type == BT_CMD) + { + *hdr = H4_CMD; + } + else if (type == BT_ACL_OUT) + { + *hdr = H4_ACL; + } + else if (type == BT_ISO_OUT) + { + *hdr = H4_ISO; + } + else + { + return -EINVAL; + } + + if (esp_vhci_host_check_send_available()) + { + esp_vhci_host_send_packet(hdr, len + drv->head_reserve); + } + + return len; +} + +/**************************************************************************** + * Name: esp_ble_close + * + * Description: + * ESP32-C6 BLE close callback function for BT driver. + * + * Input Parameters: + * drv - BT driver pointer + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void esp_ble_close(struct bt_driver_s *drv) +{ +} + +/**************************************************************************** + * Name: esp_ble_open + * + * Description: + * ESP32-C6 BLE open callback function for BT driver. + * + * Input Parameters: + * drv - BT driver pointer + * + * Returned Value: + * OK on success or a negated value on failure. + * + ****************************************************************************/ + +static int esp_ble_open(struct bt_driver_s *drv) +{ + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp_ble_initialize + * + * Description: + * Init BT controller + * + * Input Parameters: + * None + * + * Returned Value: + * success or fail + * + ****************************************************************************/ + +int esp_ble_initialize(void) +{ + int ret; + esp_bt_controller_config_t cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); + + cfg.controller_task_stack_size = CONFIG_ESPRESSIF_BLE_TASK_STACK_SIZE; + cfg.controller_task_prio = CONFIG_ESPRESSIF_BLE_TASK_PRIORITY; + cfg.controller_run_cpu = CONFIG_BT_CTRL_PINNED_TO_CORE; + + if (esp_bt_controller_init(&cfg) != ESP_OK) + { + wlerr("Failed to initialize BLE\n"); + return ERROR; + } + + if (esp_bt_controller_enable(ESP_BT_MODE_BLE) != ESP_OK) + { + wlerr("Failed to Enable BLE\n"); + return ERROR; + } + + ret = esp_vhci_host_register_callback(&vhci_host_cb); + if (ret != ESP_OK) + { + esp_bt_controller_disable(); + wlerr("Failed to register BLE callback ret=%d\n", ret); + return ERROR; + } + +#if defined(CONFIG_UART_BTH4) + ret = uart_bth4_register(CONFIG_ESPRESSIF_BLE_TTY_NAME, &g_ble_priv.drv); +#else + ret = bt_netdev_register(&g_ble_priv.drv); +#endif + if (ret < 0) + { + wlerr("bt_netdev_register error: %d\n", ret); + return ret; + } + + return OK; +} diff --git a/arch/risc-v/src/esp32h2/esp_ble.h b/arch/risc-v/src/esp32h2/esp_ble.h new file mode 100644 index 0000000000000..8c6490bbcaffb --- /dev/null +++ b/arch/risc-v/src/esp32h2/esp_ble.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * arch/risc-v/src/esp32h2/esp_ble.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 __ARCH_RISCV_SRC_ESP32H2_ESP_BLE_H +#define __ARCH_RISCV_SRC_ESP32H2_ESP_BLE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: esp_ble_initialize + * + * Description: + * Init BT controller + * + * Input Parameters: + * None + * + * Returned Value: + * success or fail + * + ****************************************************************************/ + +int esp_ble_initialize(void); + +#endif /* __ARCH_RISCV_SRC_ESP32H2_ESP_BLE_H */ From ff1cbd4b9c23754eef7c0ae715b5c602d63ab1a7 Mon Sep 17 00:00:00 2001 From: Eren Terzioglu Date: Mon, 25 May 2026 12:00:59 +0200 Subject: [PATCH 2/3] boards/risc-v/espressif: Add BLE board support for esp32[-c6|-h2] Add BLE board support for esp32c6 and esp32h2 Signed-off-by: Eren Terzioglu --- .../common/scripts/esp32c6_sections.ld | 11 +++ .../esp32c6-devkitc/configs/ble/defconfig | 67 +++++++++++++++++++ .../esp32c6-devkitc/src/esp32c6_bringup.c | 13 ++++ .../common/scripts/esp32h2_sections.ld | 11 +++ .../esp32h2-devkit/configs/ble/defconfig | 66 ++++++++++++++++++ .../esp32h2-devkit/src/esp32h2_bringup.c | 13 ++++ 6 files changed, 181 insertions(+) create mode 100644 boards/risc-v/esp32c6/esp32c6-devkitc/configs/ble/defconfig create mode 100644 boards/risc-v/esp32h2/esp32h2-devkit/configs/ble/defconfig diff --git a/boards/risc-v/esp32c6/common/scripts/esp32c6_sections.ld b/boards/risc-v/esp32c6/common/scripts/esp32c6_sections.ld index 7665b29b94613..df35644d61d55 100644 --- a/boards/risc-v/esp32c6/common/scripts/esp32c6_sections.ld +++ b/boards/risc-v/esp32c6/common/scripts/esp32c6_sections.ld @@ -446,6 +446,17 @@ SECTIONS *(EXCLUDE_FILE(*libnet80211.a *libpp.a) .wifislprxiram EXCLUDE_FILE(*libnet80211.a *libpp.a) .wifislprxiram.*) *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + +#ifdef CONFIG_ESPRESSIF_BLE + /* BLE controller (libble_app.a) uses custom section names; collect them + * here so elf2image does not see one ESP segment per input section (max 16). + */ + *(.high_perf_code_iram1) + *(.high_perf_code_iram1.*) + *(.adv_fast_execute_code_iram1) + *(.adv_fast_execute_code_iram1.*) +#endif + *(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */ *(.fini.literal) *(.fini) diff --git a/boards/risc-v/esp32c6/esp32c6-devkitc/configs/ble/defconfig b/boards/risc-v/esp32c6/esp32c6-devkitc/configs/ble/defconfig new file mode 100644 index 0000000000000..15fce8f4137b9 --- /dev/null +++ b/boards/risc-v/esp32c6/esp32c6-devkitc/configs/ble/defconfig @@ -0,0 +1,67 @@ +# +# 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="esp32c6-devkitc" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32C6_DEVKITC=y +CONFIG_ARCH_CHIP="esp32c6" +CONFIG_ARCH_CHIP_ESP32C6=y +CONFIG_ARCH_CHIP_ESP32C6WROOM1=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=15000 +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/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c b/boards/risc-v/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c index 0b221584f2d18..d44081a652ffc 100644 --- a/boards/risc-v/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c +++ b/boards/risc-v/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c @@ -147,6 +147,10 @@ # include "esp_board_mmcsd.h" #endif +#ifdef CONFIG_ESPRESSIF_BLE +# include "esp_ble.h" +#endif + #ifdef CONFIG_ESPRESSIF_USE_LP_CORE # include "espressif/esp_ulp.h" # ifdef CONFIG_ESPRESSIF_ULP_USE_TEST_BIN @@ -305,6 +309,15 @@ int esp_bringup(void) } #endif +#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_SPI # ifdef CONFIG_ESPRESSIF_SPI_SLAVE ret = board_spislavedev_initialize(ESPRESSIF_SPI2); diff --git a/boards/risc-v/esp32h2/common/scripts/esp32h2_sections.ld b/boards/risc-v/esp32h2/common/scripts/esp32h2_sections.ld index 7d9f5a11054b5..b4052cd7cb75b 100644 --- a/boards/risc-v/esp32h2/common/scripts/esp32h2_sections.ld +++ b/boards/risc-v/esp32h2/common/scripts/esp32h2_sections.ld @@ -431,6 +431,17 @@ SECTIONS _text_start = ABSOLUTE(.); *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + +#ifdef CONFIG_ESPRESSIF_BLE + /* BLE controller (libble_app.a) uses custom section names; collect them + * here so elf2image does not see one ESP segment per input section (max 16). + */ + *(.high_perf_code_iram1) + *(.high_perf_code_iram1.*) + *(.adv_fast_execute_code_iram1) + *(.adv_fast_execute_code_iram1.*) +#endif + *(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */ *(.fini.literal) *(.fini) diff --git a/boards/risc-v/esp32h2/esp32h2-devkit/configs/ble/defconfig b/boards/risc-v/esp32h2/esp32h2-devkit/configs/ble/defconfig new file mode 100644 index 0000000000000..6a40302329814 --- /dev/null +++ b/boards/risc-v/esp32h2/esp32h2-devkit/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="esp32h2-devkit" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32H2_DEVKIT=y +CONFIG_ARCH_CHIP="esp32h2" +CONFIG_ARCH_CHIP_ESP32H2=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=15000 +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/esp32h2/esp32h2-devkit/src/esp32h2_bringup.c b/boards/risc-v/esp32h2/esp32h2-devkit/src/esp32h2_bringup.c index 0540d712cc241..d1ce3a79f60c2 100644 --- a/boards/risc-v/esp32h2/esp32h2-devkit/src/esp32h2_bringup.c +++ b/boards/risc-v/esp32h2/esp32h2-devkit/src/esp32h2_bringup.c @@ -137,6 +137,10 @@ # include "esp_board_mmcsd.h" #endif +#ifdef CONFIG_ESPRESSIF_BLE +# include "esp_ble.h" +#endif + #include "esp32h2-devkit.h" /**************************************************************************** @@ -452,6 +456,15 @@ int esp_bringup(void) } #endif +#ifdef CONFIG_ESPRESSIF_BLE + ret = esp_ble_initialize(); + if (ret) + { + syslog(LOG_ERR, "ERROR: Failed to initialize BLE\n"); + return ret; + } +#endif + #ifdef CONFIG_PM /* Configure PM */ From defbed3d4ef7d579b1e46d2522fd52c8e0ad4cf5 Mon Sep 17 00:00:00 2001 From: Eren Terzioglu Date: Thu, 28 May 2026 12:07:35 +0200 Subject: [PATCH 3/3] Docs/platforms/esp32[-c6|-h2]: Add BLE docs for esp32[-c6|-h2] Add BLE docs for esp32c6 and esp32h2 Signed-off-by: Eren Terzioglu --- .../esp32c6/boards/esp32c6-devkitc/index.rst | 68 +++++++++++++++++++ .../platforms/risc-v/esp32c6/index.rst | 2 +- .../esp32h2/boards/esp32h2-devkit/index.rst | 68 +++++++++++++++++++ .../platforms/risc-v/esp32h2/index.rst | 2 +- 4 files changed, 138 insertions(+), 2 deletions(-) diff --git a/Documentation/platforms/risc-v/esp32c6/boards/esp32c6-devkitc/index.rst b/Documentation/platforms/risc-v/esp32c6/boards/esp32c6-devkitc/index.rst index 3b39191ef21b1..ba228e8e913a1 100644 --- a/Documentation/platforms/risc-v/esp32c6/boards/esp32c6-devkitc/index.rst +++ b/Documentation/platforms/risc-v/esp32c6/boards/esp32c6-devkitc/index.rst @@ -121,6 +121,74 @@ power if DTIM is short as the DTIM is determined by the access point. During ping operation power consumption should drop from 90-100mA to 30-40mA. +ble +--- + +This configuration is used to enable the Bluetooth Low Energy (BLE) of +ESP32-C6 chip. + +To test it, just run the following commands below. + +Confirm that bnep interface exist:: + + nsh> ifconfig + bnep0 Link encap:UNSPEC at DOWN mtu -9 + inet addr:0.0.0.0 DRaddr:0.0.0.0 Mask:0.0.0.0 + +Get basic information from it:: + + nsh> bt bnep0 info + Device: bnep0 + BDAddr: 8c:bf:ea:b3:4c:ea + Flags: 0000 + Free: 20 + ACL: 20 + SCO: 0 + Max: + ACL: 24 + SCO: 0 + MTU: + ACL: 70 + SCO: 70 + Policy: 0 + Type: 0 + +Start the scanning process:: + + nsh> bt bnep0 scan start + +Wait a little bit before stopping it. + +Then after some minutes stop it:: + + nsh> bt bnep0 scan stop + +Get the list of BLE devices found around you:: + + nsh> bt bnep0 scan get + Scan result: + 1. addr: d7:c4:e6:xx:xx:xx type: 0 + rssi: -62 + response type: 4 + advertiser data: 10 09 4d 69 20 XX XX XX XX XX XX XX XX XX XX 20 e + 2. addr: cb:23:18:xx:xx:xx type: 0 + rssi: -60 + response type: 0 + advertiser data: 02 01 06 1b ff XX XX XX ff ff ff ff ff ff ff ff 8 + 3. addr: cb:23:18:xx:xx:xx type: 0 + rssi: -60 + response type: 4 + advertiser data: 10 09 4d 69 20 XX XX XX XX XX XX XX XX XX XX 20 e + 4. addr: d7:c4:e6:xx:xx:xx type: 0 + rssi: -62 + response type: 0 + advertiser data: 02 01 06 1b ff XX XX XX ff ff ff ff ff ff ff ff e + 5. addr: d7:c4:e6:xx:xx:xx type: 0 + rssi: -62 + response type: 4 + advertiser data: 10 09 4d 69 20 XX XX XX XX XX XX XX XX XX XX 20 e + nsh> + bmp180 ------ diff --git a/Documentation/platforms/risc-v/esp32c6/index.rst b/Documentation/platforms/risc-v/esp32c6/index.rst index 1cda738ceeaaa..f0db2ae1a03a5 100644 --- a/Documentation/platforms/risc-v/esp32c6/index.rst +++ b/Documentation/platforms/risc-v/esp32c6/index.rst @@ -425,7 +425,7 @@ Peripheral Support NOTES ============== ======= ==================== ADC Yes Oneshot and internal temperature sensor AES Yes -Bluetooth No +Bluetooth Yes CAN/TWAI Yes DMA Yes ECC No diff --git a/Documentation/platforms/risc-v/esp32h2/boards/esp32h2-devkit/index.rst b/Documentation/platforms/risc-v/esp32h2/boards/esp32h2-devkit/index.rst index 5703429f07c90..ff979d67572e9 100644 --- a/Documentation/platforms/risc-v/esp32h2/boards/esp32h2-devkit/index.rst +++ b/Documentation/platforms/risc-v/esp32h2/boards/esp32h2-devkit/index.rst @@ -146,6 +146,74 @@ autopm This configuration makes the device automatically enter the low power consumption mode when in the idle state, powering off the cpu and other peripherals. +ble +--- + +This configuration is used to enable the Bluetooth Low Energy (BLE) of +ESP32-H2 chip. + +To test it, just run the following commands below. + +Confirm that bnep interface exist:: + + nsh> ifconfig + bnep0 Link encap:UNSPEC at DOWN mtu -9 + inet addr:0.0.0.0 DRaddr:0.0.0.0 Mask:0.0.0.0 + +Get basic information from it:: + + nsh> bt bnep0 info + Device: bnep0 + BDAddr: 58:41:81:40:02:08 + Flags: 0000 + Free: 20 + ACL: 20 + SCO: 0 + Max: + ACL: 24 + SCO: 0 + MTU: + ACL: 70 + SCO: 70 + Policy: 0 + Type: 0 + +Start the scanning process:: + + nsh> bt bnep0 scan start + +Wait a little bit before stopping it. + +Then after some minutes stop it:: + + nsh> bt bnep0 scan stop + +Get the list of BLE devices found around you:: + + nsh> bt bnep0 scan get + Scan result: + 1. addr: d7:c4:e6:xx:xx:xx type: 0 + rssi: -62 + response type: 4 + advertiser data: 10 09 4d 69 20 XX XX XX XX XX XX XX XX XX XX 20 e + 2. addr: cb:23:18:xx:xx:xx type: 0 + rssi: -60 + response type: 0 + advertiser data: 02 01 06 1b ff XX XX XX ff ff ff ff ff ff ff ff 8 + 3. addr: cb:23:18:xx:xx:xx type: 0 + rssi: -60 + response type: 4 + advertiser data: 10 09 4d 69 20 XX XX XX XX XX XX XX XX XX XX 20 e + 4. addr: d7:c4:e6:xx:xx:xx type: 0 + rssi: -62 + response type: 0 + advertiser data: 02 01 06 1b ff XX XX XX ff ff ff ff ff ff ff ff e + 5. addr: d7:c4:e6:xx:xx:xx type: 0 + rssi: -62 + response type: 4 + advertiser data: 10 09 4d 69 20 XX XX XX XX XX XX XX XX XX XX 20 e + nsh> + bmp180 ------ diff --git a/Documentation/platforms/risc-v/esp32h2/index.rst b/Documentation/platforms/risc-v/esp32h2/index.rst index 33ecb7278cf13..a37949ab829cb 100644 --- a/Documentation/platforms/risc-v/esp32h2/index.rst +++ b/Documentation/platforms/risc-v/esp32h2/index.rst @@ -416,7 +416,7 @@ Peripheral Support NOTES ============== ======= ==================== ADC Yes Oneshot and internal temperature sensor AES Yes -Bluetooth No +Bluetooth Yes CAN/TWAI Yes DMA Yes DS No