diff --git a/Jenkinsfile b/Jenkinsfile index 4c1f6ad8..4a2e4922 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -109,7 +109,7 @@ pipeline { ["build", "scons -j4"], ["flash", "cd scripts/ && ./reflash_internal_panda.py"], ["flash jungle", "cd board/jungle && ./flash.py --all"], - ["test", "cd tests/hitl && HW_TYPES=10 pytest --durations=0 2*.py [5-9]*.py"], + ["test", "cd tests/hitl && pytest --durations=0 2*.py [5-9]*.py"], ]) } } @@ -121,7 +121,7 @@ pipeline { ["build", "scons -j4"], ["flash", "cd scripts/ && ./reflash_internal_panda.py"], ["flash jungle", "cd board/jungle && ./flash.py --all"], - ["test", "cd tests/hitl && HW_TYPES=9 pytest --durations=0 2*.py [5-9]*.py"], + ["test", "cd tests/hitl && pytest --durations=0 2*.py [5-9]*.py"], ]) } } diff --git a/python/spi.py b/python/spi.py index ecb95944..89018a6a 100644 --- a/python/spi.py +++ b/python/spi.py @@ -161,10 +161,10 @@ class PandaSpiHandle(BaseHandle): start = time.monotonic() while (timeout == 0) or ((time.monotonic() - start) < timeout_s): dat = spi.xfer2([tx, ] * length) - if dat[0] == NACK: - raise PandaSpiNackResponse - elif dat[0] == ack_val: + if dat[0] == ack_val: return bytes(dat) + elif dat[0] == NACK: + raise PandaSpiNackResponse raise PandaSpiMissingAck @@ -240,7 +240,19 @@ class PandaSpiHandle(BaseHandle): return self._transfer_raw(spi, endpoint, data, timeout, max_rx_len, expect_disconnect) except PandaSpiException as e: exc = e - logger.debug("SPI transfer failed, retrying", exc_info=True) + logger.info("SPI transfer failed, retrying", exc_info=True) + + # ensure slave is in a consistent state and ready for the next transfer + # (e.g. slave TX buffer isn't stuck full) + nack_cnt = 0 + attempts = 5 + while (nack_cnt <= 3) and (attempts > 0): + attempts -= 1 + try: + self._wait_for_ack(spi, NACK, MIN_ACK_TIMEOUT_MS, 0x11, length=XFER_SIZE//2) + nack_cnt += 1 + except PandaSpiException: + nack_cnt = 0 raise exc diff --git a/tests/hitl/5_spi.py b/tests/hitl/5_spi.py index 1861ffef..6964c9ab 100644 --- a/tests/hitl/5_spi.py +++ b/tests/hitl/5_spi.py @@ -6,9 +6,6 @@ from unittest.mock import patch from panda import Panda, PandaDFU from panda.python.spi import SpiDevice, PandaProtocolMismatch, PandaSpiNackResponse -pytestmark = [ - pytest.mark.test_panda_types((Panda.HW_TYPE_TRES, )) -] @pytest.mark.skip("doesn't work, bootloader seems to ignore commands once it sees junk") def test_dfu_with_spam(p):