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>
This commit is contained in:
parent
4afe063aad
commit
8227c72c47
2 changed files with 12 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue