| lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 1 | # Simple SPI Tests |
| 2 | |
| Scott Johnson | c668cf9 | 2019-10-30 11:49:13 -0700 | [diff] [blame] | 3 | `spitest` is a trivial Python tool for interacting with the SPI device |
| 4 | code in the `hello_world` test program running on `top_earlgrey` on the |
| 5 | FPGA board. |
| lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 6 | |
| 7 | The same FTDI interface is used for SPI as for JTAG, so this tool |
| 8 | cannot be used at the same time as an OpenOCD debugger. The |
| 9 | `top_earlgray_nexsysvideo` pin mux has been modified to use one of the |
| 10 | FTDI GPIOs to select between the two interfaces, so it is possible to |
| 11 | dynamically switch between the tools. This status bit is also |
| Scott Johnson | c668cf9 | 2019-10-30 11:49:13 -0700 | [diff] [blame] | 12 | presented as `GPIO[16]` (which was previously unused). |
| lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 13 | |
| Scott Johnson | c668cf9 | 2019-10-30 11:49:13 -0700 | [diff] [blame] | 14 | The example commands assume `$REPO_TOP` is set to the toplevel directory |
| lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 15 | of the repo. |
| 16 | |
| 17 | ### Setup |
| 18 | |
| 19 | If packages have not previously been installed you will need to set a |
| 20 | few things up. First use `apt` and `pip3` to install some required packages: |
| Scott Johnson | c668cf9 | 2019-10-30 11:49:13 -0700 | [diff] [blame] | 21 | |
| 22 | ```console |
| lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 23 | $ sudo apt-get install libusb-1.0 |
| 24 | $ pip3 install --user pyftdi |
| 25 | ``` |
| 26 | |
| 27 | You also need the `udev` rules to be set correctly by following the |
| 28 | instructions for setting up the Xilinx tools. |
| 29 | |
| 30 | ### SPI/JTAG selection GPIO |
| 31 | |
| 32 | The tool can be used to test the SPI/JTAG selection gpio. This is done |
| 33 | by providing the `--flippy` or `-f` argument which causes the |
| 34 | selection to be flipped 10 times with 2 second pauses between. The |
| 35 | `hello_world` program will see the bit flip and print a message. |
| 36 | |
| 37 | |
| Scott Johnson | c668cf9 | 2019-10-30 11:49:13 -0700 | [diff] [blame] | 38 | ```console |
| lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 39 | $ cd $REPO_TOP/util/simplespi |
| 40 | $ ./spitest.py -f |
| 41 | ``` |
| 42 | |
| 43 | |
| 44 | ### SPI Protocol Test |
| 45 | |
| 46 | The SPI protocol used in the test is a simple exchange of 4-byte |
| 47 | messages. When data is received from the SPI Device interface the |
| 48 | `hello_world` program will receive and print it out on the UART. The |
| 49 | first four bytes have their bottom bit inverted and are returned in |
| 50 | the next SPI transaction. If the sender is faster than the FPGA then |
| 51 | messages are aggregated in the receive buffer and will appear as a |
| 52 | single long message to `hello_world` which will only return a single |
| 53 | 4-byte message. |
| 54 | |
| 55 | A simple test should therefore just use 4 characters. |
| 56 | |
| 57 | |
| Scott Johnson | c668cf9 | 2019-10-30 11:49:13 -0700 | [diff] [blame] | 58 | ```console |
| lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 59 | $ cd $REPO_TOP/util/simplespi |
| 60 | $ ./spitest.py 1234 |
| 61 | $ ./spitest.py 5678 |
| 62 | ``` |
| 63 | |
| 64 | Long messages will be padded to a multiple of 4 bytes before being |
| 65 | sent, and there may be some garbage return messages. |
| 66 | |
| Scott Johnson | c668cf9 | 2019-10-30 11:49:13 -0700 | [diff] [blame] | 67 | ```console |
| lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 68 | $ cd $REPO_TOP/util/simplespi |
| 69 | $ ./spitest.py the quick brown fox jumps |
| 70 | ``` |
| 71 | |
| 72 | Messages of any length (the length given is used even if not a |
| 73 | multiple of 4) may be generated by the tool. The message is formed |
| Scott Johnson | c668cf9 | 2019-10-30 11:49:13 -0700 | [diff] [blame] | 74 | from repeating the ascii characters `0123456789abcdef` (to fill the |
| lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 75 | required length) and sent, and there may be some garbage return |
| 76 | messages. |
| 77 | |
| Scott Johnson | c668cf9 | 2019-10-30 11:49:13 -0700 | [diff] [blame] | 78 | ```console |
| lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 79 | $ cd $REPO_TOP/util/simplespi |
| 80 | $ ./spitest.py -l 120 |
| 81 | ``` |