|
| 1 | +One Board SPI Communication Test |
| 2 | +============= |
| 3 | + |
| 4 | +### tests-mbed_hal-spi_com |
| 5 | + |
| 6 | +Overview |
| 7 | +---------------- |
| 8 | +This is the SPI communication test which verifies various SPI configuration variants. The test is based on Green Tea framework. The test transfers data between SPI master and SPI slave on the same device. |
| 9 | + |
| 10 | +Test Setup |
| 11 | +---------------- |
| 12 | +1. **Pre-requirements** |
| 13 | + - One Mbed board with SPI support |
| 14 | + - Board must have two SPI peripherals available |
| 15 | + - Board must support SPI slave mode |
| 16 | + - Wire connection between SPI interfaces |
| 17 | + |
| 18 | +  |
| 19 | + |
| 20 | +2. **Running the test** |
| 21 | + - Test assumes that SPI pins are defined in target's `PinNames.h` file: |
| 22 | + - `SPI0_MOSI`, `SPI0_MISO`, `SPI0_SCK`, `SPI0_CS` |
| 23 | + - `SPI1_MOSI`, `SPI1_MISO`, `SPI1_SCK`, `SPI1_CS` |
| 24 | + - Wire the 4 pins for each peripheral. |
| 25 | + - Set `MANUAL_TEST` macro in the test to `1`. |
| 26 | + - Run the test using the following command: |
| 27 | + `mbed test -t TOOLCHAIN -m BOARD -n tests-mbed_hal-spi_com` |
| 28 | + |
| 29 | +Test scenario |
| 30 | +---------------- |
| 31 | +Typical SPI transmission schema during the test is shown below: |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +Five predefined(different) symbols are sent in both directions using different SPI configurations. |
| 36 | + |
| 37 | +- Test for synchronous API |
| 38 | + - CS is asserted high (inactive state). |
| 39 | + - Configuration is validated against device capabilities. |
| 40 | + - If master or slave cannot handle this configuration the test case is skipped. |
| 41 | + - Format configuration is set for both master and slave. |
| 42 | + - Frequency configuration is set on the master peripheral. |
| 43 | + - Reception buffers and semaphores are reinitialized. |
| 44 | + - A thread is started for the slave side. |
| 45 | + - A thread is started for the master side. |
| 46 | + - The master thread asserts CS to 0 (active state), performs the transfer and asserts CS back to 1. |
| 47 | + - The test thread (main) waits until either the semaphore is given twice or we it reaches a timeout. |
| 48 | + - Master & slave rx buffers are respectively compared to slave & master tx buffers. |
| 49 | + - If a buffer do not match, then the test fails. |
| 50 | + - Both SPI peripheral are freed and the next test starts. |
| 51 | + |
| 52 | +**Note:** |
| 53 | +On master side data is transferred symbol by symbol (i.e. when 5 symbols is to be transferred, then transfer routine is called 5 times in loop). This is the limitation of the one board SPI communication test. |
| 54 | + |
| 55 | +- Test for asynchronous API |
| 56 | + - CS is asserted high (inactive state). |
| 57 | + - Configuration is validated against device capabilities |
| 58 | + - If master or slave cannot handle this configuration the test case is skipped. |
| 59 | + - Format configuration is set for both master and slave. |
| 60 | + - Frequency configuration is set on the master peripheral. |
| 61 | + - Reception buffers and semaphores are reinitialized. |
| 62 | + - The spi_transfer_async() function is called for the slave peripheral. |
| 63 | + - The CS is asserted to 0 (active state). |
| 64 | + - spi_trasnfer_async() is called for the master peripheral. |
| 65 | + - The CS is asserted back to 1 (inactive state). |
| 66 | + - Master & slave rx buffers are respectively compared to slave & master tx buffers. |
| 67 | + - If a buffer do not match, then the test fails. |
| 68 | + - Both SPI peripheral are freed and the next test starts. |
| 69 | + |
| 70 | +What is verified by the test? |
| 71 | +---------------- |
| 72 | +| | Test case | Testing | Description | |
| 73 | +|-----|----------------------------------------------------------------|---------------------------|----------------------------------------------------------| |
| 74 | +| 1 | **SPI master-slave sync com - default config** | Sync/General | Verifies most commonly used SPI configuration* | |
| 75 | +| 2 | SPI master-slave sync com - symbol size: 1 | Sync/Symbol sizes | Symbol size is equal to 1 | |
| 76 | +| 3 | SPI master-slave sync com - symbol size: 7 | Sync/Symbol sizes | Symbol size is equal to 7 | |
| 77 | +| 4 | SPI master-slave sync com - symbol size: 9 | Sync/Symbol sizes | Symbol size is equal to 9 | |
| 78 | +| 5 | SPI master-slave sync com - symbol size: 15 | Sync/Symbol sizes | Symbol size is equal to 15 | |
| 79 | +| 6 | SPI master-slave sync com - symbol size: 16 | Sync/Symbol sizes | Symbol size is equal to 16 | |
| 80 | +| 7 | SPI master-slave sync com - symbol size: 17 | Sync/Symbol sizes | Symbol size is equal to 17 | |
| 81 | +| 8 | SPI master-slave sync com - symbol size: 31 | Sync/Symbol sizes | Symbol size is equal to 31 | |
| 82 | +| 9 | SPI master-slave sync com - symbol size: 32 | Sync/Symbol sizes | Symbol size is equal to 32 | |
| 83 | +| 10 | SPI master-slave sync com - mode: idle low, sample second edge | Sync/Clock polarity/phase | Clock idle high/sampling on the first edge | |
| 84 | +| 11 | SPI master-slave sync com - mode: idle high, sample first edge | Sync/Clock polarity/phase | Clock idle high/sampling on the second edge | |
| 85 | +| 12 | SPI master-slave sync com - mode: idle high, sample second edge| Sync/Clock polarity/phase | Clock idle low/sampling on the first edge | |
| 86 | +| 13 | SPI master-slave sync com - bit ordering: LSB first | Sync/Bit order | LSB transmitted first | |
| 87 | +| 14 | SPI master-slave sync com - master: manual ss | Sync/SS handling | Internal SS handling by master | |
| 88 | +| 15 | SPI master-slave sync com - freq testing: 200 KHz | Sync/Frequency | Minimum required frequency (200 kHz) | |
| 89 | +| 16 | SPI master-slave sync com - freq testing: 2 MHz | Sync/Frequency | Maximum required frequency (2 MHz) | |
| 90 | +| 17 | SPI master-slave sync com - freq testing: min defined | Sync/Frequency | Minimum frequency specified in capabilities | |
| 91 | +| 18 | SPI master-slave sync com - freq testing: max defined | Sync/Frequency | Maximum frequency specified in capabilities | |
| 92 | +| 19 | SPI master-slave sync com - master: TX undefined | Sync/Buffers | Master TX buffer is undefined (NULL) | |
| 93 | +| 20 | SPI master-slave sync com - master: RX undefined | Sync/Buffers | Master RX buffer is undefined (NULL) | |
| 94 | +| 21 | SPI master-slave sync com - slave: TX undefined | Sync/Buffers | Slave TX buffer is undefined (NULL) | |
| 95 | +| 22 | SPI master-slave sync com - slave: RX undefined | Sync/Buffers | Slave RX buffer is undefined (NULL) | |
| 96 | +| 23 | SPI master-slave sync com - master: TX > RX | Sync/Buffers | Master TX buffer size is greater than RX buffer size | |
| 97 | +| 24 | SPI master-slave sync com - master: TX < RX | Sync/Buffers | Master TX buffer size is less than RX buffer size | |
| 98 | +| 25 | SPI master-slave sync com - slave: TX > RX | Sync/Buffers | SLAVE TX buffer size is greater than RX buffer size | |
| 99 | +| 26 | SPI master-slave sync com - slave: TX < RX | Sync/Buffers | SLAVE TX buffer size is less than RX buffer size | |
| 100 | +| 27 | SPI master-slave sync com - one symbol | Sync/Buffers | 1 symbol is transmitted | |
| 101 | +| 28 | SPI master-slave sync com - long buffer | Sync/Buffers | 64 symbols are transmitted | |
| 102 | +| 29 | SPI master-slave async com - default config | Aync/General | Verifies most commonly used SPI configuration | |
| 103 | +| 30 | SPI master-slave sync com - symbol size: 1 | Aync/Symbol sizes | Symbol size is equal to 1 | |
| 104 | +| 31 | SPI master-slave sync com - symbol size: 7 | Aync/Symbol sizes | Symbol size is equal to 7 | |
| 105 | +| 32 | SPI master-slave sync com - symbol size: 9 | Aync/Symbol sizes | Symbol size is equal to 9 | |
| 106 | +| 33 | SPI master-slave sync com - symbol size: 15 | Aync/Symbol sizes | Symbol size is equal to 15 | |
| 107 | +| 34 | SPI master-slave sync com - symbol size: 16 | Aync/Symbol sizes | Symbol size is equal to 16 | |
| 108 | +| 35 | SPI master-slave sync com - symbol size: 17 | Aync/Symbol sizes | Symbol size is equal to 17 | |
| 109 | +| 36 | SPI master-slave sync com - symbol size: 31 | Aync/Symbol sizes | Symbol size is equal to 31 | |
| 110 | +| 37 | SPI master-slave sync com - symbol size: 32 | Aync/Symbol sizes | Symbol size is equal to 32 | |
| 111 | +| 38 | SPI master-slave sync com - mode: idle low, sample second edge | Aync/Clock polarity/phase | Clock idle high/sampling on the first edge | |
| 112 | +| 39 | SPI master-slave sync com - mode: idle high, sample first edge | Aync/Clock polarity/phase | Clock idle high/sampling on the second edge | |
| 113 | +| 40 | SPI master-slave sync com - mode: idle high, sample second edge| Aync/Clock polarity/phase | Clock idle low/sampling on the first edge | |
| 114 | +| 41 | SPI master-slave sync com - bit ordering: LSB first | Aync/Bit order | LSB transmitted first | |
| 115 | +| 42 | SPI master-slave sync com - freq testing: 200 KHz | Aync/Frequency | Minimum required frequency (200 kHz) | |
| 116 | +| 43 | SPI master-slave sync com - freq testing: 2 MHz | Aync/Frequency | Maximum required frequency (2 MHz) | |
| 117 | +| 44 | SPI master-slave sync com - master: manual ss | Aync/SS handling | Internal SS handling by master | |
| 118 | +| 45 | SPI master-slave sync com - one symbol | Aync/Buffers | 1 symbol is transmitted | |
| 119 | +| 46 | SPI master-slave sync com - long buffer | Aync/Buffers | 32 symbols are transmitted | |
| 120 | + |
| 121 | +Synchronous and asynchronous modes are tested separately. |
| 122 | + |
| 123 | + `*` - `default config` test case verifies the most typical SPI configuration which is: |
| 124 | +- Symbol size: 8 bits |
| 125 | +- Clock polarity/phase: Clock idle low/sampling on the first edge |
| 126 | +- Bit order: MSB first |
| 127 | +- SS handling: external (manual) |
| 128 | +- Duplex: Full duplex |
| 129 | +- Frequency: 1 MHz |
| 130 | +- Synchronous mode (blocking) |
| 131 | +- RX, TX buffers defined |
| 132 | +- RX buffer length is equal to TX buffer length (5 symbols are transmitted in both directions) |
| 133 | + |
| 134 | +Other test cases differs from the `default config` always only by one setting (e.g. `symbol size: 16` test case has the same scenario, but 16 bit symbols are transmitted). |
| 135 | + |
| 136 | +Test Limitations |
| 137 | +---------------- |
| 138 | + |
| 139 | +Synchronous mode: |
| 140 | + |
| 141 | +- Test uses two threads in to handle master-slave data transfer, because of that master is sending symbols one by one (when five symbols are to be sent, then spi_transfer() function is called five times and in each call one symbol is transferred). This will allow slave thread to read transmitted symbols. |
| 142 | +- Half-Duplex mode cannot be tested. |
| 143 | + |
| 144 | +Asynchronous mode: |
| 145 | + |
| 146 | +**Note:** |
| 147 | +In async mode cases when rx buffer size is different than tx buffer size and half-duplex mode are not supported. |
| 148 | + |
| 149 | +- Undefined RX/TX buffers(NULL) cannot be tested. |
| 150 | +- High frequencies cannot be tested. |
| 151 | + |
| 152 | + |
| 153 | +It is recommended to use Ice Tea version of the SPI communication test which do not have such limitations and is more reliable. |
| 154 | + |
| 155 | +Expected result |
| 156 | +---------------- |
| 157 | +The test exits without errors. |
0 commit comments