From 83a388e6c8e23fee0e9c63b3a1dd5200e3c33202 Mon Sep 17 00:00:00 2001 From: Baohong Liu Date: Thu, 15 Dec 2016 11:44:32 -0800 Subject: [PATCH] tests: spi: correct a spi buffer length issue Make the buffer length for tx and rx are the same for spi_transceive API call. QMSI only supports equal length. This is clearly specifed in spi header file. Also correct some coding style issues. Change-Id: Ifd34683e8813dae9b692ad453176a93cb3848427 Signed-off-by: Baohong Liu --- tests/drivers/spi_test/src/spi.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/drivers/spi_test/src/spi.c b/tests/drivers/spi_test/src/spi.c index b4afe398d2c..7b8257b0808 100644 --- a/tests/drivers/spi_test/src/spi.c +++ b/tests/drivers/spi_test/src/spi.c @@ -21,8 +21,6 @@ #include #include - - #define SPI_DRV_NAME "SPI_0" #ifdef CONFIG_SPI_INTEL @@ -67,11 +65,11 @@ static void _spi_show(struct spi_config *spi_conf) void main(void) { struct device *spi; + uint32_t len = 0; printk("==== SPI Test Application ====\n"); spi = device_get_binding(SPI_DRV_NAME); - if (!spi) { printk("SPI device not found\n"); return; @@ -92,16 +90,24 @@ void main(void) _spi_show(&spi_conf); printk("Writing...\n"); + if (spi_write(spi, (uint8_t *) wbuf, 6) != 0) { printk("SPI write failed\n"); return; } printk("SPI sent: %s\n", wbuf); - print_buf_hex(rbuf, 6); + print_buf_hex(wbuf, 6); strcpy((char *)wbuf, "So what then?"); - if (spi_transceive(spi, wbuf, 14, rbuf, 16) != 0) { + + len = strlen(wbuf); + /* + * len does not include string terminator. + * Let's sent the terminator as well. + * Also make sure tx and rx have the same length. + */ + if (spi_transceive(spi, wbuf, len + 1, rbuf, len + 1) != 0) { printk("SPI transceive failed\n"); return; }