12 #include "sw/device/lib/testing/pinmux_testutils.h"
13 #include "sw/device/lib/testing/rand_testutils.h"
14 #include "sw/device/lib/testing/spi_host_testutils.h"
15 #include "sw/device/lib/testing/test_framework/check.h"
17 #include "sw/device/lib/testing/test_framework/status.h"
21 OTTF_DEFINE_TEST_CONFIG();
30 static volatile const uint8_t kSPIHostIdx = 0x0;
32 #define DATA_SET_SIZE 16
34 static dif_spi_host_t spi_host;
35 static dif_pinmux_t pinmux;
39 kTopEarlgreyMuxedPadsIob0,
40 kTopEarlgreyMuxedPadsIob1,
41 kTopEarlgreyMuxedPadsIob6,
42 kTopEarlgreyMuxedPadsIob5,
43 kTopEarlgreyMuxedPadsIob4,
44 kTopEarlgreyMuxedPadsIob3,
123 void init_spi_host(dif_spi_host_t *spi_host,
124 uint32_t peripheral_clock_freq_hz) {
126 .
spi_clock = peripheral_clock_freq_hz / 2,
127 .peripheral_clock_freq_hz = peripheral_clock_freq_hz,
128 .chip_select = {.idle = 2, .trail = 2, .lead = 2},
142 void setup_pinmux_pads_spi_host1(
void) {
149 .flags = kDifPinmuxPadAttrPullResistorEnable |
150 kDifPinmuxPadAttrPullResistorUp};
152 for (uint32_t i = 0; i <
ARRAYSIZE(spi_host1_muxed_pads); ++i) {
161 "Specified slew rate not supported, trying supported slew rate");
166 "Specified drive strength not supported, trying supported drive "
179 for (
int i = 0; i <
ARRAYSIZE(pinmux_in_config); ++i) {
185 for (
int i = 0; i <
ARRAYSIZE(pinmux_out_config); ++i) {
194 CHECK_DIF_OK(dif_pinmux_init(
196 pinmux_testutils_init(&pinmux);
201 spi_host_testutils_configure_host0_pad_attrs(&pinmux));
202 setup_pinmux_pads_spi_host1();
205 LOG_INFO(
"Testing spi_host%0d", kSPIHostIdx);
208 switch (kSPIHostIdx) {
220 LOG_FATAL(
"Invalid kSPIHostIdx: %d", kSPIHostIdx);
224 init_spi_host(&spi_host, (uint32_t)clkHz);
227 LOG_INFO(
"spi host configuration complete");
229 uint32_t expected_data[DATA_SET_SIZE];
230 uint32_t received_data[DATA_SET_SIZE];
231 for (uint32_t i = 0; i <
ARRAYSIZE(expected_data); ++i) {
232 expected_data[i] = rand_testutils_gen32();
243 .buf = &expected_data[0],
248 .txbuf = &expected_data[1],
249 .rxbuf = received_data,
250 .length = (DATA_SET_SIZE - 1) *
sizeof(uint32_t)}},
254 .buf = &received_data[DATA_SET_SIZE - 1],
262 CHECK_ARRAYS_EQ(received_data, expected_data,
ARRAYSIZE(expected_data));