Skip to content

Commit 5165c66

Browse files
authored
Merge pull request #36 from Dasharo/spi
development/verilog_modules.md: add SPI module description
2 parents b4466a7 + b895ce4 commit 5165c66

13 files changed

+2679
-120
lines changed

docs/changelog/index.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,23 @@ SPDX-License-Identifier: CC-BY-SA-4.0
66

77
# Changelog
88

9+
## 2024-03-14
10+
11+
* Added testbench outputs to [Verilog modules](../development/verilog_modules/)
12+
* Added [SPI module description](../development/verilog_modules/#spi-module)
13+
- Reset signal was added to the registers module, required because SPI clock
14+
isn't free-running.
15+
* Added instructions for [connecting to mainboard through SPI](../tutorials/mainboard-connection/#protectli-vp66xx-spi)
16+
* Fixed broken links here and in [Development/Testing](../development/testing/)
17+
* Fixed command for running tests in [Development/Testing](../development/testing/)
18+
(missing asterisks)
19+
* Published
20+
[tests results as part of Task 7. Implement SPI TPM protocol](../test-results/2024_01_11_orange_crab_without_create_primary.html)
21+
* Updated [FPGA utilisation numbers](../development/verilog_modules/)
22+
923
## 2024-01-16
1024

11-
* Added page about [running tests](../development/testing.md)
25+
* Added page about [running tests](../development/testing/)
1226
* Published
1327
[tests results as part of Task 6. Base tests](../test-results/2024_01_11_orange_crab_without_create_primary.html)
1428
* Small changes to

docs/development/soc_fpga_communication.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ Reserved bits are read as 0. They may change in the future.
4747

4848
* `op_type` is a type of operation expected from MCU. 0 is used as a default
4949
value to which this register returns after `complete` signal is acknowledged
50-
by FPGA. 0xC is reserved as it may be part of 0xBADFABAC magic value. This
51-
register is only valid if `exec` is set.
50+
by FPGA, code should treat this value as error because no valid path produces
51+
it when requesting interaction from MCU. 0xC is reserved as it may be part of
52+
0xBADFABAC magic value. This register is only valid if `exec` is set.
5253

5354
| op_type | Operation |
5455
|--------:|--------------------------------------------|

docs/development/testing.md

+15-8
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,30 @@ module features. The tests used here are located in the
1414

1515
## Tests results
1616

17-
The latest results (as of 11/01/2024) can be found
17+
The latest results (as of 14/03/2024) can be found
18+
[here](/test-results/2024_03_14_orange_crab_without_create_primary.html). It was
19+
run on Protectli VP6670, TwPM was connected through SPI interface. Previous
20+
version (running on LPC) is available
1821
[here](/test-results/2024_01_11_orange_crab_without_create_primary.html).
1922

2023
## Hardware setup
2124

2225
### Hardware list
2326

24-
* [Protectli VP4670](https://docs.dasharo.com/variants/protectli_vp46xx/overview/)
25-
- The TwPM is connected to LPC TPM header on this board, so we can test the
26-
TPM features of the TwPM
2727
* [Orange Crab](https://github.com/orangecrab-fpga/orangecrab-hardware)
2828
- The TwPM is implemented on this board
29+
* One of:
30+
- [Protectli VP4670](https://docs.dasharo.com/variants/protectli_vp46xx/overview/),
31+
the TwPM is connected to LPC TPM header on this board
32+
- [Protectli VP6670](https://eu.protectli.com/product/vp6670/),
33+
the TwPM is connected to SPI TPM header on this board
2934

3035
### Connection to the platform
3136

3237
Follow the [mainboard connection tutorial](/tutorials/mainboard-connection/).
33-
Make sure that LCLK and LAD lines aren't directly next to each other (e.g.
34-
separate those with GND), otherwise inter-signal noise would cause bad reads.
38+
In case of LPC, make sure that LCLK and LAD lines aren't directly next to each
39+
other (e.g. separate those with GND), otherwise inter-signal noise would cause
40+
bad reads. No such interference was observed for SPI.
3541

3642
![](/images/twpm_connection.png)
3743

@@ -61,8 +67,9 @@ the USB-UART converter must also be connected.
6167
> [this issue](https://github.com/Dasharo/TwPM_toplevel/issues/23).
6268
> Replace `$DEVICE_IP` with the IP address of your device, where TwPM is
6369
> connected. It is assumed running Ubuntu 22.04 OS with OpenSSH server enabled
64-
> via password authentication.
70+
> via password authentication. For this test suite, both VP4670 and VP6670 may
71+
> use `protectli-vp4670` configuration.
6572
6673
```bash
67-
robot -L TRACE -v device_ip:$DEVICE_IP -v config:protectli-vp4670 -v snipeit:no -t "TPMCMD00[0-469]" -t "TPMCMD010" dasharo-security/tpm2-commands.robot
74+
robot -L TRACE -v device_ip:$DEVICE_IP -v config:protectli-vp4670 -v snipeit:no -t "TPMCMD00[0-469]*" -t "TPMCMD010*" dasharo-security/tpm2-commands.robot
6875
```

docs/development/verilog_modules.md

+207-46
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,72 @@ a guess about signal function based only on its name, which in some cases gives
1919
wrong results. Such cases are mentioned in the signal descriptions under the
2020
diagrams.
2121

22-
Current FPGA utilization:
22+
Current FPGA utilization for LPC:
2323

2424
```text
2525
Info: Device utilisation:
26-
Info: TRELLIS_IO: 65/ 197 32%
27-
Info: DCCA: 5/ 56 8%
28-
Info: DP16KD: 5/ 56 8%
29-
Info: MULT18X18D: 1/ 28 3%
30-
Info: ALU54B: 0/ 14 0%
31-
Info: EHXPLLL: 1/ 2 50%
32-
Info: EXTREFB: 0/ 1 0%
33-
Info: DCUA: 0/ 1 0%
34-
Info: PCSCLKDIV: 0/ 2 0%
35-
Info: IOLOGIC: 44/ 128 34%
36-
Info: SIOLOGIC: 0/ 69 0%
37-
Info: GSR: 0/ 1 0%
38-
Info: JTAGG: 0/ 1 0%
39-
Info: OSCG: 0/ 1 0%
40-
Info: SEDGA: 0/ 1 0%
41-
Info: DTR: 0/ 1 0%
42-
Info: USRMCLK: 1/ 1 100%
43-
Info: CLKDIVF: 1/ 4 25%
44-
Info: ECLKSYNCB: 1/ 10 10%
45-
Info: DLLDELD: 0/ 8 0%
46-
Info: DDRDLL: 1/ 4 25%
47-
Info: DQSBUFM: 2/ 8 25%
48-
Info: TRELLIS_ECLKBUF: 3/ 8 37%
49-
Info: ECLKBRIDGECS: 1/ 2 50%
50-
Info: DCSC: 0/ 2 0%
51-
Info: TRELLIS_FF: 5081/24288 20%
52-
Info: TRELLIS_COMB: 12350/24288 50%
53-
Info: TRELLIS_RAMW: 121/ 3036 3%
26+
Info: TRELLIS_IO: 65/ 197 32%
27+
Info: DCCA: 5/ 56 8%
28+
Info: DP16KD: 5/ 56 8%
29+
Info: MULT18X18D: 1/ 28 3%
30+
Info: ALU54B: 0/ 14 0%
31+
Info: EHXPLLL: 1/ 2 50%
32+
Info: EXTREFB: 0/ 1 0%
33+
Info: DCUA: 0/ 1 0%
34+
Info: PCSCLKDIV: 0/ 2 0%
35+
Info: IOLOGIC: 44/ 128 34%
36+
Info: SIOLOGIC: 0/ 69 0%
37+
Info: GSR: 0/ 1 0%
38+
Info: JTAGG: 0/ 1 0%
39+
Info: OSCG: 0/ 1 0%
40+
Info: SEDGA: 0/ 1 0%
41+
Info: DTR: 0/ 1 0%
42+
Info: USRMCLK: 1/ 1 100%
43+
Info: CLKDIVF: 1/ 4 25%
44+
Info: ECLKSYNCB: 1/ 10 10%
45+
Info: DLLDELD: 0/ 8 0%
46+
Info: DDRDLL: 1/ 4 25%
47+
Info: DQSBUFM: 2/ 8 25%
48+
Info: TRELLIS_ECLKBUF: 3/ 8 37%
49+
Info: ECLKBRIDGECS: 1/ 2 50%
50+
Info: DCSC: 0/ 2 0%
51+
Info: TRELLIS_FF: 5049/24288 20%
52+
Info: TRELLIS_COMB: 12639/24288 52%
53+
Info: TRELLIS_RAMW: 121/ 3036 3%
54+
```
55+
56+
Current FPGA utilization for SPI:
57+
58+
```text
59+
Info: Device utilisation:
60+
Info: TRELLIS_IO: 62/ 197 31%
61+
Info: DCCA: 6/ 56 10%
62+
Info: DP16KD: 5/ 56 8%
63+
Info: MULT18X18D: 0/ 28 0%
64+
Info: ALU54B: 0/ 14 0%
65+
Info: EHXPLLL: 1/ 2 50%
66+
Info: EXTREFB: 0/ 1 0%
67+
Info: DCUA: 0/ 1 0%
68+
Info: PCSCLKDIV: 0/ 2 0%
69+
Info: IOLOGIC: 44/ 128 34%
70+
Info: SIOLOGIC: 0/ 69 0%
71+
Info: GSR: 0/ 1 0%
72+
Info: JTAGG: 0/ 1 0%
73+
Info: OSCG: 0/ 1 0%
74+
Info: SEDGA: 0/ 1 0%
75+
Info: DTR: 0/ 1 0%
76+
Info: USRMCLK: 1/ 1 100%
77+
Info: CLKDIVF: 1/ 4 25%
78+
Info: ECLKSYNCB: 1/ 10 10%
79+
Info: DLLDELD: 0/ 8 0%
80+
Info: DDRDLL: 1/ 4 25%
81+
Info: DQSBUFM: 2/ 8 25%
82+
Info: TRELLIS_ECLKBUF: 3/ 8 37%
83+
Info: ECLKBRIDGECS: 1/ 2 50%
84+
Info: DCSC: 0/ 2 0%
85+
Info: TRELLIS_FF: 5025/24288 20%
86+
Info: TRELLIS_COMB: 12175/24288 50%
87+
Info: TRELLIS_RAMW: 121/ 3036 3%
5488
```
5589

5690
## Top level
@@ -82,9 +116,15 @@ External ports:
82116
marked as negated on the diagram due to how Symbolator detects such signals,
83117
i.e. its name doesn't end with either `_n` or `_b`).
84118
- `uart_rxd_i`, `uart_txd_o`: UART running at 115200n8.
85-
- LPC signals: those are to be connected to the mainboard, see
86-
[Connecting TwPM to mainboard](/tutorials/mainboard-connection/).
87-
- SPI signals: connected to onboard SPI flash. Note that there is no clock
119+
- LPC interface: those are to be connected to the mainboard, see
120+
[Connecting TwPM to mainboard](/tutorials/mainboard-connection/). Note that
121+
only one of LPC or SPI interface is present at any given time, depending on
122+
build configuration.
123+
- SPI interface: those are to be connected to the mainboard, see
124+
[Connecting TwPM to mainboard](/tutorials/mainboard-connection/). Note that
125+
only one of LPC or SPI interface is present at any given time, depending on
126+
build configuration.
127+
- SPI flash signals: connected to onboard SPI flash. Note that there is no clock
88128
signal on the diagram, a hardware macro must be used instead of defining it as
89129
a port.
90130
- DDR3 interface: signals to and from onboard DRAM, connected directly to
@@ -158,6 +198,50 @@ List of ports:
158198

159199
Source code: [Dasharo/verilog-lpc-module](https://github.com/Dasharo/verilog-lpc-module)
160200

201+
Testbench results:
202+
203+
```text
204+
VCD info: dumpfile lpc_periph_tb.vcd opened for output.
205+
Performing TPM write w/o delay
206+
Performing TPM write with delay
207+
Performing TPM read with delay
208+
Performing TPM read w/o delay
209+
Testing reset behaviour - TPM write w/o delay
210+
Testing reset behaviour - TPM read w/o delay
211+
Testing reset behaviour - TPM write with delay
212+
Testing reset behaviour - TPM read with delay
213+
Testing non-TPM transactions
214+
Testing extended LFRAME# timings - write
215+
Testing extended LFRAME# timings - read
216+
Testing abort mechanism - write
217+
Testing abort mechanism - read
218+
Testing interrupts - Continuous mode:
219+
no interrupt reported when not requested?
220+
proper IRQ reported?
221+
IRQ number latched at start frame?
222+
IRQ keeps being sent while active?
223+
IRQ stops being sent when no longer active?
224+
recovery and turn-around phases executed when int is deactivated?
225+
IRQs reported with idle clock cycles before stop frame?
226+
IRQs reported with idle clock cycles after stop frame?
227+
IRQs reported with longer start pulse width?
228+
Testing interrupts - switching between modes:
229+
peripheral doesn't initialize SERIRQ cycle in Quiet mode when not needed?
230+
peripheral initializes SERIRQ cycle when IRQ needed in Quiet mode?
231+
reset switches peripheral to Continuous mode?
232+
Testing interrupts - Quiet mode:
233+
proper IRQ reported?
234+
IRQ number latched at start frame?
235+
IRQ keeps being sent while active?
236+
IRQ stops being sent when no longer active?
237+
recovery and turn-around phases executed when int is deactivated?
238+
IRQs reported with idle clock cycles before stop frame?
239+
peripheral keeps working after spurious interrupt?
240+
IRQs reported with longer start pulse width?
241+
Testing interrupts - IRQ stops being reported on reset
242+
lpc_periph_tb.v:1344: $stop called at 518601000 (1ps)
243+
```
244+
161245
This module is responsible for managing LPC communication. It responds only to
162246
TPM cycles, other cycle types are ignored. SERIRQ (both continuous and quiet
163247
mode), cycle aborts and LPC resets are implemented.
@@ -211,36 +295,113 @@ Ports for signals to/from data provider:
211295
that, in quiet mode this signal initializes SERIRQ cycle. Data provider should
212296
drive this signal as long as reason for interrupt is valid.
213297

298+
## SPI module
299+
300+
Source code: [Dasharo/verilog-spi-module](https://github.com/Dasharo/verilog-spi-module)
301+
302+
Testbench results:
303+
304+
```text
305+
VCD info: dumpfile spi_periph_tb.vcd opened for output.
306+
Performing TPM write w/o delay
307+
Performing TPM write with delay
308+
Performing TPM read with delay
309+
Performing TPM read w/o delay
310+
Testing transfers with scattered clock between bytes
311+
Testing over-sized transfers
312+
Testing non-TPM addresses
313+
Testing crossing registers boundary
314+
spi_periph_tb.v:349: $stop called at 86540000 (1ps)
315+
```
316+
317+
This module is responsible for managing SPI communication with PC. It only
318+
supports SPI protocol as described in TPM specification.
319+
320+
![SPI peripheral module](/images/spi_periph.svg)
321+
322+
Ports for SPI interface:
323+
324+
- `clk_i`: SPI clock.
325+
- `cs_n`: Chip select (active low).
326+
- `mosi`: SPI Main Out Sub In.
327+
- `miso`: SPI Main In Sub Out, slow pull-up on host side.
328+
329+
Ports for signals to/from data provider:
330+
331+
- `addr_o`: 16-bit address of TPM register.
332+
- `data_i`, `data_o`: data received from or sent to TPM registers module.
333+
- `data_wr`: signal to data provider that `addr_o` and `data_o` have valid data
334+
and write is requested.
335+
- `wr_done`: signal from data provider that `data_o` has been read. This signal
336+
isn't used by SPI module because it would most likely arrive when the clock is
337+
no longer running. Contrary to the LPC, SPI clock runs only during the
338+
transmission.
339+
- `data_req`: signal to data provider that data is requested.
340+
- `data_rd`: signal from data provider that `data_i` has valid data for reading.
341+
This signal should be driven in response to `data_req`.
342+
343+
Note that there are no signals responsible for interrupts. SPI uses PIRQ, which
344+
doesn't require any additional logic, so `interrupt` signal from TPM registers
345+
module is used to drive it directly in the top level module.
346+
214347
## TPM registers module
215348

216349
Source code: [Dasharo/verilog-tpm-fifo-registers](https://github.com/Dasharo/verilog-tpm-fifo-registers)
217350

351+
Testbench results:
352+
353+
```text
354+
VCD info: dumpfile regs_tb.vcd opened for output.
355+
Testing simple register reads without delay
356+
Testing simple register reads with delay
357+
Checking register values against expected.txt
358+
Checking if RO registers are writable
359+
Testing mechanisms for changing locality
360+
Testing mechanisms for seizing locality
361+
Testing TPM_INT_VECTOR write without delay - proper locality
362+
Testing TPM_INT_VECTOR write with delay - proper locality
363+
Testing TPM_INT_VECTOR write without delay - wrong locality
364+
Testing TPM_INT_VECTOR write with delay - wrong locality
365+
Testing TPM_INT_VECTOR write without delay - no locality
366+
Testing TPM_INT_VECTOR write with delay - no locality
367+
Testing command/response exchange and TPM state machine - basic
368+
Testing command/response exchange and TPM state machine - advanced
369+
regs_tb.v:1075: $stop called at 2023220000 (1ps)
370+
```
371+
218372
This module implements TPM register space. It also handles locality transitions,
219373
TPM interrupt generation and command finite state machine. Register values are
220374
reported accordingly to the current state. Registers not defined by PC Client
221375
specification return 0xFF on reads, and writes are dropped.
222376

223-
The module is located between host interface module (LPC or, in the future, SPI)
224-
and memory buffer for TPM commands and responses. It also exposes hardware
225-
interface that is translated by top module into software interface for TPM stack
226-
running on NEORV32 processor.
377+
The module is located between host interface module (LPC or SPI) and memory
378+
buffer for TPM commands and responses. It also exposes hardware interface that
379+
is translated by top module into software interface for TPM stack running on
380+
NEORV32 processor.
227381

228382
![TPM registers module](/images/regs_module.svg)
229383

230-
Ports for signals to/from LPC module:
384+
Ports for signals to/from LPC or SPI module:
231385

232-
- `clk_i`: LPC clock is used for this module to allow for synchronous
233-
communication with LPC module. Because of that, all registers' values are
234-
available in one clock cycle and no wait states have to be inserted.
386+
- `clk_i`: LPC/SPI clock is used for this module to allow for synchronous
387+
communication with LPC/SPI module. Because of that, all registers' values are
388+
available in one clock cycle and no wait states (LPC) or exactly one wait
389+
state (SPI) has to be inserted. For LPC,the clock is free-running, but for SPI
390+
it is enabled only during the communication.
391+
- `reset`: reset signal, required to reset registers to their initial values,
392+
active low.
235393
- `addr_i`: 16-bit address of register to access.
236-
- `data_i`: 8-bit data from LPC module.
237-
- `data_o`: 8-bit data to LPC module.
394+
- `data_i`: 8-bit data from LPC/SPI module.
395+
- `data_o`: 8-bit data to LPC/SPI module.
238396
- `data_wr`, `wr_done`, `data_req`, `data_rd`: 4 signals coordinating
239397
communication over `data_i` and `data_o`. Their functions can be found in the
240-
[LPC module description](#lpc-module) above.
398+
[LPC module description](#lpc-module) or [SPI module description](#spi-module)
399+
above.
241400
- `irq_num`, `interrupt`: configuration and request of interrupts sent to host,
242-
see [LPC module description](#lpc-module) for details. Note that these are not
243-
interrupts sent towards NEORV32.
401+
see [LPC module description](#lpc-module) for details. In case of SPI,
402+
`interrupt` is negated and routed directly to I/O pin in top level and
403+
`irq_num` is not used. Note that these are not interrupts sent towards
404+
NEORV32.
244405

245406
Ports for signals for MCU interface:
246407

@@ -284,5 +445,5 @@ Ports:
284445

285446
- `A`: address, counted in 32-bit words.
286447
- `WD`, `RD`: input and output data, respectively.
287-
- `Clk`: input clock, arbitrated by top level between LPC and system clocks.
448+
- `Clk`: input clock, arbitrated by top level between LPC/SPI and system clocks.
288449
- `WEN`: write enable for each byte of `WD`.

docs/images/pinout-2x6-key10-vert.png

2.64 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2024 3mdeb <contact@3mdeb.com>
2+
3+
SPDX-License-Identifier: CC-BY-SA-4.0

0 commit comments

Comments
 (0)