Skip to content

Commit 56929a2

Browse files
lylezhu2012kartben
authored andcommitted
Driver: hci_nxp_setup: Support HCI baudrate update
Change running baudrate from `115200` from `3000000`. Implement the function `bt_h4_vnd_setup` to update the HCI bandrate. Add Kconfig `BT_H4_NXP_CTLR_WAIT_TIME_AFTER_BAUDRATE_UPDATE` to set the waiting time after the controller bandrate HCI vendor specific command sent. It is used to ensure the controller is ready to update HCI bandrate. Select `BT_HCI_SETUP` if `BT_H4_NXP_CTLR` is enabled. Signed-off-by: Lyle Zhu <[email protected]>
1 parent 298ebaf commit 56929a2

File tree

3 files changed

+80
-3
lines changed

3 files changed

+80
-3
lines changed

boards/nxp/mimxrt1170_evk/mimxrt1170_evk_mimxrt1176_cm7_B.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ m2_hci_uart: &lpuart2 {
8989
compatible = "nxp,bt-hci-uart";
9090
sdio-reset-gpios = <&gpio9 15 GPIO_ACTIVE_HIGH>;
9191
w-disable-gpios = <&gpio9 30 GPIO_ACTIVE_HIGH>;
92-
hci-operation-speed = <115200>;
92+
hci-operation-speed = <3000000>;
9393
hw-flow-control;
9494
fw-download-primary-speed = <115200>;
9595
fw-download-secondary-speed = <3000000>;

drivers/bluetooth/hci/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ config BT_H4_NXP_CTLR
304304
select GPIO
305305
depends on BT_H4
306306
select CRC
307+
select BT_HCI_SETUP
307308
default y
308309
depends on DT_HAS_NXP_BT_HCI_UART_ENABLED
309310
help
@@ -327,4 +328,11 @@ config BT_H4_NXP_CTLR_WAIT_TIME_AFTER_UPLOAD
327328
help
328329
Waiting time after firmware is uploaded. Unit is millisecond.
329330

331+
config BT_H4_NXP_CTLR_WAIT_TIME_AFTER_BAUDRATE_UPDATE
332+
int "Waiting time after controller baudrate is updated"
333+
range 500 5000
334+
default 500
335+
help
336+
Waiting time after controller baudrate is updated. Unit is millisecond.
337+
330338
endif #BT_H4_NXP_CTLR

drivers/bluetooth/hci/hci_nxp_setup.c

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <errno.h>
88
#include <stddef.h>
9+
#include <string.h>
910

1011
#include <zephyr/kernel.h>
1112
#include <zephyr/arch/cpu.h>
@@ -16,7 +17,9 @@
1617
#include <zephyr/sys/util.h>
1718
#include <zephyr/sys/byteorder.h>
1819
#include <zephyr/sys/crc.h>
19-
#include <string.h>
20+
21+
#include <zephyr/bluetooth/bluetooth.h>
22+
#include <zephyr/bluetooth/hci.h>
2023

2124
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
2225
#include <zephyr/logging/log.h>
@@ -1056,7 +1059,6 @@ static int bt_nxp_ctlr_init(void)
10561059
}
10571060

10581061
speed = DT_PROP(DT_INST_GPARENT(0), current_speed);
1059-
speed = DT_PROP_OR(DT_DRV_INST(0), hci_operation_speed, speed);
10601062
uart_dev_data.primary_speed = DT_PROP_OR(DT_DRV_INST(0), fw_download_primary_speed, speed);
10611063
uart_dev_data.secondary_speed =
10621064
DT_PROP_OR(DT_DRV_INST(0), fw_download_secondary_speed, speed);
@@ -1175,3 +1177,70 @@ int bt_hci_transport_setup(const struct device *dev)
11751177

11761178
return bt_nxp_ctlr_init();
11771179
}
1180+
1181+
#define BT_HCI_VSC_BAUDRATE_UPDATE_LENGTH 4
1182+
#define BT_HCI_VSC_BAUDRATE_UPDATE_OPCODE BT_OP(BT_OGF_VS, 0x09)
1183+
1184+
static int bt_hci_baudrate_update(const struct device *dev, uint32_t baudrate)
1185+
{
1186+
int err;
1187+
struct net_buf *buf;
1188+
1189+
buf = bt_hci_cmd_create(BT_HCI_VSC_BAUDRATE_UPDATE_OPCODE,
1190+
BT_HCI_VSC_BAUDRATE_UPDATE_LENGTH);
1191+
if (!buf) {
1192+
LOG_ERR("Fail to allocate buffer");
1193+
return -ENOBUFS;
1194+
}
1195+
1196+
/* Add new baudrate to the buffer */
1197+
net_buf_add_le32(buf, baudrate);
1198+
1199+
err = bt_hci_cmd_send_sync(BT_HCI_VSC_BAUDRATE_UPDATE_OPCODE, buf, NULL);
1200+
if (err) {
1201+
LOG_ERR("Fail to send baudrate update cmd");
1202+
return err;
1203+
}
1204+
1205+
return 0;
1206+
}
1207+
1208+
int bt_h4_vnd_setup(const struct device *dev)
1209+
{
1210+
int err;
1211+
uint32_t default_speed;
1212+
uint32_t operation_speed;
1213+
bool flowcontrol_of_hci;
1214+
1215+
if (dev != uart_dev) {
1216+
return -EINVAL;
1217+
}
1218+
1219+
if (!device_is_ready(uart_dev)) {
1220+
return -ENODEV;
1221+
}
1222+
1223+
default_speed = DT_PROP(DT_INST_GPARENT(0), current_speed);
1224+
operation_speed = DT_PROP_OR(DT_DRV_INST(0), hci_operation_speed, default_speed);
1225+
flowcontrol_of_hci = (bool)DT_PROP_OR(DT_DRV_INST(0), hw_flow_control, false);
1226+
1227+
if (operation_speed == default_speed) {
1228+
return 0;
1229+
}
1230+
1231+
err = bt_hci_baudrate_update(dev, operation_speed);
1232+
if (err) {
1233+
return err;
1234+
}
1235+
1236+
/* BT waiting time after controller bandrate updated */
1237+
(void)k_msleep(CONFIG_BT_H4_NXP_CTLR_WAIT_TIME_AFTER_BAUDRATE_UPDATE);
1238+
1239+
err = fw_upload_uart_reconfig(operation_speed, flowcontrol_of_hci);
1240+
if (err) {
1241+
LOG_ERR("Fail to update uart bandrate");
1242+
return err;
1243+
}
1244+
1245+
return 0;
1246+
}

0 commit comments

Comments
 (0)