Skip to content

Commit

Permalink
Fix some slave test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
multiplemonomials committed Sep 2, 2024
1 parent 0427ad3 commit 876490c
Show file tree
Hide file tree
Showing 6 changed files with 3,591 additions and 2,259 deletions.
50 changes: 49 additions & 1 deletion CI-Shield-Tests/SPISlaveCommsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void test_one_byte_transaction()
// Preload reply
spi->reply(0x2);

Timer transactionTimer;
transactionTimer.start();

uint8_t byteRxed = 0;
while(true)
{
Expand All @@ -90,6 +93,12 @@ void test_one_byte_transaction()
byteRxed = spi->read();
break;
}

if(transactionTimer.elapsed_time() > 1s)
{
TEST_FAIL_MESSAGE("No data seen by slave device!");
return;
}
}

TEST_ASSERT_EQUAL_UINT8(0x1, byteRxed);
Expand All @@ -111,6 +120,9 @@ void test_one_16bit_word_transaction()
// Preload reply
spi->reply(0x0304);

Timer transactionTimer;
transactionTimer.start();

uint16_t wordRxed = 0;
while(true)
{
Expand All @@ -119,6 +131,12 @@ void test_one_16bit_word_transaction()
wordRxed = spi->read();
break;
}

if(transactionTimer.elapsed_time() > 1s)
{
TEST_FAIL_MESSAGE("No data seen by slave device!");
return;
}
}

TEST_ASSERT_EQUAL_UINT16(0x0102, wordRxed);
Expand Down Expand Up @@ -147,13 +165,23 @@ void test_one_byte_rx_only()
greentea_send_kv("do_transaction", "0x25 expected_response 0x25");

uint8_t byteRxed = 0;

Timer transactionTimer;
transactionTimer.start();

while(true)
{
if(spi->receive())
{
byteRxed = spi->read();
break;
}

if(transactionTimer.elapsed_time() > 1s)
{
TEST_FAIL_MESSAGE("No data seen by slave device!");
return;
}
}

TEST_ASSERT_EQUAL_UINT8(0x25, byteRxed);
Expand All @@ -176,6 +204,10 @@ void test_one_byte_tx_only()
greentea_send_kv("do_transaction", "0x77 expected_response 0x88");

spi->reply(0x88);

Timer transactionTimer;
transactionTimer.start();

while(true)
{
if(spi->receive())
Expand All @@ -184,6 +216,12 @@ void test_one_byte_tx_only()
spi->read();
break;
}

if(transactionTimer.elapsed_time() > 1s)
{
TEST_FAIL_MESSAGE("No data seen by slave device!");
return;
}
}

assert_next_message_from_host("do_transaction", "complete");
Expand Down Expand Up @@ -214,10 +252,20 @@ void test_four_byte_transaction()
spi->reply(txData[txIndex++]);
}

Timer transactionTimer;
transactionTimer.start();

for(size_t dataIndex = 0; dataIndex < sizeof(txData); ++dataIndex)
{
// Wait for data
while(!spi->receive()){}
while(!spi->receive())
{
if(transactionTimer.elapsed_time() > 1s)
{
TEST_FAIL_MESSAGE("No data seen by slave device!");
return;
}
}

// Read response
rxData[rxIndex++] = spi->read();
Expand Down
6 changes: 5 additions & 1 deletion CI-Shield-Tests/ci_test_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@

// Overrides for Nucleo L452RE_P
#if TARGET_NUCLEO_L452RE_P
// PA4 (CN8 pin A2) must be jumpered to the analog in pin (A0)
// PA4 (CN6 pin 30) must be jumpered to the analog in pin (A0)
#define PIN_ANALOG_OUT PA_4

// The default Arduino D5 pin cannot use PWM due to the us ticker. To get around this we
// jumper PB0 (CN6 pin 10) to PIN_GPOUT1_PWM.
#define PIN_GPOUT_1_PWM PB_0

// STMicro accidentally used a HW CS pin from the wrong SPI for the Arduino shield pinmappings... oops!
// To get around this we jumper PB9 (CN5 pin 37) to PIN_SPI_HW_CS
#define PIN_SPI_HW_CS PB_9
#endif

// Default definitions, if not overridden above. These use the Arduino Uno form factor.
Expand Down
8 changes: 8 additions & 0 deletions CI-Shield-Tests/host_tests/i2c_slave_comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,13 @@ def setup(self):

def teardown(self):
self.recorder.teardown()

# Noticed that, if the I2C slave implementation is broken and doesn't acknowledge the
# CY7C65211, it can get "stuck" and keep the I2C bus low, preventing subsequent tests
# from working. Closing and reopening it one last time seems to reset it, preventing
# this from happening.
self._destroy_i2c_bridge()
self._initialize_i2c_bridge()

self._destroy_i2c_bridge()

2 changes: 1 addition & 1 deletion CI-Shield-Tests/mbed_app.json5
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"STM32L452xE": {
// This was added because not using it seemed to cause intermittent
// glitchy behavior with UART comms on my dev board
"target.clock_source": "USE_PLL_HSI"
"target.lse_drive_load_level": "RCC_LSEDRIVE_HIGH"
}
}
}
Loading

0 comments on commit 876490c

Please sign in to comment.