From 3704e8b8b4cb9787049e13a9dac969bef4aff0c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C3=ABl=20Boutreux?= Date: Wed, 3 Jul 2019 12:34:13 +0200 Subject: [PATCH] drivers: bluetooth: hci: spi: Handle when the buffer is empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check if the buffer size is not empty before spi transceive and buffer's data processing. This fixes the need to slow down MCUs to 16MHz when using BlueNRG-MS chips. Tested samples : Beacon, Central, Peripheral Signed-off-by: Yaƫl Boutreux Signed-off-by: Arnaud Pouliquen Signed-off-by: Alexandre Torgue --- drivers/bluetooth/hci/spi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/bluetooth/hci/spi.c b/drivers/bluetooth/hci/spi.c index ba0724c6945..e92dc890b10 100644 --- a/drivers/bluetooth/hci/spi.c +++ b/drivers/bluetooth/hci/spi.c @@ -326,9 +326,8 @@ static void bt_spi_rx_thread(void) header_slave[STATUS_HEADER_TOREAD] == 0xFF) && !ret)) && exit_irq_high_loop()); - if (!ret) { - size = header_slave[STATUS_HEADER_TOREAD]; - + size = header_slave[STATUS_HEADER_TOREAD]; + if (!ret || size != 0) { do { ret = bt_spi_transceive(&txmsg, size, &rxmsg, size); @@ -339,8 +338,10 @@ static void bt_spi_rx_thread(void) gpio_pin_enable_callback(irq_dev, GPIO_IRQ_PIN); k_sem_give(&sem_busy); - if (ret) { - BT_ERR("Error %d", ret); + if (ret || size == 0) { + if (ret) { + BT_ERR("Error %d", ret); + } continue; }