Skip to content

Commit

Permalink
[nrf fromtree] tests: drivers: spi: Add negative test cases
Browse files Browse the repository at this point in the history
Extend test coverage by adding tests that check invalid use
of the SPI API.

Signed-off-by: Sebastian Głąb <sebastian.glab@nordicsemi.no>
(cherry picked from commit 5e4bbd5)
  • Loading branch information
nordic-segl authored and gmarull committed Apr 24, 2024
1 parent 253ee08 commit 6c515dd
Show file tree
Hide file tree
Showing 6 changed files with 442 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/drivers/spi/spi_error_cases/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(spi_error_cases)

FILE(GLOB app_sources src/*.c)

target_sources(app PRIVATE ${app_sources})
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2024 Nordic Semiconductor
*
* SPDX-License-Identifier: Apache-2.0
*/

&pinctrl {
spi3_default_alt: spi3_default_alt {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 1)>,
<NRF_PSEL(SPIM_MISO, 1, 3)>,
<NRF_PSEL(SPIM_MOSI, 1, 5)>;
};
};

spi3_sleep_alt: spi3_sleep_alt {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 1)>,
<NRF_PSEL(SPIM_MISO, 1, 3)>,
<NRF_PSEL(SPIM_MOSI, 1, 5)>;
low-power-enable;
};
};

spi1_default_alt: spi1_default_alt {
group1 {
psels = <NRF_PSEL(SPIS_SCK, 1, 2)>,
<NRF_PSEL(SPIS_MISO, 1, 4)>,
<NRF_PSEL(SPIS_MOSI, 1, 6)>,
<NRF_PSEL(SPIS_CSN, 1, 8)>;
};
};

spi1_sleep_alt: spi1_sleep_alt {
group1 {
psels = <NRF_PSEL(SPIS_SCK, 1, 2)>,
<NRF_PSEL(SPIS_MISO, 1, 4)>,
<NRF_PSEL(SPIS_MOSI, 1, 6)>,
<NRF_PSEL(SPIS_CSN, 1, 8)>;
low-power-enable;
};
};

};

dut_spi: &spi3 {
status = "okay";
pinctrl-0 = <&spi3_default_alt>;
pinctrl-1 = <&spi3_sleep_alt>;
pinctrl-names = "default", "sleep";
overrun-character = <0x00>;
cs-gpios = <&gpio1 7 GPIO_ACTIVE_LOW>;
dut_spi_dt: test-spi-dev@0 {
compatible = "vnd,spi-device";
reg = <0>;
spi-max-frequency = <200000>;
};
};

dut_spis: &spi1 {
compatible = "nordic,nrf-spis";
status = "okay";
def-char = <0x00>;
pinctrl-0 = <&spi1_default_alt>;
pinctrl-1 = <&spi1_sleep_alt>;
pinctrl-names = "default", "sleep";
dut_spis_dt: test-spis-dev@0 {
compatible = "vnd,spi-device";
reg = <0>;
spi-max-frequency = <200000>;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2024 Nordic Semiconductor
*
* SPDX-License-Identifier: Apache-2.0
*/

&pinctrl {
spi22_default_alt: spi22_default_alt {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
<NRF_PSEL(SPIM_MISO, 1, 11)>,
<NRF_PSEL(SPIM_MOSI, 1, 9)>;
};
};

spi22_sleep_alt: spi22_sleep_alt {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
<NRF_PSEL(SPIM_MISO, 1, 11)>,
<NRF_PSEL(SPIM_MOSI, 1, 9)>;
low-power-enable;
};
};

spi21_default_alt: spi21_default_alt {
group1 {
psels = <NRF_PSEL(SPIS_SCK, 1, 12)>,
<NRF_PSEL(SPIS_MISO, 1, 10)>,
<NRF_PSEL(SPIS_MOSI, 1, 8)>,
<NRF_PSEL(SPIS_CSN, 1, 14)>;
};
};

spi21_sleep_alt: spi21_sleep_alt {
group1 {
psels = <NRF_PSEL(SPIS_SCK, 1, 12)>,
<NRF_PSEL(SPIS_MISO, 1, 10)>,
<NRF_PSEL(SPIS_MOSI, 1, 8)>,
<NRF_PSEL(SPIS_CSN, 1, 14)>;
low-power-enable;
};
};

};

&gpio2 {
status = "okay";
};

dut_spi: &spi22 {
status = "okay";
pinctrl-0 = <&spi22_default_alt>;
pinctrl-1 = <&spi22_sleep_alt>;
pinctrl-names = "default", "sleep";
overrun-character = <0x00>;
cs-gpios = <&gpio2 10 GPIO_ACTIVE_LOW>;
dut_spi_dt: test-spi-dev@0 {
compatible = "vnd,spi-device";
reg = <0>;
spi-max-frequency = <200000>;
};
};

dut_spis: &spi21 {
compatible = "nordic,nrf-spis";
status = "okay";
def-char = <0x00>;
pinctrl-0 = <&spi21_default_alt>;
pinctrl-1 = <&spi21_sleep_alt>;
pinctrl-names = "default", "sleep";
dut_spis_dt: test-spis-dev@0 {
compatible = "vnd,spi-device";
reg = <0>;
spi-max-frequency = <200000>;
};
/delete-property/rx-delay-supported;
/delete-property/rx-delay;
};
7 changes: 7 additions & 0 deletions tests/drivers/spi/spi_error_cases/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CONFIG_SPI=y
CONFIG_SPI_SLAVE=y
CONFIG_GPIO=y
CONFIG_POLL=y
CONFIG_SPI_ASYNC=y
CONFIG_SPI_EXTENDED_MODES=y
CONFIG_ZTEST=y
Loading

0 comments on commit 6c515dd

Please sign in to comment.