Skip to content

Commit 3424e7f

Browse files
committed
[test, spi_device] Update the tpm test to verify hw registers
Signed-off-by: Douglas Reis <[email protected]> (cherry picked from commit 6e1731e)
1 parent 27d37ce commit 3424e7f

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

sw/device/tests/spi_device_tpm_tx_rx_test.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ enum {
3939
};
4040

4141
const static dif_spi_device_tpm_config_t kTpmConfig = {
42-
.interface = kDifSpiDeviceTpmInterfaceCrb,
42+
.interface = kDifSpiDeviceTpmInterfaceFifo,
4343
.disable_return_by_hardware = false,
4444
.disable_address_prefix_check = false,
4545
.disable_locality_check = false};
@@ -169,8 +169,17 @@ bool test_main(void) {
169169
// Sync message with testbench to begin.
170170
LOG_INFO("SYNC: Begin TPM Test");
171171

172+
// Enable locality 0, so that sts_reg can be read by the host.
173+
enum { kActiveLocalityBit = 5 };
174+
CHECK_DIF_OK(dif_spi_device_tpm_set_access_reg(&spi_device, 0,
175+
0x01 << kActiveLocalityBit));
176+
172177
for (uint32_t i = 0; i < kIterations; i++) {
173178
LOG_INFO("Iteration %d", i);
179+
CHECK_DIF_OK(dif_spi_device_tpm_set_sts_reg(&spi_device, i));
180+
CHECK_DIF_OK(dif_spi_device_tpm_set_int_enable_reg(&spi_device, i + 1));
181+
CHECK_DIF_OK(dif_spi_device_tpm_set_int_vector_reg(&spi_device, i + 2));
182+
CHECK_DIF_OK(dif_spi_device_tpm_set_int_status_reg(&spi_device, i + 3));
174183

175184
// Wait for write interrupt.
176185
ATOMIC_WAIT_FOR_INTERRUPT(header_interrupt_received);

sw/host/tests/chip/spi_device/src/spi_device_tpm_test.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,24 @@ fn tpm_read_test(opts: &Opts, transport: &TransportWrapper) -> Result<()> {
4242
let tpm = tpm::SpiDriver::new(spi, false)?;
4343
const SIZE: usize = 10;
4444

45-
for _ in 0..10 {
45+
for index in 0..10 {
4646
let test_data: Vec<u8> = (0..SIZE).map(|_| rand::random()).collect();
4747
tpm.write_register(tpm::Register::DATA_FIFO, &test_data)?;
4848
let _ = UartConsole::wait_for(&*uart, r"SYNC: Waiting Read", opts.timeout)?;
49+
50+
let mut hw_reg_val = [0xaau8; 4];
51+
tpm.read_register(tpm::Register::STS, &mut hw_reg_val)?;
52+
assert_eq!(hw_reg_val, [index, 0x00, 0x00, 0x00]);
53+
54+
tpm.read_register(tpm::Register::INT_ENABLE, &mut hw_reg_val)?;
55+
assert_eq!(hw_reg_val, [index + 1, 0x00, 0x00, 0x00]);
56+
57+
tpm.read_register(tpm::Register::INT_VECTOR, &mut hw_reg_val)?;
58+
assert_eq!(hw_reg_val, [index + 2, 0xff, 0xff, 0xff]);
59+
60+
tpm.read_register(tpm::Register::INT_STATUS, &mut hw_reg_val)?;
61+
assert_eq!(hw_reg_val, [index + 3, 0x00, 0x00, 0x00]);
62+
4963
let mut buffer = [0xFFu8; SIZE];
5064
tpm.read_register(tpm::Register::DATA_FIFO, &mut buffer)?;
5165
assert_eq!(buffer, &test_data[0..SIZE]);

0 commit comments

Comments
 (0)