Skip to content

Commit ce3738c

Browse files
committed
drivers/sdcard/sdcard.py: Fixes per PR discussion.
Merged crc7.py into sdcard.py, fixed many little things per suggestions. Removed hardwired crcs from cmd, always recompute. Signed-off-by: Marcus Mendenhall <[email protected]>
1 parent dda1c98 commit ce3738c

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

micropython/drivers/storage/sdcard/sdcard.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,12 @@
4343
b"\xe4\xd2\xc0\x1c\x0e8*TFpb\x8c\x9e\xa8\xba\xc4\xd6\xe0\xf2"
4444
)
4545

46-
# ruff: noqa: F821 - @asm_thumb and @viper decorator adds names to function scope
47-
try:
48-
from uctypes import addressof
49-
50-
@micropython.viper
51-
def crc7(buf) -> int:
52-
n = int(len(buf))
53-
table = ptr8(addressof(crc7_be_syndrome_table))
54-
bp = ptr8(addressof(buf))
55-
idx = 0
56-
crc = 0
57-
while idx < n:
58-
crc = table[crc ^ bp[idx]]
59-
idx = idx + 1
60-
return crc
61-
62-
# test to make sure this works!
63-
# print(f"{crc7('abcde'):02x}")
64-
assert crc7(b"abcde") == 0x34
65-
except:
66-
# non-viper version if viper can'r be built
67-
def crc7(buf) -> int:
68-
crc = 0
69-
for b in buf:
70-
crc = crc7_be_syndrome_table[crc ^ b]
71-
return crc
46+
47+
def crc7(buf) -> int:
48+
crc = 0
49+
for b in buf:
50+
crc = crc7_be_syndrome_table[crc ^ b]
51+
return crc
7252

7353

7454
def gb(bigval, b0, bn):

0 commit comments

Comments
 (0)