Skip to content

Commit ed6195d

Browse files
committed
Merge branch 'feature/ble_example' into 'feature/esp_as_mcu_host'
feature/ble_example See merge request app-frameworks/esp_hosted!497
2 parents 1c568c9 + 0de6579 commit ed6195d

File tree

10 files changed

+1146
-1
lines changed

10 files changed

+1146
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.16)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
project(bleprph_host_only_vhci)
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-H2 | ESP32-S3 | ESP32-P4 |
2+
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
3+
4+
# BLE Host-Only Peripheral VHCI Example
5+
6+
This example uses the Bluetooth VHCI transport provided by ESP-Hosted.
7+
8+
To use the VHCI transport in the application, the Bluetooth controller
9+
should be disabled and the default uart-transport should also be
10+
disabled (when the controller is disabled, by default the
11+
uart-transport is selected). The Bluetooth VHCI transport in
12+
ESP-Hosted should also be enabled.
13+
14+
Refer to the `sdkconfig.defaults` file which has the required
15+
configuration.
16+
17+
To test this demo, any BLE scanner app can be used.
18+
19+
## How to Use This Example
20+
21+
Before project configuration and build, be sure to set the correct
22+
chip target using:
23+
24+
```bash
25+
idf.py set-target <chip_name>
26+
```
27+
28+
### Configure the project
29+
30+
Open the project configuration menu:
31+
32+
```bash
33+
idf.py menuconfig
34+
```
35+
36+
In the `Component config-> Bluetooth` menu:
37+
38+
* Select `controller` to Disabled.
39+
* Disable `Nimble Options-> Host-controller Transport -> Enable Uart Transport`.
40+
41+
In the `Component config-> ESP-Hosted config` menu:
42+
43+
* Enable `Bluetooth Support-> Enable Hosted Bluetooth support`
44+
45+
### Build and Flash
46+
47+
Run `idf.py -p PORT flash monitor` to build, flash and monitor the
48+
project.
49+
50+
(To exit the serial monitor, type ``Ctrl-]``.)
51+
52+
See the [Getting Started Guide](https://idf.espressif.com/) for full
53+
steps to configure and use ESP-IDF to build projects.
54+
55+
## Example Output
56+
57+
This is the console output when `bleprph_host_only_vhci` is running on
58+
the ESP32-P4 and using the Bluetooth Controller of the ESP32C6 on the
59+
ESP32-P4-Function-EV-Board. The data is transferred through SDIO
60+
between the ESP32-P4 and ESP32-C6:
61+
62+
```
63+
I (25) boot: ESP-IDF v5.4-dev-2793-g24047f9a04-dirty 2nd stage bootloader
64+
I (26) boot: compile time Sep 9 2024 16:23:48
65+
I (27) boot: Multicore bootloader
66+
I (32) boot: chip revision: v0.1
67+
I (34) boot: efuse block revision: v0.0
68+
I (39) boot.esp32p4: SPI Speed : 80MHz
69+
I (44) boot.esp32p4: SPI Mode : DIO
70+
I (49) boot.esp32p4: SPI Flash Size : 2MB
71+
I (53) boot: Enabling RNG early entropy source...
72+
I (59) boot: Partition Table:
73+
I (62) boot: ## Label Usage Type ST Offset Length
74+
I (70) boot: 0 nvs WiFi data 01 02 00009000 00006000
75+
I (77) boot: 1 phy_init RF data 01 01 0000f000 00001000
76+
I (84) boot: 2 factory factory app 00 00 00010000 00100000
77+
I (93) boot: End of partition table
78+
I (96) esp_image: segment 0: paddr=00010020 vaddr=40070020 size=2ae08h (175624) map
79+
I (135) esp_image: segment 1: paddr=0003ae30 vaddr=30100000 size=0000ch ( 12) load
80+
I (137) esp_image: segment 2: paddr=0003ae44 vaddr=3010000c size=00038h ( 56) load
81+
I (142) esp_image: segment 3: paddr=0003ae84 vaddr=4ff00000 size=05194h ( 20884) load
82+
I (154) esp_image: segment 4: paddr=00040020 vaddr=40000020 size=638b0h (407728) map
83+
I (226) esp_image: segment 5: paddr=000a38d8 vaddr=4ff05194 size=0b9a0h ( 47520) load
84+
I (237) esp_image: segment 6: paddr=000af280 vaddr=4ff10b80 size=02328h ( 9000) load
85+
I (244) boot: Loaded app from partition at offset 0x10000
86+
I (244) boot: Disabling RNG early entropy source...
87+
I (258) cpu_start: Multicore app
88+
W (267) clk: esp_perip_clk_init() has not been implemented yet
89+
I (274) cpu_start: Pro cpu start user code
90+
I (274) cpu_start: cpu freq: 360000000 Hz
91+
I (274) app_init: Application information:
92+
I (277) app_init: Project name: bleprph_host_only_vhci
93+
I (283) app_init: App version: 1c568c9-dirty
94+
I (288) app_init: Compile time: Sep 9 2024 16:23:43
95+
I (294) app_init: ELF file SHA256: ee5a16527...
96+
I (299) app_init: ESP-IDF: v5.4-dev-2793-g24047f9a04-dirty
97+
I (306) efuse_init: Min chip rev: v0.1
98+
I (311) efuse_init: Max chip rev: v0.99
99+
I (316) efuse_init: Chip rev: v0.1
100+
I (321) heap_init: Initializing. RAM available for dynamic allocation:
101+
I (328) heap_init: At 4FF160B0 len 00024F10 (147 KiB): RAM
102+
I (334) heap_init: At 4FF3AFC0 len 00004BF0 (18 KiB): RAM
103+
I (340) heap_init: At 4FF40000 len 00060000 (384 KiB): RAM
104+
I (347) heap_init: At 50108080 len 00007F80 (31 KiB): RTCRAM
105+
I (353) heap_init: At 30100044 len 00001FBC (7 KiB): TCM
106+
I (360) spi_flash: detected chip: generic
107+
I (363) spi_flash: flash io: dio
108+
W (367) spi_flash: Detected size(16384k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
109+
I (381) host_init: ESP Hosted : Host chip_ip[18]
110+
I (409) H_API: ESP-Hosted starting. Hosted_Tasks: prio:23, stack: 5120 RPC_task_stack: 5120
111+
sdio_mempool_create free:181028 min-free:181028 lfb-def:139264 lfb-8bit:139264
112+
113+
I (414) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
114+
I (423) gpio: GPIO[19]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
115+
I (433) gpio: GPIO[14]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
116+
I (442) gpio: GPIO[15]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
117+
I (451) gpio: GPIO[16]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
118+
I (461) gpio: GPIO[17]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
119+
I (470) H_API: ** add_esp_wifi_remote_channels **
120+
I (475) transport: Add ESP-Hosted channel IF[1]: S[0] Tx[0x4000d110] Rx[0x4001b4aa]
121+
0x4000d110: transport_drv_sta_tx at /home/kysoh/projects/esp_as_mcu_host/examples/bleprph_host_only_vhci/components/esp_hosted/host/drivers/transport/transport_drv.c:208
122+
0x4001b4aa: esp_wifi_remote_channel_rx at /home/kysoh/projects/esp_as_mcu_host/examples/bleprph_host_only_vhci/managed_components/espressif__esp_wifi_remote/esp_wifi_remote_net.c:19
123+
124+
I (484) transport: Add ESP-Hosted channel IF[2]: S[0] Tx[0x4000d058] Rx[0x4001b4aa]
125+
0x4000d058: transport_drv_ap_tx at /home/kysoh/projects/esp_as_mcu_host/examples/bleprph_host_only_vhci/components/esp_hosted/host/drivers/transport/transport_drv.c:238
126+
0x4001b4aa: esp_wifi_remote_channel_rx at /home/kysoh/projects/esp_as_mcu_host/examples/bleprph_host_only_vhci/managed_components/espressif__esp_wifi_remote/esp_wifi_remote_net.c:19
127+
128+
I (493) main_task: Started on CPU0
129+
I (503) main_task: Calling app_main()
130+
I (513) transport: Attempt connection with slave: retry[0]
131+
I (513) transport: Reset slave using GPIO[54]
132+
I (513) os_wrapper_esp: GPIO [54] configured
133+
I (513) gpio: GPIO[54]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
134+
I (1693) sdio_wrapper: SDIO master: Data-Lines: 4-bit Freq(KHz)[40000 KHz]
135+
I (1693) sdio_wrapper: GPIOs: CLK[18] CMD[19] D0[14] D1[15] D2[16] D3[17] Slave_Reset[54]
136+
I (1693) H_SDIO_DRV: Starting SDIO process rx task
137+
I (1693) sdio_wrapper: Queues: Tx[20] Rx[20] SDIO-Rx-Mode[1]
138+
I (1733) gpio: GPIO[15]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
139+
I (1733) gpio: GPIO[17]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
140+
Name:
141+
Type: SDIO
142+
Speed: 40.00 MHz (limit: 40.00 MHz)
143+
Size: 0MB
144+
CSD: ver=1, sector_size=0, capacity=0 read_bl_len=0
145+
SCR: sd_spec=0, bus_width=0
146+
TUPLE: DEVICE, size: 3: D9 01 FF
147+
TUPLE: MANFID, size: 4
148+
MANF: 0092, CARD: 6666
149+
TUPLE: FUNCID, size: 2: 0C 00
150+
TUPLE: FUNCE, size: 4: 00 00 02 32
151+
TUPLE: CONFIG, size: 5: 01 01 00 02 07
152+
TUPLE: CFTABLE_ENTRY, size: 8
153+
INDX: C1, Intface: 1, Default: 1, Conf-Entry-Num: 1
154+
IF: 41
155+
FS: 30, misc: 0, mem_space: 1, irq: 1, io_space: 0, timing: 0, power: 0
156+
IR: 30, mask: 1, IRQ: FF FF
157+
LEN: FFFF
158+
TUPLE: END
159+
I (1783) sdio_wrapper: Function 0 Blocksize: 512
160+
I (1793) sdio_wrapper: Function 1 Blocksize: 512
161+
I (1793) H_SDIO_DRV: SDIO Host operating in STREAMING MODE
162+
I (1803) H_SDIO_DRV: generate slave intr
163+
I (1813) transport: Received INIT event from ESP32 peripheral
164+
I (1813) transport: EVENT: 12
165+
I (1813) transport: EVENT: 11
166+
I (1823) transport: capabilities: 0xd
167+
I (1823) transport: Features supported are:
168+
I (1833) transport: * WLAN
169+
I (1833) transport: - HCI over SDIO
170+
I (1843) transport: - BLE only
171+
I (1843) transport: EVENT: 13
172+
I (1843) transport: ESP board type is : 13
173+
174+
I (1853) transport: Base transport is set-up
175+
176+
I (1853) transport: Slave chip Id[12]
177+
I (1863) vhci_drv: Host BT Support: Enabled
178+
I (1863) vhci_drv: BT Transport Type: VHCI
179+
I (1873) H_SDIO_DRV: Received INIT event
180+
I (1883) rpc_wrap: Received Slave ESP Init
181+
I (2623) NimBLE_BLE_PRPH: BLE Host Task Started
182+
I (2623) uart: queue free spaces: 8
183+
I (2623) main_task: Returned from app_main()
184+
I (2623) NimBLE: GAP procedure initiated: stop advertising.
185+
186+
I (2633) NimBLE: Device Address:
187+
I (2633) NimBLE: 40:4c:ca:5b:9a:e2
188+
I (2633) NimBLE:
189+
190+
I (2643) NimBLE: GAP procedure initiated: advertise;
191+
I (2643) NimBLE: disc_mode=2
192+
I (2653) NimBLE: adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
193+
I (2663) NimBLE:
194+
```
195+
196+
## Troubleshooting
197+
198+
For any technical queries, please open an [issue](https://github.com/espressif/esp-hosted/issues) on ESP-Hosted on GitHub. We will get back to you soon.
199+
200+
## References
201+
202+
* Bluetooth Implementation in ESP-Hosted: https://github.com/espressif/esp-hosted/blob/feature/esp_as_mcu_host/docs/bluetooth_implementation.md
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set(srcs "main.c"
2+
"gatt_svr.c")
3+
4+
idf_component_register(SRCS "${srcs}"
5+
INCLUDE_DIRS ".")
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
menu "Example Configuration"
2+
3+
choice EXAMPLE_USE_IO_TYPE
4+
prompt "I/O Capability"
5+
default BLE_SM_IO_CAP_NO_IO
6+
help
7+
I/O capability of device.
8+
9+
config BLE_SM_IO_CAP_DISP_ONLY
10+
bool "DISPLAY ONLY"
11+
config BLE_SM_IO_CAP_DISP_YES_NO
12+
bool "DISPLAY YESNO"
13+
config BLE_SM_IO_CAP_KEYBOARD_ONLY
14+
bool "KEYBOARD ONLY"
15+
config BLE_SM_IO_CAP_NO_IO
16+
bool "Just works"
17+
config BLE_SM_IO_CAP_KEYBOARD_DISP
18+
bool "Both KEYBOARD & DISPLAY"
19+
endchoice
20+
21+
config EXAMPLE_IO_TYPE
22+
int
23+
default 0 if BLE_SM_IO_CAP_DISP_ONLY
24+
default 1 if BLE_SM_IO_CAP_DISP_YES_NO
25+
default 2 if BLE_SM_IO_CAP_KEYBOARD_ONLY
26+
default 3 if BLE_SM_IO_CAP_NO_IO
27+
default 4 if BLE_SM_IO_CAP_KEYBOARD_DISP
28+
29+
config EXAMPLE_BONDING
30+
bool
31+
default n
32+
prompt "Use Bonding"
33+
help
34+
Use this option to enable/disable bonding.
35+
36+
config EXAMPLE_MITM
37+
bool
38+
default n
39+
prompt "MITM security"
40+
help
41+
Use this option to enable/disable MITM security.
42+
43+
config EXAMPLE_USE_SC
44+
bool
45+
depends on BT_NIMBLE_SM_SC
46+
default n
47+
prompt "Use Secure Connection feature"
48+
help
49+
Use this option to enable/disable Security Manager Secure Connection 4.2 feature.
50+
51+
config EXAMPLE_EXTENDED_ADV
52+
bool
53+
depends on SOC_BLE_50_SUPPORTED && BT_NIMBLE_50_FEATURE_SUPPORT
54+
default y if SOC_ESP_NIMBLE_CONTROLLER
55+
select BT_NIMBLE_EXT_ADV
56+
prompt "Enable Extended Adv"
57+
help
58+
Use this option to enable extended advertising in the example.
59+
If this option is disabled, ensure config BT_NIMBLE_EXT_ADV is
60+
also disabled from Nimble stack menuconfig
61+
62+
config EXAMPLE_RANDOM_ADDR
63+
bool
64+
prompt "Advertise RANDOM Address"
65+
help
66+
Use this option to advertise a random address instead of public address
67+
68+
config EXAMPLE_ENCRYPTION
69+
bool
70+
prompt "Enable Link Encryption"
71+
help
72+
This adds Encrypted Read and Write permissions in the custom GATT server.
73+
74+
config EXAMPLE_RESOLVE_PEER_ADDR
75+
bool
76+
prompt "Enable resolving peer address"
77+
help
78+
Use this option to enable resolving peer's address.
79+
80+
endmenu
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef H_BLEPRPH_
7+
#define H_BLEPRPH_
8+
9+
#include <stdbool.h>
10+
#include "nimble/ble.h"
11+
#include "modlog/modlog.h"
12+
#include "esp_peripheral.h"
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
struct ble_hs_cfg;
18+
struct ble_gatt_register_ctxt;
19+
20+
/** GATT server. */
21+
#define GATT_SVR_SVC_ALERT_UUID 0x1811
22+
#define GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47
23+
#define GATT_SVR_CHR_NEW_ALERT 0x2A46
24+
#define GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48
25+
#define GATT_SVR_CHR_UNR_ALERT_STAT_UUID 0x2A45
26+
#define GATT_SVR_CHR_ALERT_NOT_CTRL_PT 0x2A44
27+
28+
void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
29+
int gatt_svr_init(void);
30+
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
35+
#endif

0 commit comments

Comments
 (0)