Skip to content

Commit

Permalink
esp32[c3]: Add BLE support
Browse files Browse the repository at this point in the history
  • Loading branch information
eren-terzioglu committed Oct 10, 2024
1 parent fee7e0c commit 05df057
Show file tree
Hide file tree
Showing 16 changed files with 4,781 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,74 @@ All of the configurations presented below can be tested by running the following
Where <config_name> is the name of board configuration you want to use, i.e.: nsh, buttons, wifi...
Then use a serial console terminal like ``picocom`` configured to 115200 8N1.

ble
---

This configuration is used to enable the Bluetooth Low Energy (BLE) of
ESP32-C3 chip.

To test it, just run the following commands below.

Confirm that bnep interface exist::

nsh> ifconfig
bnep0 Link encap:UNSPEC at DOWN
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: 86:f7:03:09:41:4d
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
------

Expand Down
39 changes: 39 additions & 0 deletions arch/risc-v/src/common/espressif/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,14 @@ config ESPRESSIF_WIFI
---help---
Enable Wi-Fi support

config ESPRESSIF_BLE
bool "BLE"
depends on ESPRESSIF_ESP32C3
default n
select ESP_WIRELESS
---help---
Enable BLE support

config ESP_COEX_SW_COEXIST_ENABLE
bool "Software WiFi/Bluetooth/IEEE 802.15.4 coexistence"
depends on (ESPRESSIF_WIFI && ESPRESSIF_BLE) || \
Expand All @@ -478,6 +486,13 @@ config ESP_COEX_SW_COEXIST_ENABLE
If only Bluetooth is used, it is recommended to disable this option to reduce binary file
size.

menuconfig ESPRESSIF_WIFI_BT_COEXIST
bool "Wi-Fi and BT coexist"
default y if ESPRESSIF_WIFI && ESPRESSIF_BLE
default n
depends on ESPRESSIF_WIFI && ESPRESSIF_BLE
select ESPRESSIF_WIFI_STA_DISCONNECT_PM

config ESP_MCPWM
bool "Motor Control PWM (MCPWM)"
default n
Expand Down Expand Up @@ -933,6 +948,30 @@ endchoice # ESP_POWER_SAVE_MODE

endmenu # ESPRESSIF_WIFI

menu "BLE Configuration"
depends on ESPRESSIF_BLE

config ESPRESSIF_BLE_TTY_NAME
string "BLE TTY device name"
default "/dev/ttyHCI0"
depends on UART_BTH4

config ESPRESSIF_BLE_TASK_STACK_SIZE
int "Controller task stack size"
default 4096

config ESPRESSIF_BLE_TASK_PRIORITY
int "Controller task priority"
default 253

config ESPRESSIF_BLE_INTERRUPT_SAVE_STATUS
int "Number of interrupt save status"
default 3
---help---
Number of interrupt save status variables to keep track. Increase it if any related bug is found.

endmenu # BLE Configuration

menu "UART Configuration"
depends on ESPRESSIF_UART

Expand Down
6 changes: 3 additions & 3 deletions arch/risc-v/src/common/espressif/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ ifeq ($(CONFIG_ESP_WIRELESS),y)
ifeq ($(CONFIG_ESPRESSIF_WIFI),y)
CHIP_CSRCS += esp_wifi_init.c
CHIP_CSRCS += esp_wlan.c
CHIP_CSRCS += esp_wifi_utils.c
endif
CHIP_CSRCS += esp_wifi_utils.c
endif

ifeq ($(CONFIG_ESP_MCPWM),y)
Expand All @@ -136,7 +136,7 @@ endif

ESP_HAL_3RDPARTY_REPO = esp-hal-3rdparty
ifndef ESP_HAL_3RDPARTY_VERSION
ESP_HAL_3RDPARTY_VERSION = b4c723a119344b4b71d69819019d55637fb570fd
ESP_HAL_3RDPARTY_VERSION = ca869dd97ed2c01187b85b759c0d6edb27c12c21
endif

ifndef ESP_HAL_3RDPARTY_URL
Expand Down Expand Up @@ -168,7 +168,7 @@ chip/$(ESP_HAL_3RDPARTY_REPO):
$(Q) git -C chip/$(ESP_HAL_3RDPARTY_REPO) checkout --quiet $(ESP_HAL_3RDPARTY_VERSION)
ifeq ($(CONFIG_ESP_WIRELESS),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/mbedtls/mbedtls components/esp_phy/lib components/esp_wifi/lib components/esp_coex/lib
$(Q) git -C chip/$(ESP_HAL_3RDPARTY_REPO) submodule --quiet update --init $(GIT_DEPTH_PARAMETER) components/mbedtls/mbedtls 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)/components/mbedtls/mbedtls reset --quiet --hard
$(Q) echo "Applying patches..."
$(Q) cd chip/$(ESP_HAL_3RDPARTY_REPO)/components/mbedtls/mbedtls && git apply ../../../nuttx/patches/components/mbedtls/mbedtls/*.patch
Expand Down
1 change: 1 addition & 0 deletions arch/risc-v/src/common/espressif/Wireless.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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

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)
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)
Expand Down
6 changes: 6 additions & 0 deletions arch/risc-v/src/common/espressif/esp_wifi_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/wireless/wireless.h>

#ifdef CONFIG_ESPRESSIF_WIFI
#include "esp_wifi_adapter.h"

#include "esp_log.h"
Expand All @@ -44,7 +45,9 @@
#include "esp_wpa.h"
#include "rom/ets_sys.h"
#include "soc/soc_caps.h"
#endif /* CONFIG_ESPRESSIF_WIFI */

#include "esp_err.h"
#include "esp_wifi_utils.h"

/****************************************************************************
Expand Down Expand Up @@ -104,6 +107,8 @@ static uint8_t g_channel_list[CHANNEL_MAX_NUM];
* Public Functions
****************************************************************************/

#ifdef CONFIG_ESPRESSIF_WIFI

/****************************************************************************
* Name: esp_wifi_start_scan
*
Expand Down Expand Up @@ -573,6 +578,7 @@ void esp_wifi_scan_event_parse(void)
priv->scan_status = ESP_SCAN_DONE;
nxsem_post(&priv->scan_signal);
}
#endif /* CONFIG_ESPRESSIF_WIFI */

/****************************************************************************
* Name: esp_wifi_to_errno
Expand Down
4 changes: 4 additions & 0 deletions arch/risc-v/src/common/espressif/esp_wifi_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ extern "C"
* Public Function Prototypes
****************************************************************************/

#ifdef CONFIG_ESPRESSIF_WIFI

/****************************************************************************
* Name: esp_wifi_start_scan
*
Expand Down Expand Up @@ -95,6 +97,8 @@ int esp_wifi_get_scan_results(struct iwreq *iwr);

void esp_wifi_scan_event_parse(void);

#endif

/****************************************************************************
* Name: esp_wifi_to_errno
*
Expand Down
5 changes: 5 additions & 0 deletions arch/risc-v/src/esp32c3/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,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 esp_ble_adapter.c esp_wireless.c
EXTRA_LIBS += -lbtbb -lbtdm_app
endif

CFLAGS += ${DEFINE_PREFIX}_RETARGETABLE_LOCKING
Loading

0 comments on commit 05df057

Please sign in to comment.