Skip to content

Add Master<->Slave SPI test #5200

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

Closed
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
24 changes: 9 additions & 15 deletions drivers/spi/spi_ll_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,30 @@ static void spi_stm32_shift_m(SPI_TypeDef *spi, struct spi_stm32_data *data)
/* Shift a SPI frame as slave. */
static void spi_stm32_shift_s(SPI_TypeDef *spi, struct spi_stm32_data *data)
{
u16_t tx_frame;
u16_t rx_frame;
if (LL_SPI_IsActiveFlag_TXE(spi) && spi_context_tx_on(&data->ctx)) {
u16_t tx_frame = spi_stm32_next_tx(data);

tx_frame = spi_stm32_next_tx(data);
if (LL_SPI_IsActiveFlag_TXE(spi)) {
if (SPI_WORD_SIZE_GET(data->ctx.config->operation) == 8) {
LL_SPI_TransmitData8(spi, tx_frame);
/* The update is ignored if TX is off. */
spi_context_update_tx(&data->ctx, 1, 1);
} else {
LL_SPI_TransmitData16(spi, tx_frame);
/* The update is ignored if TX is off. */
spi_context_update_tx(&data->ctx, 2, 1);
}
} else {
LL_SPI_DisableIT_TXE(spi);
}

if (LL_SPI_IsActiveFlag_RXNE(spi)) {
if (LL_SPI_IsActiveFlag_RXNE(spi) && spi_context_rx_buf_on(&data->ctx)) {
u16_t rx_frame;

if (SPI_WORD_SIZE_GET(data->ctx.config->operation) == 8) {
rx_frame = LL_SPI_ReceiveData8(spi);
if (spi_context_rx_buf_on(&data->ctx)) {
UNALIGNED_PUT(rx_frame,
(u8_t *)data->ctx.rx_buf);
}
UNALIGNED_PUT(rx_frame, (u8_t *)data->ctx.rx_buf);
spi_context_update_rx(&data->ctx, 1, 1);
} else {
rx_frame = LL_SPI_ReceiveData16(spi);
if (spi_context_rx_buf_on(&data->ctx)) {
UNALIGNED_PUT(rx_frame,
(u16_t *)data->ctx.rx_buf);
}
UNALIGNED_PUT(rx_frame, (u16_t *)data->ctx.rx_buf);
spi_context_update_rx(&data->ctx, 2, 1);
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/drivers/spi/spi_slave_master_loopback/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(KCONFIG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Kconfig)

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

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

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
43 changes: 43 additions & 0 deletions tests/drivers/spi/spi_slave_master_loopback/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
config TEST_MASTER_DRV_NAME
string "Master SPI DRV name"
default "SPI_LOOPBACK_MASTER"

config TEST_SLAVE_DRV_NAME
string "Slave SPI DRV Name"
default "SPI_LOOPBACK_SLAVE"

config TEST_SPI_SLAVE
int "SPI Slave CS index"
default 0

config TEST_MASTER_SLOW_FREQ
int "Master SPI Slow Frequency"
default 128000

config TEST_MASTER_FAST_FREQ
int "Master SPI Fast Frequency"
default 12000000

config TEST_SLAVE_FREQ
int "Slave SPI Frequency"
default 24000000

config TEST_SPI_MASTER_CS_GPIO_ENABLE
bool "Enable SPI Master CS GPIO"
default n

config TEST_MASTER_CS_GPIO_DRV_NAME
string "Master SPI GPIO DRV Name"
depends on TEST_SPI_MASTER_CS_GPIO_ENABLE
default ""

config TEST_MASTER_CS_GPIO_PIN
string "Master SPI GPIO Pin"
depends on TEST_SPI_MASTER_CS_GPIO_ENABLE
default ""

config TEST_SPI_SLAVE_CS_IGNORE
bool "Ignore CS Line for SPI Slave"
default y

source "$ZEPHYR_BASE/Kconfig.zephyr"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CONFIG_SPI_STM32=y
CONFIG_SPI_STM32_INTERRUPT=y
CONFIG_SPI_1=y
CONFIG_SPI_1_IRQ_PRI=10
CONFIG_SPI_1_NAME="SPI_LOOPBACK_MASTER"
CONFIG_SPI_2=y
CONFIG_SPI_2_IRQ_PRI=9
CONFIG_SPI_2_NAME="SPI_LOOPBACK_SLAVE"
CONFIG_TEST_MASTER_SLOW_FREQ=500000
CONFIG_TEST_SPI_MASTER_CS_GPIO_ENABLE=n
CONFIG_TEST_SPI_SLAVE_CS_IGNORE=y
7 changes: 7 additions & 0 deletions tests/drivers/spi/spi_slave_master_loopback/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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_POLL=y
Loading