Skip to content

Commit

Permalink
tests: drivers: spi: Add test for SPI master and slave
Browse files Browse the repository at this point in the history
Add test which is using one SPI master and one SPI slave instance.
There is already a loopback test for SPI master so this test is
focusing on SPI slave API. Test requires 4 pairs of GPIO pins
shortened together. One set of pins is used by SPI master and
one for SPI slave.

Signed-off-by: Krzysztof Chruściński <[email protected]>
  • Loading branch information
nordic-krch authored and carlescufi committed Apr 11, 2024
1 parent 289c7e1 commit 1cd7f51
Show file tree
Hide file tree
Showing 6 changed files with 618 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/drivers/spi/spi_slave/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_slave)

FILE(GLOB app_sources src/*.c)

target_sources(app PRIVATE ${app_sources})
67 changes: 67 additions & 0 deletions tests/drivers/spi/spi_slave/boards/nrf52840dk_nrf52840.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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, 7)>;
};
};

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, 7)>;
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, 8)>,
<NRF_PSEL(SPIS_CSN, 1, 10)>;
};
};

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, 8)>,
<NRF_PSEL(SPIS_CSN, 1, 10)>;
low-power-enable;
};
};

};

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

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";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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";
};

&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 = <4000000>;
};
};

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";
/delete-property/rx-delay-supported;
/delete-property/rx-delay;
};
6 changes: 6 additions & 0 deletions tests/drivers/spi/spi_slave/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CONFIG_SPI=y
CONFIG_SPI_SLAVE=y
CONFIG_GPIO=y
CONFIG_POLL=y
CONFIG_SPI_ASYNC=y
CONFIG_ZTEST=y
Loading

0 comments on commit 1cd7f51

Please sign in to comment.