Skip to content

Commit

Permalink
Merge pull request #18439 from gschorcht/cpu/esp32/enable_ble_nimble
Browse files Browse the repository at this point in the history
cpu/esp32: add Bluetooth LE and NimBLE host support
  • Loading branch information
benpicco authored Aug 24, 2022
2 parents 4b75725 + 4b0d920 commit 2abc850
Show file tree
Hide file tree
Showing 49 changed files with 997 additions and 26 deletions.
11 changes: 11 additions & 0 deletions cpu/esp32/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ config HAS_CPU_ESP32
help
Indicates that the current CPU belongs to the ESP32x SoC series.

config HAS_ESP_BLE
bool
help
Indicates that the used ESP32x SoC supports Bluetooth LE.

config HAS_ESP_BLE_ESP32
bool
help
Indicates that the ESP32x SoC uses the SDK Bluetooth LE library
for the ESP32 variant.

config HAS_ESP_HW_COUNTER
bool
help
Expand Down
8 changes: 8 additions & 0 deletions cpu/esp32/Kconfig.common
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ if TEST_KCONFIG && HAS_ARCH_ESP32

# define configuration menu entries that common for all ESP32x SoC variants

config MODULE_ESP_BLE
bool "Enable Bluetooth LE interface"
depends on HAS_ESP_BLE
select MODULE_ESP_IDF_BLE
select PACKAGE_ESP32_SDK_LIB_PHY
select PACKAGE_ESP32_SDK_LIB_BT_ESP32 if HAS_ESP_BLE_ESP32

config MODULE_ESP_JTAG
bool "Enable JTAG debugging interface"
depends on HAS_ESP_JTAG
Expand All @@ -24,6 +31,7 @@ config MODULE_ESP_SPI_RAM
Say y to use external SPI RAM connected through the SPI interface.

rsource "bootloader/Kconfig"
rsource "esp-ble-nimble/Kconfig"
rsource "esp-idf/Kconfig"
rsource "esp-idf-api/Kconfig"
rsource "periph/Kconfig"
Expand Down
4 changes: 4 additions & 0 deletions cpu/esp32/Kconfig.esp32
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ config CPU_FAM_ESP32
select CPU_CORE_XTENSA_LX6
select HAS_ARCH_ESP32
select HAS_CPU_ESP32
select HAS_BLE_NIMBLE
select HAS_BLE_NIMBLE_NETIF
select HAS_ESP_BLE
select HAS_ESP_BLE_ESP32
select HAS_ESP_HW_COUNTER
select HAS_ESP_WIFI_ENTERPRISE
select HAS_PUF_SRAM
Expand Down
4 changes: 4 additions & 0 deletions cpu/esp32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ ifneq (, $(filter esp_bootloader, $(USEMODULE)))
DIRS += bootloader
endif

ifneq (, $(filter esp_ble_nimble, $(USEMODULE)))
DIRS += esp-ble-nimble
endif

ifneq (, $(filter esp_eth, $(USEMODULE)))
DIRS += esp-eth
endif
Expand Down
19 changes: 19 additions & 0 deletions cpu/esp32/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ ifneq (,$(filter cpp,$(USEMODULE)))
USEMODULE += pthread
endif

ifneq (,$(filter esp_ble,$(USEMODULE)))
# add additional modules and packages used for any BLE interface
FEATURES_REQUIRED += esp_ble
USEMODULE += esp_idf_ble
USEPKG += esp32_sdk_lib_phy
ifeq (esp32,$(CPU_FAM))
FEATURES_REQUIRED += esp_ble_esp32
USEPKG += esp32_sdk_lib_bt_esp32
endif
endif

ifneq (,$(filter esp_eth,$(USEMODULE)))
FEATURES_REQUIRED += esp_eth
USEMODULE += esp_idf_eth
Expand Down Expand Up @@ -120,6 +131,14 @@ ifneq (,$(filter mtd,$(USEMODULE)))
USEMODULE += esp_idf_spi_flash
endif

ifneq (,$(filter nimble,$(USEPKG)))
USEMODULE += esp_ble
USEMODULE += esp_ble_nimble
USEMODULE += nimble_host
USEMODULE += nimble_transport_hci_h4
USEMODULE += ztimer_msec
endif

ifneq (,$(filter periph_adc,$(USEMODULE)))
USEMODULE += esp_idf_adc
endif
Expand Down
7 changes: 7 additions & 0 deletions cpu/esp32/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ ifeq (xtensa,$(CPU_ARCH))
FEATURES_PROVIDED += esp_hw_counter
endif

ifeq (esp32,$(CPU_FAM))
FEATURES_PROVIDED += ble_nimble
FEATURES_PROVIDED += ble_nimble_netif
FEATURES_PROVIDED += esp_ble
FEATURES_PROVIDED += esp_ble_esp32
endif

ifneq (,$(filter esp32-wrover% esp32s2%r2 esp32s3%r2 esp32s3%r8 esp32s3%r8v,$(CPU_MODEL)))
FEATURES_PROVIDED += esp_spi_ram
ifneq (,$(filter esp32s3%r8 esp32s3%r8v,$(CPU_MODEL)))
Expand Down
31 changes: 29 additions & 2 deletions cpu/esp32/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ else
$(error Unkwnown ESP32x SoC architecture)
endif

PSEUDOMODULES += esp_ble
PSEUDOMODULES += esp_bootloader
PSEUDOMODULES += esp_gdbstub
PSEUDOMODULES += esp_hw_counter
Expand Down Expand Up @@ -80,6 +81,15 @@ ifneq (,$(filter xtensa%,$(TARGET_ARCH)))
INCLUDES += -I$(ESP32_SDK_DIR)/components/xtensa/$(CPU_FAM)/include
endif

ifneq (,$(filter esp_ble,$(USEMODULE)))
INCLUDES += -I$(ESP32_SDK_DIR)/components/bt/include/$(CPU_FAM)/include
endif

ifneq (,$(filter esp_ble_nimble,$(USEMODULE)))
INCLUDES += -I$(RIOTCPU)/$(CPU)/include/esp_ble_nimble
INCLUDES += $(NIMIBASE)/nimble/transport/common/hci_h4/include
endif

ifneq (,$(filter esp_spi_ram,$(USEMODULE)))
INCLUDES += -I$(ESP32_SDK_DIR)/components/esp_hw_support/include/soc/$(CPU_FAM)
endif
Expand Down Expand Up @@ -150,8 +160,14 @@ ifneq (,$(filter xtensa%,$(TARGET_ARCH)))
endif

LINKFLAGS += -L$(RIOTCPU)/$(CPU)/ld/$(CPU_FAM)/
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/$(CPU_FAM)/memory.ld

ifeq (,$(filter esp_ble,$(USEMODULE)))
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/$(CPU_FAM)/memory.ld
else
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/$(CPU_FAM)/memory_bt.ld
endif
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/$(CPU_FAM)/sections.ld

LINKFLAGS += -T$(ESP32_SDK_DIR)/components/soc/$(CPU_FAM)/ld/$(CPU_FAM).peripherals.ld
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.api.ld
LINKFLAGS += -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU_FAM)/ld/$(CPU_FAM).rom.ld
Expand Down Expand Up @@ -182,7 +198,7 @@ ifneq (,$(filter esp_wifi_any,$(USEMODULE)))
LINKFLAGS += -L$(ESP32_SDK_LIB_PHY_DIR)/$(CPU_FAM)
ARCHIVES += -lcoexist -lcore -lmesh -lnet80211 -lpp
ARCHIVES += -lphy -lstdc++
ifneq (,$(filter esp32,$(CPU_FAM)))
ifeq (esp32,$(CPU_FAM))
ARCHIVES += -lrtc
endif
endif
Expand All @@ -192,6 +208,17 @@ ifneq (,$(filter esp_now,$(USEMODULE)))
ARCHIVES += -lespnow -lmesh
endif

# Libraries needed when using esp_ble
ifneq (,$(filter esp_ble,$(USEMODULE)))
LINKFLAGS += -L$(ESP32_SDK_LIB_PHY_DIR)/$(CPU_FAM)
LINKFLAGS += -L$(ESP32_SDK_LIB_BT_DIR)/$(CPU_FAM)
ARCHIVES += -lbtdm_app
ARCHIVES += -lphy -lstdc++
ifeq (esp32,$(CPU_FAM))
ARCHIVES += -lrtc
endif
endif

ifneq (,$(filter cpp,$(USEMODULE)))
ARCHIVES += -lstdc++
endif
Expand Down
19 changes: 17 additions & 2 deletions cpu/esp32/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ This document describes the RIOT implementation for supported variants
2. [WiFi Network Interface](#esp32_wifi_network_interface)
3. [WiFi SoftAP Network Interface](#esp32_wifi_ap_network_interface)
4. [ESP-NOW Network Interface](#esp32_esp_now_network_interface)
4. [Bluetooth Interface](#esp32_esp_bluetooth_interface)
5. [Other Network Devices](#esp32_other_network_devices)
10. [Application-Specific Configurations](#esp32_application_specific_configurations)
1. [Make Variable `CFLAGS`](#esp32_config_make_variable)
Expand Down Expand Up @@ -204,7 +205,7 @@ The key features of ESP32 are:
| SPIs | 4 | yes (2) |
| UARTs | 3 | yes |
| WiFi | IEEE 802.11 b/g/n built in | yes |
| Bluetooth | v4.2 BR/EDR and BLE | no |
| Bluetooth | v4.2 BR/EDR and BLE | yes |
| Ethernet | MAC interface with dedicated DMA and IEEE 1588 support | yes |
| CAN | version 2.0 | yes |
| IR | up to 8 channels TX/RX | no |
Expand Down Expand Up @@ -335,7 +336,6 @@ at the moment:

- Only **one core** (the PRO CPU) is used because RIOT does not support running
multiple threads simultaneously.
- **Bluetooth** cannot be used at the moment.
- **Flash encryption** is not yet supported.

[Back to table of contents](#esp32_toc)
Expand Down Expand Up @@ -1691,6 +1691,21 @@ the channel of the AP asvalue for the parameter 'ESP_NOW_CHANNEL'.

[Back to table of contents](#esp32_toc)

## Bluetooth Network Interface {#esp32_esp_bluetooth_interface}

The following ESP32x SoC variants (families) integrate a Bluetooth Link
Controller and a Bluetooth baseband system:

- ESP32 supports Bluetooth v4.2 BR/EDR and Bluetooth LE
- ESP32-C3, ESP32-S3 support Bluetooth 5 and Bluetooth mesh

The Bluetooth interface can be used with the Bluetooth host implementation
of the NimBLE package. Use one of the `nimble_*` modules for different
applications to enable the Bluetooth interface and the NimBLE host
implementation. Please refer to the NimBle package documentation for details.

[Back to table of contents](#esp32_toc)

## Other Network Devices {#esp32_other_network_devices}

RIOT provides a number of driver modules for different types of network
Expand Down
22 changes: 22 additions & 0 deletions cpu/esp32/esp-ble-nimble/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2022 HAW Hamburg
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

config MODULE_ESP_BLE_NIMBLE
bool "ESP32 Bluetooth LE HCI for NimBLE host"
depends on TEST_KCONFIG
depends on CPU_FAM_ESP32
depends on HAS_ESP_BLE
default y if TEST_KCONFIG && MODULE_NIMBLE
select MODULE_ESP_BLE
select MODULE_NIMBLE_HOST
select MODULE_NIMBLE_TRANSPORT_HCI_H4
select MODULE_ZTIMER_MSEC

config HAS_ESP_BLE
bool
help
Indicates that a ESP32 Buetooth LE controller.
3 changes: 3 additions & 0 deletions cpu/esp32/esp-ble-nimble/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE=esp_ble_nimble

include $(RIOTBASE)/Makefile.base
17 changes: 17 additions & 0 deletions cpu/esp32/esp-ble-nimble/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (C) 2022 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @defgroup cpu_esp32_esp_ble_nimble ESP32 Bluetooth LE HCI for NimBLE host
* @ingroup cpu_esp32
* @brief ESP32 Bluetooth LE HCI implementation for NimBLE host
*
* This module realizes the HCI for NimBLE host using the ESP32 Bluetooth controller
*
* @author Gunar Schorcht <gunar@schorcht.net>
*/
Loading

0 comments on commit 2abc850

Please sign in to comment.