8000 Configure sdcardio automount within settings.toml · Issue #10342 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Configure sdcardio automount within settings.toml #10342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
relic-se opened this issue May 13, 2025 · 7 comments · Fixed by #10351
Closed

Configure sdcardio automount within settings.toml #10342

relic-se opened this issue May 13, 2025 · 7 comments · Fixed by #10351

Comments

@relic-se
Copy link

The new automount feature of sdcardio added in #10129 is great for devices which host an SD card connector directly on board. This feature is currently unavailable on devices which have an SD card added on via a breakout or some other daughter board. In my case, I am using a Raspberry Pi Pico 2W with a Camera PiCowbell.

I suggest that new constants be added to settings.toml to define the pins, SPI device, and other properties used by this feature to allow it to work on devices which don't support it by default.

If it isn't possible to support this feature due to compile-time constraints and flash size, an alternative would be to add additional boards for well-supported addon boards such as the PiCowbell line. This change would definitely open the gates for many more combinations of boards and addon boards, so it wouldn't be ideal.

@tannewt
Copy link
Member
tannewt commented May 14, 2025

I don't really want to do this because it is up to code.py to set things up for things off the board. Setting up the sdcard there should still make it available to the host via USB though.

@tannewt tannewt modified the milestones: 10.0.0, Long term May 14, 2025
@relic-se
Copy link
Author

@tannewt I think that is my end goal here, to allow the second drive to be presented by the device to directly access the SD card. In my testing with 10.0.0-alpha.4, this hasn't been the case. Does the sd card configuration need to be defined within boot.py or has the implementation not been completed at this point?

@tannewt
Copy link
Member
tannewt commented May 14, 2025

You must use native sdcardio for it to work I believe. What is your code.py?

@tannewt
Copy link
Member
tannewt commented May 14, 2025

Looks like I have a check to ensure it isn't heap allocated. Try removing the gc_nbytes() check:

fs_user_mount_t *sdcard = filesystem_for_path("/sd", &path_under_mount);
if (sdcard != root && (sdcard->blockdev.flags & MP_BLOCKDEV_FLAG_NATIVE) != 0 && gc_nbytes(sdcard) == 0) {

@relic-se
Copy link
Author

You must use native sdcardio for it to work I believe. What is your code.py?

Here's a stripped down example from my program which is just a basic sd card mounting procedure with card detect:

import board, digitalio, os, storage, time
from busio import SPI
from sdcardio import SDCard

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

sd_detect = digitalio.DigitalInOut(board.GP15)
sd_detect.direction = digitalio.Direction.INPUT
sd_detect.pull = digitalio.Pull.UP

spi = SPI(
    clock=board.GP18,
    MOSI=board.GP19,
    MISO=board.GP16,
)

state = True
while True:
    if sd_detect.value == state:
        continue
    state = sd_detect.value
    
    if not state:
        try:
            sdcard = SDCard(
                spi,
                cs=board.GP17,
            )
            vfs = storage.VfsFat(sdcard)
            storage.mount(vfs, "/sd")
            led.value = True
            print(os.listdir("/sd"))
        except OSError as e:
            print(e)
    else:
        storage.umount(vfs)
        del vfs
        sdcard.deinit()
        del sdcard
        led.val
8000
ue = False

Same deal here but without the card detect:

import board, storage
from busio import SPI
from sdcardio import SDCard

spi = SPI(
    clock=board.GP18,
    MOSI=board.GP19,
    MISO=board.GP16,
)

sdcard = SDCard(
    spi,
    cs=board.GP17,
)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

Neither example results in the second drive being available. It's listed within the Gnome Disks application but without any size, contents, etc.

Image

@relic-se
Copy link
Author

@tannewt Huzzah! Removing the gc_nbytes(sdcard) == 0 does in fact fix the situation and works for both examples even with removal and re-insertion. Awesome!

Disregard my initial settings.toml request. This is exactly what I was hoping for.

I'll make a quick PR for it and tie this issue to it to close as soon as it is merged. Thanks!

@dhalbert
Copy link
Collaborator

Fixed by #10351

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0