Add nimble hci example for c2

This commit is contained in:
GengYuchao 2022-06-17 21:55:40 +08:00
parent 69c63e63b3
commit ee55f016be
6 changed files with 129 additions and 0 deletions

View File

@ -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)

View File

@ -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
```

View File

@ -0,0 +1,4 @@
set(srcs "main.c")
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS ".")

View File

@ -0,0 +1,4 @@
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

View File

@ -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));
}

View File

@ -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