-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Sdcard in core #2863
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
Sdcard in core #2863
Conversation
1d2fc3f
to
a2becfa
Compare
@dhalbert is this review on your radar? |
For now, let's call this _sdcardio just in the top level so that we can evolve the API as SDIO support is added. Internally the names can stay the same. |
@tannewt Sorry, I looked for this the other day, and it seemed like a number of changes were pending, so I waited. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK -- I found the commit fixing the doc example -- thanks !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only had stylistic comments. It looks good but I have not tested it. Are we going to rewrite adafruit_sdcard
to be a thin wrapper around this for now, or just deprecate it?
Thanks @dhalbert I'll take your comments into account when I revise the PR to rename it as _sdcardio. |
|
tested this PR on a grand_central_m4_express
I had to make a few changes to the example since the Grand Central M4 does not use the statndar SPI bus for the SD Card. here is the example I ran
took it one step further and actually executed a python script (hello.py) from the sdcard
here is the example sdcardio_lib.py
oops _I noticed that I was still importing adafruit_sdcard -- It still works when I remove it!
and
|
@jepler There are still some unresolved comments above (alphabetization and "not bitbangio.SPI") |
This has been updated with SDIO for STM32F405 Feather. |
Tested SDIOCard example on feather_stm32f405_express -- worked fine! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for myself: https://github.com/avrxml/asf/blame/61c7353e0183bbd0615db1d0a3144cbdcd09983a/common/components/memory/sd_mmc/sd_mmc.c
Also, this PR presently reverts two submodules to an intended ref. oof.
I think it'd be better to separate the bus from the SDCard APIs here. # Connect to the card and mount the filesystem.
bus = busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO)
device = adafruit_bus_device.SPIDevice(bus, board.SD_CS) # Also takes frequency, polarity and phase.
# For SDIO
# device = sdioio.SDIO(clock=board.SDIO_CLOCK, command=board.SDIO_COMMAND, data=(board.SDIO_DATA,), frequency=25000000)
sdcard = sdcardio.SDCard(device) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple comments about the Systick and peripherals structures. I'm going to take a closer look at HAL_GetTick and try to get a handle on what's going on with the low power code.
52e6ec5
to
7499e1c
Compare
This has grown and is really multiple different topics. We need to split it up into multiple PRs. Our priority list becomes:
(that's not to say we wouldn't love someone to pick up #3 before I get a chance to! It's still the only reasonable way to use the SD card on the STM32F405 Feather. The main thing that needs completion on STM32F405 is handling of pin assignments, instead of ignoring them as now) We also need to nail down what the API is going to look like, to avoid more renames and incompatible changes if possible. We have discussed this informally a number of times, but I'd like to get to an official decision.
If you take my suggestions/preferences, this leads to the following code snippets for mounting SD storage, depending on interface:
and
We are going to do priorities 1 and 2 in this PR and push #3 to a separate PR or issue. (comment updated based on discussion with @tannewt via discord) |
46096e6
to
28b1d0b
Compare
Testing performed: That a card is successfully mounted on Pygamer with the built in SD card slot This module is enabled for most FULL_BUILD boards, but is disabled for samd21 ("M0"), litex, and pca10100 for various reasons.
This will ultimately be used by SDIO, where a variable length list of data lines is called for.
There is no implementation yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple minor things.
Co-authored-by: Scott Shawcroft <[email protected]>
I believe I've addressed all your requested changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this! Folks will be excited for the speedups!
This pull request adds
sdcardio.SDCard
and, for select atmel-sam boards,sdio.SDCard
.sdcardio.SDCard
is nearly, but not quite, compatible withadafruit_sdcard.SDCard
: It takes amicrocontroller.Pin
for the chip select (cs) line, not adigitalio.DigitalInOut
object, because this simplifies object lifetime and may help us to someday let vfs mounts survive soft-reset. It also defaults to a higher baudrate, 8MHz instead of 1.32MHz.sdcardio
benchmarks vary from card to card, but on one 4GB card, I measured an increase in read rates from 583 kB/s to 838.2kB/s, an increase of about 40%. Write rates remain very low, just 4kB/s(!) with adafruit_sdcard and sdcardio.All
sdcardio
testing was on a PyGamer with built in SD card slot. Three SD cards were tested (4GB Sandisk, 8GB Sandisk, 64GB Samsung). Some lower capacity SD cards are on order and I'll verify they all work, or if they don't whether they work under adafruit_sdcard.sdcardio
is enabled on all "full-build"s except M0, PCA10100, and litex, for reasons outlined in the individual commits.sdioio
implements an SD card interface using the SDIO bus. This is enabled and tested on the Microchip SAME54 Xplained Pro board and is also enabled on the Grand Central. The relevant pins are on headers of the Grand Central M4 Express, but (likely due to dodgy wiring) did not work in my testing.Known problems:
sdioio.SDCard
hangs at initializationsdcardio.SDCard
misidentifies the capacity of a particular 64GB card I have for testing, same asadafruit_sdcard
We made the decision to deprioritize the stm32f405 feather support for SDIO SD cards. This work is not finished and has not been renamed to suit the latest decisions, and so it have been removed from this PR. See https://github.com/jepler/circuitpython/tree/sdio-stm32-broken-rename -- We will get back to this at some point, but we would also love to see a community member pick up the work. Two main things remain to be done: Follow the naming convention of
sdioio
and finish the pin logic in the constructor.