diff --git a/examples/bluetooth/nimble/hci/CMakeLists.txt b/examples/bluetooth/nimble/hci/CMakeLists.txt new file mode 100644 index 0000000000..ab9d65e43b --- /dev/null +++ b/examples/bluetooth/nimble/hci/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(hci) diff --git a/examples/bluetooth/nimble/hci/README.md b/examples/bluetooth/nimble/hci/README.md new file mode 100644 index 0000000000..94219f932f --- /dev/null +++ b/examples/bluetooth/nimble/hci/README.md @@ -0,0 +1,63 @@ +| Supported Targets | ESP32-C2 | +| ----------------- | -------- | + + +ESP-IDF UART HCI Controller +=========================== + +This is a BLE controller use UART as HCI interface. + +It can do the configuration of UART number and UART baudrate by menuconfig. + +## BLE HCI example + +(See the README.md file in the upper level 'examples' directory for more information about examples.) + +This example start controller with uart hci. + +It uses ESP32C2's Bluetooth controller. + +In this example, two UARTs are used: + +- UART0 is used as normal output or by IDF monitor + +- UART1 is used to convey HCI messages + +Pins 8, 9 are used as TxD, RxD PINs of UART1. + + +## How to use example + +### Configure the project + +``` +idf.py menuconfig +``` + + +### Build and Flash + +Build the project and flash it to the board, then run monitor tool to view serial output: + +``` +idf.py -p PORT flash monitor +``` + +(To exit the serial monitor, type ``Ctrl-]``.) + +See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. + +## Example Output + +There is this console output when bleprph is connected and characteristic is read: + +``` +set nimble port tx:8, rx:9. +set baud:115200. +controller lib commit: [fb738d4] +controller rom commit: [3314f9d] +I (346) system_api: Base MAC address is not set +I (356) system_api: read default base MAC address from EFUSE + +``` + diff --git a/examples/bluetooth/nimble/hci/main/CMakeLists.txt b/examples/bluetooth/nimble/hci/main/CMakeLists.txt new file mode 100644 index 0000000000..023dd5e462 --- /dev/null +++ b/examples/bluetooth/nimble/hci/main/CMakeLists.txt @@ -0,0 +1,4 @@ +set(srcs "main.c") + +idf_component_register(SRCS "${srcs}" + INCLUDE_DIRS ".") diff --git a/examples/bluetooth/nimble/hci/main/component.mk b/examples/bluetooth/nimble/hci/main/component.mk new file mode 100644 index 0000000000..a98f634eae --- /dev/null +++ b/examples/bluetooth/nimble/hci/main/component.mk @@ -0,0 +1,4 @@ +# +# "main" pseudo-component makefile. +# +# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) diff --git a/examples/bluetooth/nimble/hci/main/main.c b/examples/bluetooth/nimble/hci/main/main.c new file mode 100644 index 0000000000..440bfc7113 --- /dev/null +++ b/examples/bluetooth/nimble/hci/main/main.c @@ -0,0 +1,43 @@ +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "esp_log.h" +#include "nvs_flash.h" + +#include "esp_bt.h" + +#ifndef CONFIG_BT_LE_HCI_INTERFACE_USE_UART +#error "Please Enable Uart for HCI" +#endif + +#define TAG "BLE_HCI" + +void +app_main(void) +{ + esp_err_t ret; + /* Initialize NVS — it is used to store PHY calibration data */ + ret = nvs_flash_init(); + if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { + ESP_ERROR_CHECK(nvs_flash_erase()); + ret = nvs_flash_init(); + } + ESP_ERROR_CHECK(ret); + + esp_bt_controller_config_t config_opts = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); + + /* + * Initialize Bluetooth Controller parameters. + */ + ESP_ERROR_CHECK(esp_bt_controller_init(&config_opts)); + + /* + * Enable the task stack of the Bluetooth Controller. + */ + ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE)); + + +} diff --git a/examples/bluetooth/nimble/hci/sdkconfig.defaults b/examples/bluetooth/nimble/hci/sdkconfig.defaults new file mode 100644 index 0000000000..4bf1aa850d --- /dev/null +++ b/examples/bluetooth/nimble/hci/sdkconfig.defaults @@ -0,0 +1,9 @@ +# This file was generated using idf.py save-defconfig. It can be edited manually. +# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration +# +CONFIG_BT_ENABLED=y +CONFIG_BT_CONTROLLER_ONLY=y +CONFIG_BT_LE_HCI_INTERFACE_USE_UART=y +CONFIG_BT_LE_HCI_UART_TX_PIN=8 +CONFIG_BT_LE_HCI_UART_RX_PIN=9 +CONFIG_BT_LE_HCI_UART_BAUD=115200