support DigitalInOutProtocol for CS of sdcardio.SDCard#11053
Conversation
|
With my last fix, all builds are now successful. @dhalbert , @mikeysklar : I don't have the hardware to test the automount feature (I never bothered to route the sd-card-detect pin on my pcbs). It would be great if one of you could do a test on one of the boards with integrated sd-card that use this feature (e.g. adalogger, fruit-jam). |
|
checking now on a Metro RP2350 |
|
I tried this PR on a Metro RP2350 and connected it two different hosts macOS and Linux. CircuitPython 10.3.0-alpha.2-31-g6285efc59e-dirty I'm not seeing the microSD drive pass through correctly. Tried both exFAT (64GB) and FAT32 (16GB) cards. On macOS I get this error. "The disk you attached was not readable by this computer." The disk device is visible, but the filesystem fails to mount. It looks like this is passing an address instead of an object.
should be:
Will confirm. |
|
Yep, that fixed it: Ubuntu 24.04.4 LTS: macOS Tahoe 26.5.1: |
|
@mikeysklar thanks for testing and for tracking down the bug. I will update my PR, but that won't happen before Tuesday. |
|
No rush. Let me know if you think it is worth checking on other boards or if the Metro RP2350 is enough. I do have an Adalogger RP2040. |
|
I think one board is enough - they all use the same automount function. I did test the other codepath (normal mount using |
|
With the latest commit, this should be ready for merging. Thanks again to @mikeysklar for testing and fixing the automount codepath. |
dhalbert
left a comment
There was a problem hiding this comment.
Looks good, but I have a concern about None for the CS pin.
| self->cs = digitalinout_protocol_from_pin(cs, MP_QSTR_cs, true, use_port_allocation, &self->own_cs); | ||
| if (self->cs != mp_const_none) { | ||
| digitalinout_protocol_switch_to_output(self->cs, true, DRIVE_MODE_PUSH_PULL); | ||
| } |
There was a problem hiding this comment.
The true third argument to digitalinout_protocol_from_pin() is allowing cs to be None, and the code further down also allows that.
In the original code, cs must be a pin: that's validated in shared-bindings.
So I don't think you want to allow None for CS, unless you want to handle a case where CS is pulled down all the time. (I'm not sure that even works.)
|
This is indeed following the implementation of The board I am currently bringing up does this for the display CS, so I was happy to see that |
Some displays can work with CS tied to low But for SD cards, having CS high sometimes is a required part of the spec. For instance, there is a reset sequence for SD cards where you hold CS high, and then clock the card for >= 74 clock cycles to have it go into an init state. See circuitpython/shared-module/sdcardio/SDCard.c Lines 91 to 96 in 8a10c8f and circuitpython/shared-module/sdcardio/SDCard.c Lines 258 to 261 in 8a10c8f As mentioned in the code, https://nodeloop.org/guides/sd-card-spi-init-guide/ talks about this, and cautions about CS. To quote:
Maybe some cards work without sending the init sequence, but it's out of spec, and one should not design a board without a CS pin for an SD card. |
|
Good arguments, I am convinced. I will update the implementation accordingly. |
This fixes #11047. The implementation is basically a copy&paste&edit of what
fourwire.FourWiredoes.Tested on an upcoming Waveshare board that uses SD_CS behind an ioexpander, and on a Pico with a normal SD breakout attached.