Skip to content

Commit f034faf

Browse files
adeebshihadehComma Device
andauthored
spi debug (#2292)
Co-authored-by: Comma Device <device@comma.ai>
1 parent 16f17ae commit f034faf

File tree

3 files changed

+53
-18
lines changed

3 files changed

+53
-18
lines changed

python/spi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class PandaSpiHandle(BaseHandle):
117117

118118
def __init__(self) -> None:
119119
self.dev = SpiDevice()
120+
self.no_retry = "NO_RETRY" in os.environ
120121

121122
# helpers
122123
def _calc_checksum(self, data: bytes) -> int:
@@ -193,6 +194,8 @@ def _transfer(self, endpoint: int, data, timeout: int, max_rx_len: int = 1000, e
193194
except PandaSpiException as e:
194195
exc = e
195196
logger.debug("SPI transfer failed, retrying", exc_info=True)
197+
if self.no_retry:
198+
break
196199

197200
# ensure slave is in a consistent state and ready for the next transfer
198201
# (e.g. slave TX buffer isn't stuck full)

scripts/health_test.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

scripts/spi_test.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import sys
4+
import time
5+
from datetime import datetime
6+
from collections import defaultdict, deque
7+
8+
os.environ['NO_RETRY'] = '1' # no spi retries
9+
from panda import Panda, PandaSpiException
10+
11+
12+
if __name__ == "__main__":
13+
s = defaultdict(lambda: deque(maxlen=30))
14+
def avg(k):
15+
return sum(s[k])/len(s[k])
16+
17+
#core = 6
18+
#from openpilot.common.realtime import config_realtime_process
19+
#config_realtime_process(core, 10)
20+
#os.system(f"echo {core} | sudo tee /proc/irq/10/smp_affinity_list")
21+
#os.system("sudo chrt -f -p 1 $(pgrep -f spi0)")
22+
#print(f"sudo taskset -pc {core} $(pgrep -f spi0)")
23+
#os.system(f"sudo taskset -pc {core} $(pgrep -f spi0)")
24+
25+
p = Panda()
26+
p.reset()
27+
start = datetime.now()
28+
le = p.health()['spi_error_count']
29+
while True:
30+
cnt = 0
31+
st = time.monotonic()
32+
while time.monotonic() - st < 1:
33+
try:
34+
p.get_type() # get_type has no processing on panda side
35+
except PandaSpiException:
36+
print(f"ERROR after {datetime.now() - start}\n\n")
37+
sys.stdout.write("\033[1;32;40m" + p.serial_read(0).decode('utf8') + "\033[00m" + "\n")
38+
sys.stdout.flush()
39+
sys.exit()
40+
cnt += 1
41+
s['hz'].append(cnt)
42+
43+
err = p.health()['spi_error_count']
44+
s['err'].append((err - le) & 0xFFFFFFFF)
45+
le = err
46+
47+
print(
48+
f"{avg('hz'):04.0f}Hz {avg('err'):04.0f} errors [{cnt:04d}Hz {s['err'][-1]:04d} errors] {datetime.now() - start}"
49+
)
50+

0 commit comments

Comments
 (0)