Skip to content

Commit f2ba547

Browse files
nordic-piksnordicjm
authored andcommitted
tests: benchmarks: multicore: idle_spim: detect spi errors by asserts
To validate functional operation of driver. Signed-off-by: Piotr Kosycarz <[email protected]>
1 parent 03d813b commit f2ba547

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

tests/benchmarks/multicore/idle_spim/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ CONFIG_POWEROFF=y
1010
CONFIG_BOOT_BANNER=n
1111
CONFIG_NRFS_MRAM_SERVICE_ENABLED=n
1212

13+
CONFIG_ASSERT=y
14+
1315
# Enable for debugging purposes only
1416
CONFIG_PRINTK=n
1517
CONFIG_LOG=n

tests/benchmarks/multicore/idle_spim/src/main.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ LOG_MODULE_REGISTER(idle_spim);
1818
static struct spi_dt_spec spim_spec =
1919
SPI_DT_SPEC_GET(DT_NODELABEL(bmi270), SPI_OP_MODE_MASTER | SPI_MODE, 0);
2020

21-
int spi_read_register(uint8_t register_address, uint8_t *register_value)
21+
void spi_read_register(uint8_t register_address, uint8_t *register_value)
2222
{
23-
int err;
23+
int rc;
2424
uint8_t tx_buffer[3] = {register_address | SPI_READ_MASK, 0xFF, 0xFF};
2525
uint8_t rx_buffer[3];
2626

@@ -29,32 +29,25 @@ int spi_read_register(uint8_t register_address, uint8_t *register_value)
2929
struct spi_buf rx_spi_bufs = {.buf = rx_buffer, .len = sizeof(rx_buffer)};
3030
struct spi_buf_set rx_spi_buf_set = {.buffers = &rx_spi_bufs, .count = 1};
3131

32-
err = spi_transceive_dt(&spim_spec, &tx_spi_buf_set, &rx_spi_buf_set);
32+
rc = spi_transceive_dt(&spim_spec, &tx_spi_buf_set, &rx_spi_buf_set);
33+
__ASSERT(rc == 0, "Error: spi_transceive_dt, err: %d\n", rc);
3334
*register_value = rx_buffer[2];
3435

35-
printk("'spi_transceive_dt', err: %d, rx_data: %x %x %x\n", err, rx_buffer[0], rx_buffer[1],
36+
printk("'spi_transceive_dt', rx_data: %x %x %x\n", rx_buffer[0], rx_buffer[1],
3637
rx_buffer[2]);
37-
return err;
3838
}
3939

4040
int main(void)
4141
{
42-
int err;
42+
bool status;
4343
uint8_t response;
4444

45-
err = spi_is_ready_dt(&spim_spec);
46-
if (!err) {
47-
printk("Error: SPI device is not ready, err: %d\n", err);
48-
return -1;
49-
}
45+
status = spi_is_ready_dt(&spim_spec);
46+
__ASSERT(status, "Error: SPI device is not ready");
5047

5148
while (1) {
5249
for (int read_index = 0; read_index < SPI_READ_COUNT; read_index++) {
53-
err = spi_read_register(CHIP_ID_REGISTER_ADDRESS, &response);
54-
if (!err) {
55-
printk("SPI read returned error: %d\n", err);
56-
return -1;
57-
}
50+
spi_read_register(CHIP_ID_REGISTER_ADDRESS, &response);
5851
printk("Chip ID: 0x%x\n", response);
5952
}
6053
k_msleep(2000);

0 commit comments

Comments
 (0)