Skip to content

Commit 619deea

Browse files
committed
rework to shuttle testing and chip rom code, related to ongoing .cn tt04 bringup
1 parent b512014 commit 619deea

File tree

13 files changed

+966
-50
lines changed

13 files changed

+966
-50
lines changed

src/first_boot.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ command = test_bidirs_03p5(0xff)
3131
shuttle = tt03p5
3232

3333

34-
[run_02_test_clocking]
34+
[run_test_clocking_tt03p5]
3535
message = Test clocking a project manual style
36-
command = test_clocking_03p5(0x42)
36+
command = test_clocking(False, 128, 1)
3737
shuttle = tt03p5
3838

39-
[run_01_factory_test]
39+
[run_test_clocking_tt04]
4040
message = TT04 factory test
41-
command = test_clocking_04(0x42)
41+
command = test_clocking(True, 128, 1)
4242
shuttle = tt04
4343

4444

src/tests/__init__.py

Whitespace-only changes.

src/tests/counter_read.py

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Clock speed test, Michael Bell
2+
# This test clocks the tt_um_test design at a high frequency
3+
# and checks the counter has incremented by the correct amount
4+
5+
import machine
6+
import rp2
7+
import time
8+
9+
from ttboard.mode import RPMode
10+
from ttboard.demoboard import DemoBoard
11+
12+
# PIO program to drive the clock. Put a value n and it clocks n+1 times
13+
# Reads 0 when done.
14+
@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, autopull=True, pull_thresh=32, autopush=True, push_thresh=32)
15+
def clock_prog():
16+
out(x, 32) .side(0)
17+
label("clock_loop")
18+
irq(4) .side(1)
19+
jmp(x_dec, "clock_loop").side(0)
20+
irq(clear, 4) .side(0)
21+
in_(null, 32) .side(0)
22+
23+
@rp2.asm_pio(autopush=True, push_thresh=32, in_shiftdir=rp2.PIO.SHIFT_RIGHT, fifo_join=rp2.PIO.JOIN_RX)
24+
def read_prog():
25+
in_(pins, 2)
26+
27+
# Select design, don't apply config so the PWM doesn't start.
28+
tt = DemoBoard(apply_user_config=False)
29+
tt.shuttle.tt_um_test.enable()
30+
31+
# Setup the PIO clock driver
32+
sm = rp2.StateMachine(0, clock_prog, sideset_base=machine.Pin(0))
33+
sm.exec("irq(clear, 4)")
34+
sm.active(1)
35+
36+
# Setup the PIO counter read
37+
sm_rx = rp2.StateMachine(1, read_prog, in_base=machine.Pin(3))
38+
39+
# Setup read DMA
40+
dst_data = bytearray(8192)
41+
d = rp2.DMA()
42+
43+
# Read using the SM1 RX DREQ
44+
c = d.pack_ctrl(inc_read=False, treq_sel=5)
45+
46+
# Read from the SM1 RX FIFO
47+
d.config(
48+
read=0x5020_0024,
49+
write=dst_data,
50+
count=len(dst_data)//4,
51+
ctrl=c,
52+
trigger=False
53+
)
54+
55+
def start_rx():
56+
# Reset the SM
57+
sm_rx.active(0)
58+
while sm_rx.rx_fifo() > 0: sm_rx.get()
59+
sm_rx.restart()
60+
61+
# Wait until out0 changes from its current value
62+
if machine.Pin(3).value():
63+
sm_rx.exec("wait(0, pin, 0)")
64+
else:
65+
sm_rx.exec("wait(1, pin, 0)")
66+
67+
# Re-activate SM, it will block until the wait command completes
68+
sm_rx.active(1)
69+
70+
71+
# Frequency for the RP2040, the design is clocked at half this frequency
72+
def run_test(freq):
73+
# Multiply requested project clock frequency by 2 to get RP2040 clock
74+
freq *= 2
75+
76+
if freq > 266_000_000:
77+
raise ValueError("Too high a frequency requested")
78+
79+
machine.freq(freq)
80+
81+
try:
82+
# Run 64 clocks
83+
print("Clock test... ", end ="")
84+
start_rx()
85+
sm.put(63)
86+
sm.get()
87+
print(f" done. Value now: {tt.output_byte}")
88+
89+
# Print the values read back for inspection
90+
for j in range(4):
91+
readings = sm_rx.get()
92+
for i in range(16):
93+
val = (readings >> (i*2)) & 0x3
94+
print(val, end = " ")
95+
print()
96+
sm_rx.active(0)
97+
98+
total_errors = 0
99+
100+
for _ in range(10):
101+
last = tt.output_byte
102+
103+
# Setup the read SM and DMA transfer into the verification buffer
104+
start_rx()
105+
d.config(write=dst_data, trigger=True)
106+
107+
# Run clock for enough time to fill the buffer
108+
t = time.ticks_us()
109+
sm.put(1024*17)
110+
sm.get()
111+
t = time.ticks_us() - t
112+
print(f"Clocked for {t}us: ", end = "")
113+
114+
# Print the first 16 values in the DMA'd buffer
115+
for j in range(0,4):
116+
readings = dst_data[j]
117+
for i in range(4):
118+
val = (readings >> (i*2)) & 0x3
119+
print(val, end = " ")
120+
121+
# Check the counter has incremented by 1, as we sent a
122+
# multiple of 256 clocks plus one more
123+
if tt.output_byte != (last + 1) & 0xFF:
124+
print("Error: ", end="")
125+
print(tt.output_byte)
126+
127+
# Check the read data from the counter continuously increases
128+
def verify(count, expected_val, retry):
129+
errors = 0
130+
131+
for j in range(2,len(dst_data)):
132+
readings = dst_data[j]
133+
for i in range(4):
134+
val = (readings >> (i*2)) & 0x3
135+
if count == 1 and val != expected_val:
136+
if retry:
137+
return -1
138+
else:
139+
print(f"Error at {j}:{i} {val} should be {expected_val}")
140+
errors += 1
141+
count += 1
142+
if count == 2:
143+
expected_val = (expected_val + 1) & 0x3
144+
count = 0
145+
if errors > 10: break
146+
return errors
147+
148+
expected_val = dst_data[2] & 0x3
149+
errors = verify(1, expected_val, True)
150+
if errors == -1:
151+
expected_val = (dst_data[2] >> 2) & 0x3
152+
errors = verify(0, expected_val, False)
153+
154+
total_errors += errors
155+
if errors > 10:
156+
return total_errors
157+
158+
finally:
159+
# Remove overclock
160+
if freq > 133_000_000:
161+
machine.freq(133_000_000)
162+
163+
return total_errors
164+
165+
if __name__ == "__main__":
166+
freq = 50_000_000
167+
while True:
168+
print(f"\nRun at {freq/1000000}MHz project clock\n")
169+
errors = run_test(freq)
170+
if errors > 10: break
171+
freq += 1_000_000

src/tests/counter_speed.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Clock speed test, Michael Bell
2+
# This test clocks the tt_um_test design at a high frequency
3+
# and checks the counter has incremented by the correct amount
4+
#
5+
6+
import machine
7+
import rp2
8+
import time
9+
10+
from ttboard.mode import RPMode
11+
from ttboard.demoboard import DemoBoard
12+
13+
# PIO program to drive the clock. Put a value n and it clocks n+1 times
14+
# Reads 0 when done.
15+
@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, autopull=True, pull_thresh=32, autopush=True, push_thresh=32)
16+
def clock_prog():
17+
out(x, 32) .side(0)
18+
label("clock_loop")
19+
nop() .side(1)
20+
jmp(x_dec, "clock_loop").side(0)
21+
in_(null, 32) .side(0)
22+
23+
# Select design, don't apply config so the PWM doesn't start.
24+
tt = DemoBoard(apply_user_config=False)
25+
tt.shuttle.tt_um_test.enable()
26+
27+
# Setup the PIO clock driver
28+
sm = rp2.StateMachine(0, clock_prog, sideset_base=machine.Pin(0))
29+
sm.active(1)
30+
31+
def run_test(freq, fast=False):
32+
# Multiply requested project clock frequency by 2 to get RP2040 clock
33+
freq *= 2
34+
35+
if freq > 350_000_000:
36+
raise ValueError("Too high a frequency requested")
37+
38+
if freq > 266_000_000:
39+
rp2.Flash().set_divisor(4)
40+
41+
machine.freq(freq)
42+
43+
try:
44+
# Run 1 clock
45+
print("Clock test... ", end ="")
46+
sm.put(1)
47+
sm.get()
48+
print(f" done. Value: {tt.output_byte}")
49+
50+
errors = 0
51+
for _ in range(10):
52+
last = tt.output_byte
53+
54+
# Run clock for approx 0.25 or 1 second, sending a multiple of 256 clocks plus 1.
55+
clocks = (freq // 2048) * 256 if fast else (freq // 512) * 256
56+
t = time.ticks_us()
57+
sm.put(clocks)
58+
sm.get()
59+
t = time.ticks_us() - t
60+
print(f"Clocked for {t}us: ", end = "")
61+
62+
# Check the counter has incremented by 1.
63+
if tt.output_byte != (last + 1) & 0xFF:
64+
print("Error: ", end="")
65+
errors += 1
66+
print(tt.output_byte)
67+
68+
if not fast:
69+
# Sleep so the 7-seg display can be read
70+
time.sleep(0.5)
71+
finally:
72+
if freq > 133_000_000:
73+
machine.freq(133_000_000)
74+
if freq > 266_000_000:
75+
rp2.Flash().set_divisor(2)
76+
77+
return errors
78+
79+
if __name__ == "__main__":
80+
freq = 66_000_000
81+
while True:
82+
print(f"\nRun at {freq/1000000}MHz project clock\n")
83+
errors = run_test(freq, True)
84+
if errors > 0: break
85+
freq += 2_000_000

0 commit comments

Comments
 (0)