diff options
author | Jeremy Herbert <jeremy.006@gmail.com> | 2019-11-04 01:25:16 -0800 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-11-06 11:34:02 +1100 |
commit | 4f0f3dfb410062db4d41e42c2c7cff6c8b48f071 (patch) | |
tree | 27465d65df6f42174bd4c7f655a5c4f820d74267 | |
parent | d209f9ebe72aa2af0af72ed3bba737a47c45e567 (diff) |
drivers/sdcard: Raise exception on timeout of readinto.
Otherwise the code can get stuck in an infinite loop if the SD card fails
to respond to a read.
-rw-r--r-- | drivers/sdcard/sdcard.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/sdcard/sdcard.py b/drivers/sdcard/sdcard.py index ffc551d9a..fc6787556 100644 --- a/drivers/sdcard/sdcard.py +++ b/drivers/sdcard/sdcard.py @@ -172,10 +172,13 @@ class SDCard: self.cs(0) # read until start byte (0xff) - while True: + for i in range(_CMD_TIMEOUT): self.spi.readinto(self.tokenbuf, 0xff) if self.tokenbuf[0] == _TOKEN_DATA: break + else: + self.cs(1) + raise OSError("timeout waiting for response") # read data mv = self.dummybuf_memoryview |