Skip to content

Making SPI Loopback Test more generic #5885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/drivers/spi/spi_loopback/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
set(KCONFIG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Kconfig)

macro(set_conf_file)
if(EXISTS ${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf)
set(CONF_FILE "${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf")
elseif(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf)
set(CONF_FILE "prj_base.conf ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf")
else()
set(CONF_FILE "prj_base.conf")
endif()
endmacro()

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

Expand Down
39 changes: 39 additions & 0 deletions tests/drivers/spi/spi_loopback/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
mainmenu "SPI Loopback Test"

config ZEPHYR_BASE
string
option env="ZEPHYR_BASE"

source "$ZEPHYR_BASE/Kconfig.zephyr"

config SPI_LOOPBACK_DRV_NAME
string "SPI device name to use for test"
default SPI_1_NAME

config SPI_LOOPBACK_CS_GPIO
bool "SPI port CS pin is controlled via a GPIO port during test"
depends on GPIO
default n

config SPI_LOOPBACK_CS_CTRL_GPIO_DRV_NAME
string
prompt "The GPIO port which is used to control CS"
depends on SPI_LOOPBACK_CS_GPIO
default "GPIO_0"

config SPI_LOOPBACK_CS_CTRL_GPIO_PIN
int "The GPIO PIN which is used to act as a CS pin"
depends on SPI_LOOPBACK_CS_GPIO
default 0

config SPI_LOOPBACK_SLAVE_NUMBER
int "Slave number from 0 to host controller slave limit"
default 0

config SPI_LOOPBACK_SLOW_FREQ
int "The frequency in Hz to use when testing in slow mode"
default 500000

config SPI_LOOPBACK_FAST_FREQ
int "The frequency in Hz to use when testing in fast mode"
default 16000000
1 change: 1 addition & 0 deletions tests/drivers/spi/spi_loopback/boards/96b_carbon.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_SPI_LOOPBACK_DRV_NAME="SPI_2"
4 changes: 4 additions & 0 deletions tests/drivers/spi/spi_loopback/boards/arduino_zero.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_SPI_LOOPBACK_DRV_NAME="SPI4"
CONFIG_SPI_LOOPBACK_CS_GPIO=y
CONFIG_SPI_LOOPBACK_CS_CTRL_GPIO_DRV_NAME="PINMUX_A"
CONFIG_SPI_LOOPBACK_CS_CTRL_GPIO_PIN=3
2 changes: 2 additions & 0 deletions tests/drivers/spi/spi_loopback/boards/em_starterkit.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_SPI_LOOPBACK_DRV_NAME="SPI_0"
CONFIG_SPI_LOOPBACK_SLOW_FREQ=128000
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CONFIG_GPIO=y
CONFIG_SPI_QMSI=n
CONFIG_SPI_DW=y
CONFIG_SPI_LOOPBACK_SLOW_FREQ=128000
CONFIG_SPI_LOOPBACK_SLAVE_NUMBER=1
11 changes: 0 additions & 11 deletions tests/drivers/spi/spi_loopback/prj_96b_carbon_polled.conf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ CONFIG_BOOT_BANNER=y
CONFIG_BUILD_TIMESTAMP=y
CONFIG_SYS_LOG=y
CONFIG_SPI=y
CONFIG_SPI_LEGACY_API=n
CONFIG_SYS_LOG_SPI_LEVEL=1
CONFIG_SPI_STM32=y
CONFIG_SPI_STM32_INTERRUPT=y
CONFIG_SPI_2=y
CONFIG_SPI_LEGACY_API=n
CONFIG_POLL=y
7 changes: 0 additions & 7 deletions tests/drivers/spi/spi_loopback/prj_em_starterkit.conf

This file was deleted.

11 changes: 0 additions & 11 deletions tests/drivers/spi/spi_loopback/prj_nucleo_f091rc.conf

This file was deleted.

9 changes: 0 additions & 9 deletions tests/drivers/spi/spi_loopback/prj_nucleo_l432kc.conf

This file was deleted.

This file was deleted.

87 changes: 10 additions & 77 deletions tests/drivers/spi/spi_loopback/src/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,82 +14,19 @@

#include <spi.h>

#define SPI_CS &spi_cs

#if defined(CONFIG_SOC_QUARK_SE_C1000)

#define SPI_DRV_NAME CONFIG_SPI_0_NAME
#define SPI_SLAVE 1
#define CS_CTRL_GPIO_DRV_NAME CONFIG_GPIO_QMSI_0_NAME
#define SPI_DRV_NAME CONFIG_SPI_LOOPBACK_DRV_NAME
#define SPI_SLAVE CONFIG_SPI_LOOPBACK_SLAVE_NUMBER
#define SLOW_FREQ CONFIG_SPI_LOOPBACK_SLOW_FREQ
#define FAST_FREQ CONFIG_SPI_LOOPBACK_FAST_FREQ

#if defined(CONFIG_SPI_LOOPBACK_CS_GPIO)
#define CS_CTRL_GPIO_DRV_NAME CONFIG_SPI_LOOPBACK_CS_CTRL_GPIO_DRV_NAME
struct spi_cs_control spi_cs = {
.gpio_pin = 25,
.delay = 0
};

#elif defined(CONFIG_SOC_QUARK_SE_C1000_SS)

#define SPI_DRV_NAME CONFIG_SPI_0_NAME
#define SPI_SLAVE 0
#define CS_CTRL_GPIO_DRV_NAME CONFIG_GPIO_DW_0_NAME

struct spi_cs_control spi_cs = {
.gpio_pin = 0,
.delay = 0
};

#elif defined(CONFIG_SOC_EM7D) || defined(CONFIG_SOC_EM9D)

#define SPI_DRV_NAME CONFIG_SPI_0_NAME
#define SPI_SLAVE 0

#undef SPI_CS
#define SPI_CS NULL
#define CS_CTRL_GPIO_DRV_NAME ""

#elif defined(CONFIG_BOARD_NUCLEO_L432KC) || \
defined(CONFIG_BOARD_DISCO_L475_IOT1) || \
defined(CONFIG_BOARD_NUCLEO_F091RC) || \
defined(CONFIG_BOARD_NUCLEO_F334R8) || \
defined(CONFIG_BOARD_NUCLEO_F401RE) || \
defined(CONFIG_BOARD_NUCLEO_L476RG)

#define SPI_DRV_NAME CONFIG_SPI_1_NAME
#define SPI_SLAVE 0
#define MIN_FREQ 500000

#undef SPI_CS
#define SPI_CS NULL
#define CS_CTRL_GPIO_DRV_NAME ""

#elif defined(CONFIG_BOARD_96B_CARBON)

#define SPI_DRV_NAME CONFIG_SPI_2_NAME
#define SPI_SLAVE 0
#define MIN_FREQ 500000

#define CS_CTRL_GPIO_DRV_NAME "GPIOC"

struct spi_cs_control spi_cs = {
.gpio_pin = 3,
.delay = 0,
};

#elif defined(CONFIG_BOARD_ARDUINO_ZERO)

#define SPI_DRV_NAME CONFIG_SPI_4_NAME
#define SPI_SLAVE 0
#define MIN_FREQ 500000

#define CS_CTRL_GPIO_DRV_NAME CONFIG_GPIO_SAM0_PORTA_LABEL

struct spi_cs_control spi_cs = {
.gpio_pin = 3,
.gpio_pin = CONFIG_SPI_LOOPBACK_CS_CTRL_GPIO_PIN,
.delay = 0,
};

#define SPI_CS (&spi_cs)
#else
#undef SPI_CS
#define SPI_CS NULL
#define CS_CTRL_GPIO_DRV_NAME ""
#endif
Expand All @@ -115,19 +52,15 @@ static void to_display_format(const u8_t *src, size_t size, char *dst)
}

struct spi_config spi_slow = {
#if defined(MIN_FREQ)
.frequency = MIN_FREQ,
#else
.frequency = 128000,
#endif
.frequency = SLOW_FREQ,
.operation = SPI_OP_MODE_MASTER | SPI_MODE_CPOL |
SPI_MODE_CPHA | SPI_WORD_SET(8) | SPI_LINES_SINGLE,
.slave = SPI_SLAVE,
.cs = SPI_CS,
};

struct spi_config spi_fast = {
.frequency = 16000000,
.frequency = FAST_FREQ,
.operation = SPI_OP_MODE_MASTER | SPI_MODE_CPOL |
SPI_MODE_CPHA | SPI_WORD_SET(8) | SPI_LINES_SINGLE,
.slave = SPI_SLAVE,
Expand Down
6 changes: 6 additions & 0 deletions tests/drivers/spi/spi_loopback/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tests:
test_spi_loopback:
depends_on: spi
tags: drivers spi
harness: loopback
platform_exclude: quark_se_c1000_ss_devboard arduino_101_sss