From 15d347f8c0918d9add1475beb5660fdfd7a96150 Mon Sep 17 00:00:00 2001 From: zwl Date: Tue, 28 Feb 2023 17:43:46 +0800 Subject: [PATCH 1/2] ble: Add assertion checking for bluedroid hci on ESP32-C2 and ESP32-H2 --- components/bt/controller/esp32c2/bt.c | 2 +- components/bt/controller/esp32h2/bt.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/bt/controller/esp32c2/bt.c b/components/bt/controller/esp32c2/bt.c index 19513c66a4..a7c96cf348 100644 --- a/components/bt/controller/esp32c2/bt.c +++ b/components/bt/controller/esp32c2/bt.c @@ -321,7 +321,7 @@ void esp_vhci_host_send_packet(uint8_t *data, uint16_t len) if (*(data) == DATA_TYPE_ACL) { struct os_mbuf *om = os_msys_get_pkthdr(len, ACL_DATA_MBUF_LEADINGSPCAE); assert(om); - os_mbuf_append(om, &data[1], len - 1); + assert(os_mbuf_append(om, &data[1], len - 1) == 0); ble_hci_trans_hs_acl_tx(om); } diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index 92171203e2..b429b07e67 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -325,7 +325,7 @@ void esp_vhci_host_send_packet(uint8_t *data, uint16_t len) if (*(data) == DATA_TYPE_ACL) { struct os_mbuf *om = os_msys_get_pkthdr(len, ACL_DATA_MBUF_LEADINGSPCAE); assert(om); - os_mbuf_append(om, &data[1], len - 1); + assert(os_mbuf_append(om, &data[1], len - 1) == 0); ble_hci_trans_hs_acl_tx(om); } From 5c0d18b6f5e9418ad7629e434dc34c22e3f4e5a7 Mon Sep 17 00:00:00 2001 From: zwl Date: Tue, 7 Mar 2023 18:52:30 +0800 Subject: [PATCH 2/2] Add hci uart pin reconfig API --- components/bt/porting/transport/include/hci_uart.h | 10 ++++++++++ components/bt/porting/transport/uart/hci_uart.c | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/components/bt/porting/transport/include/hci_uart.h b/components/bt/porting/transport/include/hci_uart.h index 5995397342..02bc91b403 100644 --- a/components/bt/porting/transport/include/hci_uart.h +++ b/components/bt/porting/transport/include/hci_uart.h @@ -84,6 +84,16 @@ void hci_uart_start_tx(int port_num); */ void hci_uart_start_rx(int port_num); +/** + * @brief reconfig hci uart pin + * + * @param tx_pin The Tx pin + * @param rx_pin The Rx pin + * @param cts_pin The CTS pin + * @param rts_pin The RTS pin + * @return int 0 on success, non-zero error code on failure + */ +int hci_uart_reconfig_pin(int tx_pin, int rx_pin, int cts_pin, int rts_pin); #ifdef __cplusplus } diff --git a/components/bt/porting/transport/uart/hci_uart.c b/components/bt/porting/transport/uart/hci_uart.c index 6b2da47a5e..5a418ae4fd 100644 --- a/components/bt/porting/transport/uart/hci_uart.c +++ b/components/bt/porting/transport/uart/hci_uart.c @@ -191,4 +191,17 @@ int hci_uart_close(int port_num) return 0; } +int hci_uart_reconfig_pin(int tx_pin, int rx_pin, int cts_pin, int rts_pin) +{ + int port_num = hci_uart.port; + int32_t baud_rate = hci_uart.cfg.baud_rate; + uint8_t data_bits = hci_uart.cfg.data_bits; + uint8_t stop_bits = hci_uart.cfg.stop_bits; + uart_parity_t parity = hci_uart.cfg.parity; + uart_hw_flowcontrol_t flow_ctl = hci_uart.cfg.flow_ctrl; + hci_uart_close(port_num); + hci_uart_config(port_num, baud_rate, data_bits, stop_bits, parity, flow_ctl); + ESP_ERROR_CHECK(uart_set_pin(port_num, tx_pin, rx_pin, rts_pin, cts_pin)); + return 0; +} #endif //CONFIG_BT_LE_HCI_INTERFACE_USE_UART