UART HCI Mode with UART0

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

UART HCI Mode with UART0

Postby jsuffolk » Wed Jul 24, 2019 10:35 pm

Is it possible to use UART0 for UART HCI?

I'm trying to use a ESP32-WROOM as a bluetooth coprocessor for a raspberry pi. On the PCB there is only one UART connection between the pi host and the ESP32, on UART0, similar to the example shown here:
https://lb.raspberrypi.org/forums/viewt ... p?t=183618

The poster appears to indicate they are able to use the ESP32 as a bluetooth coprocessor. My schematic is attached, as well, it's essentially the same.

But I noticed when I bring up the menuconfig to turn on UART HCI mode, the only UARTs it will allow me to choose are UART1 or UART2. Is there any way to use the ESP32 as a bluetooth coprocessor on UART0? Maybe there's a setting in the menuconfig I need to disable the use of UART0 for something else to allow this?

If UART0 is not possible, is there any other way to use the ESP32 from the raspberry pi over UART0?
Attachments
ESP32 UART.png
ESP32 UART.png (100.93 KiB) Viewed 352 times

ESP_Sprite
Posts: 2832
Joined: Thu Nov 26, 2015 4:08 am

Re: UART HCI Mode with UART0

Postby ESP_Sprite » Thu Jul 25, 2019 3:23 am

Not sure if there are ways to get it working over UART0, but the ESP32 has a GPIO matrix that you can use to re-map IO pins. You could route UART0 to some spare pins (or disconnect it entirely), then route UART2 or 3 to the previously used pins.

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

Re: UART HCI Mode with UART0

Postby jsuffolk » Fri Jul 26, 2019 1:30 am

Great idea - I'll try this and report back if it works

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

Re: UART HCI Mode with UART0

Postby jsuffolk » Thu Aug 08, 2019 2:39 am

Tried this, still having no luck. I'm not sure whether the issue is my ESP32 logic to change the pins or the setup on my host controller. In any case I was able to successfully flash the ESP32 over UART0, I used a modified version of the controller_hci_uart example. I used the following code to attempt to remap UART1 to the UART0 pins. Seems pretty straightforward, but since it's not working I wonder if I'm missing something.

[Codebox]
/*
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 "esp_bt.h"
#include "driver/uart.h"
#include "esp_log.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, 19, 22); // 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();
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_BTDM);
if (ret != ESP_OK) {
ESP_LOGE(tag, "Bluetooth Controller initialize failed: %s", esp_err_to_name(ret));
return;
}
}
[/Codebox]

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

Re: UART HCI Mode with UART0

Postby jsuffolk » Sat Aug 10, 2019 1:59 am

Found the issue. RTS/CTS were reversed and the host controller settings weren't quite right. All is working now, thanks for your help

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot], MSN [Bot] and 20 guests