diff options
author | Ricardo Salveti <ricardo.salveti@linaro.org> | 2017-01-27 18:17:01 -0200 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2017-01-28 08:43:41 +0200 |
commit | 8227c72c47bc201a70e30db40d9fc4deadbe4198 (patch) | |
tree | 5029f9d5e4c59d98bb79a6f3121ac7c6add395ee | |
parent | 4afe063aad8c8718bad77645f912a33d7ffaaf18 (diff) |
Bluetooth: SPI: fix max SPI buffer length
Drop the BLUETOOTH_SPI_RX_BUFFER_SIZE and BLUETOOTH_SPI_TX_BUFFER_SIZE
config options by fixing the max SPI buffer length to 255, as used by
the X-NUCLEO-IDB04A1 BSP. This simplifies the rx/tx buffer handling, and
avoids a potential spi rx stack overflow depending on the config values
set by the user.
Change-Id: Ifa7fd086016abda4bdcf9638f28b38d001a288c5
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
-rw-r--r-- | drivers/bluetooth/hci/Kconfig | 14 | ||||
-rw-r--r-- | drivers/bluetooth/hci/spi.c | 17 |
2 files changed, 12 insertions, 19 deletions
diff --git a/drivers/bluetooth/hci/Kconfig b/drivers/bluetooth/hci/Kconfig index 30ff83ad4..f3bbed4e5 100644 --- a/drivers/bluetooth/hci/Kconfig +++ b/drivers/bluetooth/hci/Kconfig @@ -151,20 +151,6 @@ config BLUETOOTH_SPI_RESET_PIN help This option specifies the Reset line number on the SPI device -config BLUETOOTH_SPI_RX_BUFFER_SIZE - int "Receive buffer length" - default 96 - help - This option specifies the size of the RX buffer. Try to keep this - as small as possible, since it's stored on the stack. - -config BLUETOOTH_SPI_TX_BUFFER_SIZE - int "Transmit buffer length" - default 64 - help - This option specifies the size of the TX buffer. Try to keep this - as small as possible, since it's stored on the stack. - config BLUETOOTH_SPI_MAX_CLK_FREQ int "Maximum clock frequency for the HCI SPI interface" default 5000000 diff --git a/drivers/bluetooth/hci/spi.c b/drivers/bluetooth/hci/spi.c index 44f8861d1..babbe4c84 100644 --- a/drivers/bluetooth/hci/spi.c +++ b/drivers/bluetooth/hci/spi.c @@ -48,8 +48,16 @@ #define GPIO_CS_PIN CONFIG_BLUETOOTH_SPI_CHIP_SELECT_PIN #endif /* CONFIG_BLUETOOTH_SPI_BLUENRG */ -#define MAX_RX_MSG_LEN CONFIG_BLUETOOTH_SPI_RX_BUFFER_SIZE -#define MAX_TX_MSG_LEN CONFIG_BLUETOOTH_SPI_TX_BUFFER_SIZE +/* Max SPI buffer length for transceive operations. + * + * Buffer size needs to be at least the size of the larger RX/TX buffer + * required by the SPI slave, as spi_transceive requires both RX/TX + * to be the same length. Size also needs to be compatible with the + * slave device used (e.g. nRF5X max buffer length for SPIS is 255). + */ +#define SPI_MAX_MSG_LEN 255 /* As defined by X-NUCLEO-IDB04A1 BSP */ + +static uint8_t rxmsg[SPI_MAX_MSG_LEN]; static struct device *spi_dev; #if defined(CONFIG_BLUETOOTH_SPI_BLUENRG) @@ -126,7 +134,6 @@ static void bt_spi_rx_thread(void) struct net_buf *buf; uint8_t header_master[5] = { SPI_READ, 0x00, 0x00, 0x00, 0x00 }; uint8_t header_slave[5]; - uint8_t rxmsg[MAX_RX_MSG_LEN]; uint8_t dummy = 0xFF, size, i; struct bt_hci_acl_hdr acl_hdr; @@ -195,10 +202,10 @@ static void bt_spi_rx_thread(void) static int bt_spi_send(struct net_buf *buf) { uint8_t header[5] = { SPI_WRITE, 0x00, 0x00, 0x00, 0x00 }; - uint8_t rxmsg[MAX_TX_MSG_LEN + 1]; /* Extra Byte to account for TYPE */ uint32_t pending; - if (buf->len > MAX_TX_MSG_LEN) { + /* Buffer needs an additional byte for type */ + if (buf->len >= SPI_MAX_MSG_LEN) { BT_ERR("Message too long"); return -EINVAL; } |