|
6 | 6 | #include "../common/console.hh" |
7 | 7 | #include "../common/flash-utils.hh" |
8 | 8 | #include "../common/uart-utils.hh" |
| 9 | +#include "../common/platform-pinmux.hh" |
9 | 10 | #include "test_runner.hh" |
10 | 11 | #include <cheri.hh> |
11 | 12 | #include <ds/xoroshiro.h> |
@@ -42,14 +43,16 @@ using namespace CHERI; |
42 | 43 | /** |
43 | 44 | * Configures which of the SPI controllers shall use an external loopback |
44 | 45 | * via a jumper cable, and not just the internal loopback within the SPI |
45 | | - * block itself. (-1 = no jumper cable present) |
| 46 | + * block itself. (-1 = no jumper cable present). |
| 47 | + * |
| 48 | + * Defaults to using SPI controller 4, which requires you to have |
| 49 | + * a loopback jumper cable between the MB3 and MB4 pins of the mikroBUS |
| 50 | + * Click header. |
| 51 | + * |
| 52 | + * This can be overriden via a compilation flag. |
46 | 53 | */ |
47 | 54 | #ifndef SPI_TEST_EXT_LOOPBACK_CONN |
48 | | -// Try an external loopback test with another SPI controller; |
49 | | -// Note: we can install a loopback wire between pins MB3 and MB4 of the |
50 | | -// mikroBUS Click header in CI and test this using SPI controller 4. |
51 | | -// #define SPI_TEST_EXT_LOOPBACK_CONN (4) |
52 | | -#define SPI_TEST_EXT_LOOPBACK_CONN (-1) |
| 55 | +#define SPI_TEST_EXT_LOOPBACK_CONN (4) |
53 | 56 | #endif |
54 | 57 |
|
55 | 58 | // The expected JEDEC ID to read from the SPI Flash |
@@ -417,7 +420,10 @@ int spi_irq_test(SpiPtr spi, ds::xoroshiro::P32R8 &prng, Log &log) { |
417 | 420 | */ |
418 | 421 | int spi_loopback_test(SpiPtr spi, bool external, bool cpol, bool cpha, bool msb_first, ds::xoroshiro::P32R8 &prng, |
419 | 422 | Log &log) { |
420 | | - constexpr uint32_t kSpiSpeed = 0u; // Let's go as fast as possible. |
| 423 | + // Go as fast as possible, unless using an external loopback, as the |
| 424 | + // Verilator simulation includes a single cycle delay forbidding |
| 425 | + // this from running at full speed. |
| 426 | + const uint32_t kSpiSpeed = external ? 1u : 0u; |
421 | 427 | // Take a copy of the PRNG so that we can predict the read-side data. |
422 | 428 | ds::xoroshiro::P32R8 read_prng = prng; |
423 | 429 | size_t bytes_read = 0u; |
@@ -491,6 +497,17 @@ void spi_tests(CapRoot root, Log &log) { |
491 | 497 |
|
492 | 498 | SpiFlash spi_flash(spis[2]); |
493 | 499 |
|
| 500 | + // Create a bounded capability for pinmux & initialise the driver |
| 501 | + Capability<volatile uint8_t> pinmux = root.cast<volatile uint8_t>(); |
| 502 | + pinmux.address() = PINMUX_ADDRESS; |
| 503 | + pinmux.bounds() = PINMUX_BOUNDS; |
| 504 | + SonataPinmux Pinmux = SonataPinmux(pinmux); |
| 505 | + |
| 506 | + if (SPI_TEST_EXT_LOOPBACK_CONN == 4) { |
| 507 | + // Mux SPI2 to receive from MB3. |
| 508 | + Pinmux.block_input_select(SonataPinmux::BlockInput::spi_2_cipo, 2); |
| 509 | + } |
| 510 | + |
494 | 511 | // Initialise 8-bit PRNG for use in random test data |
495 | 512 | ds::xoroshiro::P32R8 prng; |
496 | 513 | prng.set_state(0xDEAD, 0xBEEF); |
@@ -570,4 +587,9 @@ void spi_tests(CapRoot root, Log &log) { |
570 | 587 |
|
571 | 588 | check_result(log, !test_failed); |
572 | 589 | } |
| 590 | + |
| 591 | + if (SPI_TEST_EXT_LOOPBACK_CONN == 4) { |
| 592 | + // Mux SPI2 back to its default |
| 593 | + Pinmux.block_input_select(SonataPinmux::BlockInput::spi_2_cipo, 1); |
| 594 | + } |
573 | 595 | } |
0 commit comments