From 2283b02ce498b0285d4aa302cae568b1c534a6c5 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Fri, 20 Oct 2023 14:08:49 +1000 Subject: [PATCH] bluetooth: hci: spi: delay between header and data The HCI receive path has a delay between reading the header and payload from the controller to give the controller time to setup the SPI peripheral for the next transaction. Add the same delay on the transmit path for the same reasons. Signed-off-by: Jordan Yates --- drivers/bluetooth/hci/spi.c | 5 +++++ dts/bindings/bluetooth/zephyr,bt-hci-spi.yaml | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/bluetooth/hci/spi.c b/drivers/bluetooth/hci/spi.c index 5620c16a10e..32b50ea191f 100644 --- a/drivers/bluetooth/hci/spi.c +++ b/drivers/bluetooth/hci/spi.c @@ -425,6 +425,8 @@ static int bt_spi_send(struct net_buf *buf) (header_rx[1] | header_rx[2] | header_rx[3] | header_rx[4]) == 0U) && !ret); if (!ret) { + /* Delay here is rounded up to next tick */ + k_sleep(K_USEC(DATA_DELAY_US)); /* Transmit the message */ while (true) { ret = bt_spi_transceive(buf->data, buf->len, @@ -432,6 +434,9 @@ static int bt_spi_send(struct net_buf *buf) if (rx_first[0] != 0U || ret) { break; } + /* Consider increasing controller-data-delay-us + * if this message is extremely common. + */ LOG_DBG("Controller not ready for SPI transaction of %d bytes", buf->len); } } diff --git a/dts/bindings/bluetooth/zephyr,bt-hci-spi.yaml b/dts/bindings/bluetooth/zephyr,bt-hci-spi.yaml index 1a5afdc6473..50d0e311461 100644 --- a/dts/bindings/bluetooth/zephyr,bt-hci-spi.yaml +++ b/dts/bindings/bluetooth/zephyr,bt-hci-spi.yaml @@ -28,10 +28,10 @@ properties: type: int default: 20 description: - Duration to delay between reading a valid header and reading the data associated - with that header. This delay gives the controller time to configure the SPI data - transaction after finishing the header transaction. Without this delay the host - can attempt to read before the controller is ready, resulting in empty data that - then needs to be read a second time. The default of 20uS was chosen as the lowest - delay that reliably eliminated double transmits between a nRF9160 host and a - nRF52832 controller. + Duration to delay between reading a valid header and transceiving the data + associated with that header. This delay gives the controller time to configure + the SPI data transaction after finishing the header transaction. Without this + delay the host can attempt to read/write before the controller is ready, + resulting in an ignored transaction that then needs to be performed a second time. + The default of 20uS was chosen as the lowest delay that reliably eliminated double + transactions between a nRF9160 host and a nRF52832 controller.