Skip to content

sd_drive: refuse a card that never answered instead of serving no blocks - #51

Merged
bdbarnett merged 1 commit into
mainfrom
fix/sd-drive-geometry
Sep 26, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
fix/sd-drive-geometry

Conversation

@bdbarnett

Copy link
Copy Markdown
Contributor

The last section of #4: examples/sd_drive.py read card.ioctl(4, 0) straight into its block count. An empty slot or a card that times out answers -1 rather than raising, so the example printed a negative size, attached a drive of no blocks, and sat in its loop saying nothing. That's how #4 was first mistaken for a broken example.

card_geometry() now refuses a non-positive or non-integer block count or size with a RuntimeError that says to check the slot and reset the board, before anything is attached.

tests/test_sd_drive_example.py runs the example's main() against a fake card and device. Against the old example it fails three subtests and errors on the fourth (-1/-1, 0 blocks, -1 block size, None). With the fix all pass, and the control, a healthy 62,685,184 x 512 card, still attaches both ways. Full suite: 186 tests OK (22 skipped). The example also compiles on MicroPython 1.29.

Not run on a board. #4 stays open for the part that needs a card in the P4's slot.

Refs #4

@bdbarnett
bdbarnett merged commit 4c01722 into main Sep 26, 2026
12 checks passed
@bdbarnett
bdbarnett deleted the fix/sd-drive-geometry branch September 26, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant