adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
MIT License
3.97k stars 1.16k forks source link

Add ability to use SD card as main storage #2738

Closed geekguy-wy closed 4 years ago

geekguy-wy commented 4 years ago

I would really like to see Circuitpython be able to use an SD card for main storage instead of regular flash. It would help allow boards that are not Express boards to be used better with Circuitpython because there is just not enough space in flash left after loading Circuitpython. It would be great to be able to use an SD card for main storage like Micropython can do now.

tannewt commented 4 years ago

I'd rather not remove the internal flash filesystem for non-Express boards because we then risk not having a block device to show as CIRCUITPY when an SD card is not present. We could do a better job supporting libraries loaded from SD card though.

Am I interpreting your suggestion right? Removing internal flash and requiring an SD card.

geekguy-wy commented 4 years ago

Oh, no, no. I do not suggest removing the flash in favor of the SD card. I just want to add the SD card as an alternative to flash for loading scripts and libraries. For instance, I have two Feather M0 RFM69 boards that I would really like to use with Circuitpython, but there is not enough flash left after loading Circuitpython. I would like to be able to add either a wired up SD card breakout or an Adalogger FeatherWing so I could load scripts and libraries from the SD card.

tannewt commented 4 years ago

So the internal flash filesystem is too small for you? You should be able to mount an SD card using a breakout already: https://github.com/adafruit/Adafruit_CircuitPython_SD/blob/master/examples/sd_read_simpletest.py

(It does take memory itself though.)

geekguy-wy commented 4 years ago

Yes. On a Feather M0 RFM69, I have 26.1 kb of storage left with Circuitpython 4.x.x loaded. I have not updated those boards to 5.x.x yet because they are really not usable with Circuitpython at this time. I realize the M0 also has a memory limit with just 32 kb RAM too, but the flash is just not enough storage.

makermelissa commented 4 years ago

I think being able to use the SD card to run your code.py off of would be handy even for an M4 if you wanted to change between programs easily. Come to think of it, maybe a loader program that sits in flash, inits the SD card and reads code off it would be kind of cool, but I'm not sure if that's not currently within the capability of CP.

dhalbert commented 4 years ago

It is already possible to import code on the sd card. It would be something like this:

import busio
import digitalio
import board
import storage
import sys
import adafruit_sdcard

SD_CS = board.SD_CS  # setup for M0 Adalogger; change as needed

# Connect to the card and mount the filesystem.
spi = board.SPI()
cs = digitalio.DigitalInOut(SD_CS)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

# add /sd to the end of sys.path. You could add it anywhere.
sys.path.append("/sd")

import something_on_the_sd_card
makermelissa commented 4 years ago

Excellent

geekguy-wy commented 4 years ago

Oh, OK! I was not aware that we could do that. There is no need for this issue then, so I will close it now.