Skip to content

Commit e7a010d

Browse files
MaureenHelmmbolivar-nordic
authored andcommitted
tests: drivers: spi: Add test for the SPI_DT_SPEC initializer macro
Adds a new test for the SPI_DT_SPEC initializer macro to reproduce the XCC build failure reported in #43745 on the intel_adsp_cavs15 board. Signed-off-by: Maureen Helm <[email protected]>
1 parent cd51657 commit e7a010d

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(spi_dt_spec)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2020 Nordic Semiconductor ASA
3+
* Copyright (c) 2022 Intel Corporation
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
*/
8+
9+
/ {
10+
test {
11+
#address-cells = <0x1>;
12+
#size-cells = <0x1>;
13+
14+
test_gpio: gpio@deadbeef {
15+
compatible = "vnd,gpio";
16+
gpio-controller;
17+
reg = <0xdeadbeef 0x1000>;
18+
#gpio-cells = <0x2>;
19+
label = "TEST_GPIO";
20+
status = "okay";
21+
};
22+
23+
test_spi_cs: spi@33334444 {
24+
#address-cells = <1>;
25+
#size-cells = <0>;
26+
compatible = "vnd,spi";
27+
reg = <0x33334444 0x1000>;
28+
label = "TEST_SPI_CTLR_CS";
29+
status = "okay";
30+
clock-frequency = <2000000>;
31+
32+
cs-gpios = <&test_gpio 0x10 0x20>;
33+
34+
test_spi_dev_cs: test-spi-dev@0 {
35+
compatible = "vnd,spi-device";
36+
label = "TEST_SPI_DEV_0";
37+
reg = <0>;
38+
spi-max-frequency = <2000000>;
39+
};
40+
};
41+
42+
test_spi_no_cs: spi@55556666 {
43+
#address-cells = <1>;
44+
#size-cells = <0>;
45+
compatible = "vnd,spi";
46+
reg = <0x55556666 0x1000>;
47+
label = "TEST_SPI_CTLR_NO_CS";
48+
status = "okay";
49+
clock-frequency = <2000000>;
50+
51+
test_spi_dev_no_cs: test-spi-dev@0 {
52+
compatible = "vnd,spi-device";
53+
label = "TEST_SPI_DEV_NO_CS";
54+
reg = <0>;
55+
spi-max-frequency = <2000000>;
56+
};
57+
};
58+
};
59+
};

tests/drivers/spi/dt_spec/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_SPI=y
3+
CONFIG_GPIO=y
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <ztest.h>
8+
#include <devicetree.h>
9+
#include <device.h>
10+
#include <drivers/spi.h>
11+
#include <logging/log.h>
12+
13+
LOG_MODULE_REGISTER(test, CONFIG_LOG_DEFAULT_LEVEL);
14+
15+
static void test_dt_spec(void)
16+
{
17+
const struct spi_dt_spec spi_cs =
18+
SPI_DT_SPEC_GET(DT_NODELABEL(test_spi_dev_cs), 0, 0);
19+
20+
LOG_DBG("spi_cs.bus = %p", spi_cs.bus);
21+
LOG_DBG("spi_cs.config.cs->gpio_dev = %p", spi_cs.config.cs->gpio_dev);
22+
LOG_DBG("spi_cs.config.cs->gpio.port = %p", spi_cs.config.cs->gpio.port);
23+
24+
zassert_equal(spi_cs.bus, DEVICE_DT_GET(DT_NODELABEL(test_spi_cs)), "");
25+
zassert_equal(spi_cs.config.cs->gpio_dev, DEVICE_DT_GET(DT_NODELABEL(test_gpio)), "");
26+
zassert_equal(spi_cs.config.cs->gpio.port, DEVICE_DT_GET(DT_NODELABEL(test_gpio)), "");
27+
28+
const struct spi_dt_spec spi_no_cs =
29+
SPI_DT_SPEC_GET(DT_NODELABEL(test_spi_dev_no_cs), 0, 0);
30+
31+
LOG_DBG("spi_no_cs.bus = %p", spi_no_cs.bus);
32+
LOG_DBG("spi_no_cs.config.cs = %p", spi_no_cs.config.cs);
33+
34+
zassert_equal(spi_no_cs.bus, DEVICE_DT_GET(DT_NODELABEL(test_spi_no_cs)), "");
35+
zassert_is_null(spi_no_cs.config.cs, "");
36+
}
37+
38+
void test_main(void)
39+
{
40+
ztest_test_suite(spi_dt_spec,
41+
ztest_unit_test(test_dt_spec)
42+
);
43+
ztest_run_test_suite(spi_dt_spec);
44+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
tests:
2+
drivers.spi.dt_spec:
3+
tags: drivers spi devicetree
4+
depends_on: spi gpio

0 commit comments

Comments
 (0)