HCI not working in ESP-IDF 4.1

jsuffolk
Posts: 9
Joined: Wed Jul 24, 2019 10:25 pm

HCI not working in ESP-IDF 4.1

Postby jsuffolk » 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:

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

jsuffolk
Posts: 9
Joined: Wed Jul 24, 2019 10:25 pm

Re: HCI not working in ESP-IDF 4.1

Postby jsuffolk » Sun Oct 04, 2020 3:31 am

Turns out was my mistake - my old code was compiled with a baudrate of 115200 rather than 921600, I had tried to increase it and realized I couldn't get it to work. In any case. I did get it to work with the 921600 baud by using hciattach with noflow (no hardware flow control) instead of btattach (which only seemed to work with the 115200 baud).

Unfortunately my problem of dropping data is still an issue in ESP-IDF 4.1. Maybe the lack of flow control is the problem, going to try to see if I can get it to work with flow enabled, no luck so far.

danergo
Posts: 17
Joined: Fri Aug 06, 2021 2:50 pm

Re: HCI not working in ESP-IDF 4.1

Postby danergo » Sat Oct 16, 2021 4:19 pm

As I see not just no luck, but also no interest from espressif.

Have you ever managed to get some feedback from them?
Maybe the lost their glasses, or there is no internet for them (during the past year).

I'm in the similar situation except that at my side I have a reproducable 100% valid bug, which makes their cpu panic and reboot in every 6 hours.

Noone seems caring at all.

How is your feeling with espressif so far?

Thx,
Cheers

Who is online

Users browsing this forum: No registered users and 138 guests