Skip to content

Commit da525ba

Browse files
committed
timeout to avoid getting stuck in while loop
1 parent c59df6b commit da525ba

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

adafruit_sdcard.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,12 @@ def _cmd(
256256
if data_block:
257257
# Wait for the start block byte
258258
buf[1] = 0xFF
259-
while buf[1] != 0xFE:
259+
for _ in range(_CMD_TIMEOUT):
260260
card.readinto(buf, start=1, end=2, write_value=0xFF)
261+
if buf[1] == 0xFE:
262+
break
263+
if buf[1] != 0xFE:
264+
return -1
261265
card.readinto(response_buf, write_value=0xFF)
262266
if data_block:
263267
# Read the checksum

0 commit comments

Comments
 (0)