Skip to content

Commit

Permalink
Enable SPI external loopback test between MB3 & MB4
Browse files Browse the repository at this point in the history
Enables the SPI external loopback test by adding an external jumper
cable between pins MB3 and MB4 on the mikroBUS click header. Performs
appropriate pinmuxing if the SPI test is configured to run this test, so
that the test can pass.
  • Loading branch information
AlexJones0 committed Nov 7, 2024
1 parent 62df75d commit bf73045
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions sw/cheri/tests/spi_tests.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../common/console.hh"
#include "../common/flash-utils.hh"
#include "../common/uart-utils.hh"
#include "../common/platform-pinmux.hh"
#include "test_runner.hh"
#include <cheri.hh>
#include <ds/xoroshiro.h>
Expand Down Expand Up @@ -42,14 +43,16 @@ using namespace CHERI;
/**
* Configures which of the SPI controllers shall use an external loopback
* via a jumper cable, and not just the internal loopback within the SPI
* block itself. (-1 = no jumper cable present)
* block itself. (-1 = no jumper cable present).
*
* Defaults to using SPI controller 4, which requires you to have
* a loopback jumper cable between the MB3 and MB4 pins of the mikroBUS
* Click header.
*
* This can be overriden via a compilation flag.
*/
#ifndef SPI_TEST_EXT_LOOPBACK_CONN
// Try an external loopback test with another SPI controller;
// Note: we can install a loopback wire between pins MB3 and MB4 of the
// mikroBUS Click header in CI and test this using SPI controller 4.
// #define SPI_TEST_EXT_LOOPBACK_CONN (4)
#define SPI_TEST_EXT_LOOPBACK_CONN (-1)
#define SPI_TEST_EXT_LOOPBACK_CONN (4)
#endif

// The expected JEDEC ID to read from the SPI Flash
Expand Down Expand Up @@ -491,6 +494,17 @@ void spi_tests(CapRoot root, Log &log) {

SpiFlash spi_flash(spis[2]);

// Create a bounded capability for pinmux & initialise the driver
Capability<volatile uint8_t> pinmux = root.cast<volatile uint8_t>();
pinmux.address() = PINMUX_ADDRESS;
pinmux.bounds() = PINMUX_BOUNDS;
SonataPinmux Pinmux = SonataPinmux(pinmux);

if (SPI_TEST_EXT_LOOPBACK_CONN == 4) {
// Mux SPI2 to receive from MB3.
Pinmux.block_input_select(SonataPinmux::BlockInput::spi_2_cipo, 2);
}

// Initialise 8-bit PRNG for use in random test data
ds::xoroshiro::P32R8 prng;
prng.set_state(0xDEAD, 0xBEEF);
Expand Down Expand Up @@ -570,4 +584,9 @@ void spi_tests(CapRoot root, Log &log) {

check_result(log, !test_failed);
}

if (SPI_TEST_EXT_LOOPBACK_CONN == 4) {
// Mux SPI2 back to its default
Pinmux.block_input_select(SonataPinmux::BlockInput::spi_2_cipo, 1);
}
}

0 comments on commit bf73045

Please sign in to comment.