Skip to content

Commit aec0909

Browse files
nordic-baminordic-piks
authored andcommitted
tests: drivers: spi: Add test case for MLTPAN-55 workaround
Apply MLTPAN-55 conditions and test SPI transmision. Signed-off-by: Bartosz Miller <[email protected]>
1 parent bbfd366 commit aec0909

File tree

7 files changed

+118
-11
lines changed

7 files changed

+118
-11
lines changed

tests/drivers/spi/spim_pan/boards/nrf54h20dk_nrf54h20_cpuapp.overlay

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,20 @@ dut_spi: &spi130 {
4141
dut_spi_dt: test-spi-dev@0 {
4242
compatible = "vnd,spi-device";
4343
reg = <0>;
44-
spi-max-frequency = <DT_FREQ_M(1)>;
44+
spi-max-frequency = <DT_FREQ_M(4)>;
4545
};
4646
};
4747

4848
&exmif {
4949
status = "disabled";
5050
};
51+
52+
tst_timer: &timer131 {
53+
status = "okay";
54+
};
55+
56+
&dppic133 {
57+
owned-channels = <1>;
58+
sink-channels = <1>;
59+
status = "okay";
60+
};

tests/drivers/spi/spim_pan/boards/nrf54l15dk_nrf54l15_cpuapp.overlay

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ dut_spi: &spi21 {
4040
dut_spi_dt: test-spi-dev@0 {
4141
compatible = "vnd,spi-device";
4242
reg = <0>;
43-
spi-max-frequency = <DT_FREQ_M(1)>;
43+
spi-max-frequency = <DT_FREQ_M(4)>;
4444
};
4545
};
4646

4747
&gpio1 {
4848
status = "okay";
4949
};
50+
51+
tst_timer: &timer20 {
52+
status = "okay";
53+
};
54+
55+
&dppic20 {
56+
status = "okay";
57+
};

tests/drivers/spi/spim_pan/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ dut_spi: &spi21 {
4040
dut_spi_dt: test-spi-dev@0 {
4141
compatible = "vnd,spi-device";
4242
reg = <0>;
43-
spi-max-frequency = <DT_FREQ_M(1)>;
43+
spi-max-frequency = <DT_FREQ_M(4)>;
4444
};
4545
};
4646

4747
&gpio1 {
4848
status = "okay";
4949
};
50+
51+
tst_timer: &timer20 {
52+
status = "okay";
53+
};
54+
55+
&dppic20 {
56+
status = "okay";
57+
};

tests/drivers/spi/spim_pan/boards/nrf54ls05dk_nrf54ls05b_cpuapp.overlay

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ dut_spi: &spi21 {
4040
dut_spi_dt: test-spi-dev@0 {
4141
compatible = "vnd,spi-device";
4242
reg = <0>;
43-
spi-max-frequency = <DT_FREQ_M(1)>;
43+
spi-max-frequency = <DT_FREQ_M(4)>;
4444
};
4545
};
4646

4747
&gpio1 {
4848
status = "okay";
4949
};
50+
51+
tst_timer: &timer20 {
52+
status = "okay";
53+
};
54+
55+
&dppic20 {
56+
status = "okay";
57+
};

tests/drivers/spi/spim_pan/boards/nrf54lv10dk_nrf54lv10a_cpuapp.overlay

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ dut_spi: &spi21 {
4040
dut_spi_dt: test-spi-dev@0 {
4141
compatible = "vnd,spi-device";
4242
reg = <0>;
43-
spi-max-frequency = <DT_FREQ_M(1)>;
43+
spi-max-frequency = <DT_FREQ_M(4)>;
4444
};
4545
};
4646

4747
&gpio1 {
4848
status = "okay";
4949
};
50+
51+
tst_timer: &timer20 {
52+
status = "okay";
53+
};
54+
55+
&dppic20 {
56+
status = "okay";
57+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
CONFIG_SPI=y
22

3+
CONFIG_NRFX_GPPI=y
4+
35
CONFIG_ZTEST=y

tests/drivers/spi/spim_pan/src/main.c

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@
88
#include <zephyr/ztest.h>
99
#include <zephyr/drivers/spi.h>
1010
#include <nrfx_spim.h>
11+
#include <nrfx_timer.h>
1112
#include <zephyr/linker/devicetree_regions.h>
1213

13-
#define SPI_MODE (SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_LINES_SINGLE | SPI_TRANSFER_MSB)
14+
#include <zephyr/drivers/counter.h>
15+
#include <helpers/nrfx_gppi.h>
1416

15-
#define TEST_BUFFER_SIZE 8
17+
/* SPI MODE 0 */
18+
#define SPI_MODE (SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_LINES_SINGLE | SPI_TRANSFER_MSB)
19+
#define TEST_BUFFER_SIZE 64
1620

1721
static struct spi_dt_spec spim_spec = SPI_DT_SPEC_GET(DT_NODELABEL(dut_spi_dt), SPI_MODE, 0);
1822
NRF_SPIM_Type *spim_reg = (NRF_SPIM_Type *)DT_REG_ADDR(DT_NODELABEL(dut_spi));
23+
NRF_TIMER_Type *timer_reg = (NRF_TIMER_Type *)DT_REG_ADDR(DT_NODELABEL(tst_timer));
1924

2025
#define MEMORY_SECTION(node) \
2126
COND_CODE_1(DT_NODE_HAS_PROP(node, memory_regions), \
@@ -39,15 +44,27 @@ static void set_buffers(void)
3944
memset(rx_buffer, 0xFF, TEST_BUFFER_SIZE);
4045
}
4146

47+
static uint32_t configure_test_timer(NRF_TIMER_Type *preg)
48+
{
49+
const nrfy_timer_config_t test_timer_config = {.prescaler = 1,
50+
.mode = NRF_TIMER_MODE_COUNTER,
51+
.bit_width = NRF_TIMER_BIT_WIDTH_16};
52+
53+
nrfy_timer_periph_configure(preg, &test_timer_config);
54+
nrfy_timer_task_trigger(preg, NRF_TIMER_TASK_START);
55+
56+
return nrfy_timer_task_address_get(preg, NRF_TIMER_TASK_COUNT);
57+
}
58+
4259
/*
4360
* Reference: MLTPAN-8
4461
* Requirements to trigger the PAN workaround
4562
* CPHA = 0 (configured in SPI_MODE)
46-
* PRESCALER > 2 (16 for 1MHz)
63+
* PRESCALER > 2 (4 for 4MHz)
4764
* First transmitted bit is 1 (0x8B, MSB)
4865
*/
4966

50-
ZTEST(spim_pan, test_spim_pan_workaround)
67+
ZTEST(spim_pan, test_spim_mltpan_8_workaround)
5168
{
5269
int err;
5370

@@ -59,13 +76,59 @@ ZTEST(spim_pan, test_spim_pan_workaround)
5976

6077
set_buffers();
6178

79+
err = spi_transceive_dt(&spim_spec, &tx_spi_buf_set, &rx_spi_buf_set);
6280
TC_PRINT("SPIM prescaler: %u\n", spim_reg->PRESCALER);
6381
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);
6682
zassert_ok(err, "SPI transceive failed: %d\n", err);
6783

6884
zassert_mem_equal(tx_buffer, rx_buffer, TEST_BUFFER_SIZE, "TX buffer != RX buffer\n");
6985
}
7086

87+
/*
88+
* Reference: MLTPAN-55
89+
* Requirements to trigger the PAN workaround
90+
* MODE 0 or MODE 2 (CPHA = 0)
91+
* PRESCALER = 4 (4 MHz) for SPIM2x and SPIM3x
92+
* RX.MAXCNT lower than TX.MAXCNT
93+
*/
94+
95+
ZTEST(spim_pan, test_spim_mltpan_55_workaround)
96+
{
97+
int err;
98+
uint8_t ppi_channel;
99+
uint32_t timer_cc_before, timer_cc_after;
100+
101+
uint32_t timer_task;
102+
uint32_t spim_event;
103+
104+
struct spi_buf tx_spi_buf = {.buf = tx_buffer, .len = TEST_BUFFER_SIZE};
105+
struct spi_buf_set tx_spi_buf_set = {.buffers = &tx_spi_buf, .count = 1};
106+
107+
struct spi_buf rx_spi_buf = {.buf = rx_buffer, .len = TEST_BUFFER_SIZE - 1};
108+
struct spi_buf_set rx_spi_buf_set = {.buffers = &rx_spi_buf, .count = 1};
109+
110+
set_buffers();
111+
112+
err = nrfx_gppi_channel_alloc(&ppi_channel);
113+
zassert_equal(nrfx_gppi_channel_alloc(&ppi_channel), NRFX_SUCCESS,
114+
"Failed to allocate GPPI channel");
115+
116+
timer_task = configure_test_timer(timer_reg);
117+
spim_event = nrf_spim_event_address_get(spim_reg, NRF_SPIM_EVENT_END);
118+
119+
nrfx_gppi_channel_endpoints_setup(ppi_channel, spim_event, timer_task);
120+
nrfx_gppi_channels_enable(BIT(ppi_channel));
121+
122+
timer_cc_before = nrfy_timer_capture_get(timer_reg, NRF_TIMER_CC_CHANNEL0);
123+
err = spi_transceive_dt(&spim_spec, &tx_spi_buf_set, &rx_spi_buf_set);
124+
timer_cc_after = nrfy_timer_capture_get(timer_reg, NRF_TIMER_CC_CHANNEL0);
125+
126+
TC_PRINT("Timer count before: %u, timer count after: %u\n", timer_cc_before,
127+
timer_cc_after);
128+
129+
zassert_true((timer_cc_after - timer_cc_before) > 0,
130+
"NRF_SPIM_EVENT_END did not trigger\n");
131+
zassert_mem_equal(tx_buffer, rx_buffer, TEST_BUFFER_SIZE - 1, "TX buffer != RX buffer\n");
132+
}
133+
71134
ZTEST_SUITE(spim_pan, NULL, test_setup, NULL, NULL, NULL);

0 commit comments

Comments
 (0)