HCI not working in ESP-IDF 4.1
Posted: Sat Oct 03, 2020 2:32 am
I have an application using the ESP32 as a bluetooth coprocessor connected to a Raspberry PI compute module. I connected it over UART0, so I did a pin remapping, and have been having some success on ESP-IDF v4 and have been able to connect and send quite a bit of data back and forth over RFCOMM.
However, the connection has always been a little flaky. Most notably I was having a problem where data was being dropped when transferring a larger stream, about 58K of data. Not sure of the exact problem I tried to upgrade to ESP-IDF 4.1. Since upgrading I haven't been able to connect at all. The phone I'm connecting from sees the device and is able to pair, but it fails when trying to call bluetoothsocket.connect() from android. Within that function it looks like it fails trying to read the channel number from the socket. I tried both using the standard code from the controller_hci_uart sample with the few extra lines for the pin remap as well as a slightly modified version of the old code that worked with 4.0.
Are there any known issues wth ESP-IDF 4.1 for HCI that might be throwing a wrench in things? For reference, here's the code I was running with 4.0:
However, the connection has always been a little flaky. Most notably I was having a problem where data was being dropped when transferring a larger stream, about 58K of data. Not sure of the exact problem I tried to upgrade to ESP-IDF 4.1. Since upgrading I haven't been able to connect at all. The phone I'm connecting from sees the device and is able to pair, but it fails when trying to call bluetoothsocket.connect() from android. Within that function it looks like it fails trying to read the channel number from the socket. I tried both using the standard code from the controller_hci_uart sample with the few extra lines for the pin remap as well as a slightly modified version of the old code that worked with 4.0.
Are there any known issues wth ESP-IDF 4.1 for HCI that might be throwing a wrench in things? For reference, here's the code I was running with 4.0:
Code: Select all
/*
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include "nvs_flash.h"
#include "driver/uart.h"
#include "esp_log.h"
#include "esp_bt.h"
static const char *tag = "CONTROLLER_UART_HCI";
static void uart_gpio_reset(void)
{
#if CONFIG_BT_HCI_UART_NO == 1
periph_module_enable(PERIPH_UART1_MODULE);
#elif CONFIG_BT_HCI_UART_NO == 2
periph_module_enable(PERIPH_UART2_MODULE);
#endif
periph_module_enable(PERIPH_UHCI0_MODULE);
#ifdef CONFIG_BT_HCI_UART_NO
ESP_LOGI(tag, "HCI UART%d Pin select: TX 5, RX 0, RTS 12, CTS 32", CONFIG_BT_HCI_UART_NO);
uart_set_pin(UART_NUM_0, 5, 0, 12, 32); // Remap UART0 to different pins
uart_set_pin(CONFIG_BT_HCI_UART_NO, 1, 3, 22, 19); // Remap HCI uart to uart0 pins
uart_set_baudrate(CONFIG_BT_HCI_UART_NO, 921600);
// 1 is TXD0
// 3 is RXD0
// 22 is RTS0
// 19 is CTS0
#endif
}
void app_main()
{
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 );
/* As the UART1/2 pin conflict with flash pin, so do matrix of the signal and pin */
uart_gpio_reset(); //
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
bt_cfg.auto_latency = true;
ret = esp_bt_controller_init(&bt_cfg);
if (ret != ESP_OK) {
ESP_LOGE(tag, "Bluetooth Controller initialize failed: %s", esp_err_to_name(ret));
return;
}
ret = esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT);
if (ret != ESP_OK) {
ESP_LOGE(tag, "Bluetooth Controller initialize failed: %s", esp_err_to_name(ret));
return;
}
ret = esp_bt_sleep_disable();
if (ret != ESP_OK) {
ESP_LOGE(tag, "Bluetooth Sleep Disable Failed: %s", esp_err_to_name(ret));
return;
}
}