test: drivers: spi: added a test case
Added a test case for calling spi_transceive() with a null tx buffer Signed-off-by: David D <a8961713@gmail.com>
This commit is contained in:
parent
b96525c82c
commit
22326f6d99
2 changed files with 60 additions and 0 deletions
2
tests/drivers/spi/spi_loopback/boards/nucleo_f413zh.conf
Normal file
2
tests/drivers/spi/spi_loopback/boards/nucleo_f413zh.conf
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
CONFIG_SPI_LOOPBACK_DRV_NAME="SPI_1"
|
||||||
|
CONFIG_SPI_STM32_INTERRUPT=y
|
|
@ -142,6 +142,62 @@ static int spi_complete_loop(struct device *dev, struct spi_config *spi_conf)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int spi_null_tx_buf(struct device *dev, struct spi_config *spi_conf)
|
||||||
|
{
|
||||||
|
static const u8_t EXPECTED_NOP_RETURN_BUF[BUF_SIZE] = { 0 };
|
||||||
|
(void)memset(buffer_rx, 0x77, BUF_SIZE);
|
||||||
|
|
||||||
|
const struct spi_buf tx_bufs[] = {
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* According to documentation, when sending NULL tx buf -
|
||||||
|
* NOP frames should be sent on MOSI line
|
||||||
|
*/
|
||||||
|
.buf = NULL,
|
||||||
|
.len = BUF_SIZE,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const struct spi_buf rx_bufs[] = {
|
||||||
|
{
|
||||||
|
.buf = buffer_rx,
|
||||||
|
.len = BUF_SIZE,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const struct spi_buf_set tx = {
|
||||||
|
.buffers = tx_bufs,
|
||||||
|
.count = ARRAY_SIZE(tx_bufs)
|
||||||
|
};
|
||||||
|
const struct spi_buf_set rx = {
|
||||||
|
.buffers = rx_bufs,
|
||||||
|
.count = ARRAY_SIZE(rx_bufs)
|
||||||
|
};
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
LOG_INF("Start");
|
||||||
|
|
||||||
|
ret = spi_transceive(dev, spi_conf, &tx, &rx);
|
||||||
|
if (ret) {
|
||||||
|
LOG_ERR("Code %d", ret);
|
||||||
|
zassert_false(ret, "SPI transceive failed");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (memcmp(buffer_rx, EXPECTED_NOP_RETURN_BUF, BUF_SIZE)) {
|
||||||
|
to_display_format(buffer_rx, BUF_SIZE, buffer_print_rx);
|
||||||
|
LOG_ERR("Rx Buffer should contain NOP frames but got: %s",
|
||||||
|
buffer_print_rx);
|
||||||
|
zassert_false(1, "Buffer not as expected");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INF("Passed");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int spi_rx_half_start(struct device *dev, struct spi_config *spi_conf)
|
static int spi_rx_half_start(struct device *dev, struct spi_config *spi_conf)
|
||||||
{
|
{
|
||||||
const struct spi_buf tx_bufs[] = {
|
const struct spi_buf tx_bufs[] = {
|
||||||
|
@ -462,6 +518,7 @@ void test_spi_loopback(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (spi_complete_loop(spi_slow, &spi_cfg_slow) ||
|
if (spi_complete_loop(spi_slow, &spi_cfg_slow) ||
|
||||||
|
spi_null_tx_buf(spi_slow, &spi_cfg_slow) ||
|
||||||
spi_rx_half_start(spi_slow, &spi_cfg_slow) ||
|
spi_rx_half_start(spi_slow, &spi_cfg_slow) ||
|
||||||
spi_rx_half_end(spi_slow, &spi_cfg_slow) ||
|
spi_rx_half_end(spi_slow, &spi_cfg_slow) ||
|
||||||
spi_rx_every_4(spi_slow, &spi_cfg_slow)
|
spi_rx_every_4(spi_slow, &spi_cfg_slow)
|
||||||
|
@ -473,6 +530,7 @@ void test_spi_loopback(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spi_complete_loop(spi_fast, &spi_cfg_fast) ||
|
if (spi_complete_loop(spi_fast, &spi_cfg_fast) ||
|
||||||
|
spi_null_tx_buf(spi_fast, &spi_cfg_fast) ||
|
||||||
spi_rx_half_start(spi_fast, &spi_cfg_fast) ||
|
spi_rx_half_start(spi_fast, &spi_cfg_fast) ||
|
||||||
spi_rx_half_end(spi_fast, &spi_cfg_fast) ||
|
spi_rx_half_end(spi_fast, &spi_cfg_fast) ||
|
||||||
spi_rx_every_4(spi_fast, &spi_cfg_fast)
|
spi_rx_every_4(spi_fast, &spi_cfg_fast)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue