Skip to content

Commit affc349

Browse files
nordic-baminordic-piks
authored andcommitted
tests: drivers: spim: Verify MLTPAN-8 workaround
Test the MLTPAN-8 workaround. Extend testing for other devices also. Signed-off-by: Bartosz Miller <[email protected]>
1 parent 9219727 commit affc349

File tree

6 files changed

+205
-0
lines changed

6 files changed

+205
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
11+
project(spim_pan)
12+
13+
target_sources(app PRIVATE src/main.c)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/* Required loopbacks:
8+
* P0.07 <-> P0.06
9+
*/
10+
11+
&pinctrl {
12+
dut_spi_default: dut_spi_default {
13+
group1 {
14+
psels = <NRF_PSEL(SPIM_SCK, 0, 0)>,
15+
<NRF_PSEL(SPIM_MOSI, 0, 7)>,
16+
<NRF_PSEL(SPIM_MISO, 0, 6)>;
17+
};
18+
};
19+
20+
dut_spi_sleep: dut_spi_sleep {
21+
group1 {
22+
psels = <NRF_PSEL(SPIM_SCK, 0, 0)>,
23+
<NRF_PSEL(SPIM_MISO, 0, 6)>,
24+
<NRF_PSEL(SPIM_MOSI, 0, 7)>;
25+
low-power-enable;
26+
};
27+
};
28+
};
29+
30+
dut_spi: &spi130 {
31+
compatible = "nordic,nrf-spim";
32+
status = "okay";
33+
pinctrl-0 = <&dut_spi_default>;
34+
pinctrl-1 = <&dut_spi_sleep>;
35+
pinctrl-names = "default", "sleep";
36+
overrun-character = <0x00>;
37+
memory-regions = <&cpuapp_dma_region>;
38+
cs-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
39+
zephyr,pm-device-runtime-auto;
40+
41+
dut_spi_dt: test-spi-dev@0 {
42+
compatible = "vnd,spi-device";
43+
reg = <0>;
44+
spi-max-frequency = <DT_FREQ_M(1)>;
45+
};
46+
};
47+
48+
&exmif {
49+
status = "disabled";
50+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/* Required loopbacks:
8+
* P1.10 <-> P1.11
9+
*/
10+
11+
&pinctrl {
12+
dut_spi_default: dut_spi_default {
13+
group1 {
14+
psels = <NRF_PSEL(SPIM_SCK, 1, 8)>,
15+
<NRF_PSEL(SPIM_MISO, 1, 10)>,
16+
<NRF_PSEL(SPIM_MOSI, 1, 11)>;
17+
};
18+
};
19+
20+
dut_spi_sleep: dut_spi_sleep {
21+
group1 {
22+
psels = <NRF_PSEL(SPIM_SCK, 1, 8)>,
23+
<NRF_PSEL(SPIM_MISO, 1, 10)>,
24+
<NRF_PSEL(SPIM_MOSI, 1, 11)>;
25+
low-power-enable;
26+
};
27+
};
28+
};
29+
30+
dut_spi: &spi21 {
31+
compatible = "nordic,nrf-spim";
32+
status = "okay";
33+
pinctrl-0 = <&dut_spi_default>;
34+
pinctrl-1 = <&dut_spi_sleep>;
35+
pinctrl-names = "default", "sleep";
36+
overrun-character = <0x00>;
37+
zephyr,pm-device-runtime-auto;
38+
cs-gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
39+
40+
dut_spi_dt: test-spi-dev@0 {
41+
compatible = "vnd,spi-device";
42+
reg = <0>;
43+
spi-max-frequency = <DT_FREQ_M(1)>;
44+
};
45+
};
46+
47+
&gpio1 {
48+
status = "okay";
49+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_SPI=y
2+
3+
CONFIG_ZTEST=y
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/ztest.h>
9+
#include <zephyr/drivers/spi.h>
10+
#include <nrfx_spim.h>
11+
#include <zephyr/linker/devicetree_regions.h>
12+
13+
#define SPI_MODE (SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_LINES_SINGLE | SPI_TRANSFER_MSB)
14+
15+
#define TEST_BUFFER_SIZE 8
16+
17+
static struct spi_dt_spec spim_spec = SPI_DT_SPEC_GET(DT_NODELABEL(dut_spi_dt), SPI_MODE, 0);
18+
NRF_SPIM_Type *spim_reg = (NRF_SPIM_Type *)DT_REG_ADDR(DT_NODELABEL(dut_spi));
19+
20+
#define MEMORY_SECTION(node) \
21+
COND_CODE_1(DT_NODE_HAS_PROP(node, memory_regions), \
22+
(__attribute__((__section__( \
23+
LINKER_DT_NODE_REGION_NAME(DT_PHANDLE(node, memory_regions)))))), \
24+
())
25+
26+
static uint8_t tx_buffer[TEST_BUFFER_SIZE] MEMORY_SECTION(DT_BUS(DT_NODELABEL(dut_spi_dt)));
27+
static uint8_t rx_buffer[TEST_BUFFER_SIZE] MEMORY_SECTION(DT_BUS(DT_NODELABEL(dut_spi_dt)));
28+
29+
static void *test_setup(void)
30+
{
31+
zassert_true(spi_is_ready_dt(&spim_spec), "SPIM device is not ready");
32+
33+
return NULL;
34+
}
35+
36+
static void set_buffers(void)
37+
{
38+
memset(tx_buffer, 0x8B, TEST_BUFFER_SIZE);
39+
memset(rx_buffer, 0xFF, TEST_BUFFER_SIZE);
40+
}
41+
42+
/*
43+
* Reference: MLTPAN-8
44+
* Requirements to trigger the PAN workaround
45+
* CPHA = 0 (configured in SPI_MODE)
46+
* PRESCALER > 2 (16 for 1MHz)
47+
* First transmitted bit is 1 (0x8B, MSB)
48+
*/
49+
50+
ZTEST(spim_pan, test_spim_pan_workaround)
51+
{
52+
int err;
53+
54+
struct spi_buf tx_spi_buf = {.buf = tx_buffer, .len = TEST_BUFFER_SIZE};
55+
struct spi_buf_set tx_spi_buf_set = {.buffers = &tx_spi_buf, .count = 1};
56+
57+
struct spi_buf rx_spi_buf = {.buf = rx_buffer, .len = TEST_BUFFER_SIZE};
58+
struct spi_buf_set rx_spi_buf_set = {.buffers = &rx_spi_buf, .count = 1};
59+
60+
set_buffers();
61+
62+
TC_PRINT("SPIM prescaler: %u\n", spim_reg->PRESCALER);
63+
zassert_true(spim_reg->PRESCALER > 2, "SPIM prescaler is not greater than 2\n");
64+
65+
err = spi_transceive_dt(&spim_spec, &tx_spi_buf_set, &rx_spi_buf_set);
66+
zassert_ok(err, "SPI transceive failed: %d\n", err);
67+
68+
zassert_mem_equal(tx_buffer, rx_buffer, TEST_BUFFER_SIZE, "TX buffer != RX buffer\n");
69+
}
70+
71+
ZTEST_SUITE(spim_pan, NULL, test_setup, NULL, NULL, NULL);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
common:
2+
sysbuild: true
3+
depends_on: gpio
4+
harness: ztest
5+
harness_config:
6+
fixture: gpio_loopback
7+
tags:
8+
- drivers
9+
- spim
10+
- ci_tests_drivers_spi
11+
platform_allow:
12+
- nrf54h20dk/nrf54h20/cpuapp
13+
- nrf54l15dk/nrf54l15/cpuapp
14+
integration_platforms:
15+
- nrf54h20dk/nrf54h20/cpuapp
16+
- nrf54l15dk/nrf54l15/cpuapp
17+
18+
tests:
19+
drivers.spim_pan: {}

0 commit comments

Comments
 (0)