I’ve just flashed MicroPython 1.17 on an STM32 MicroMod Processor board and am using both the ATP and Thing Plus Carrier boards. The latter has an SD card I’d like to use.
The Implementation-specific details section on the machine.SDCard page (https://docs.micropython.org/en/latest/ … DCard.html) has sections for the Pyboard, ESP32 and cc3200, but nothing for the STM32, and digging through the source I couldn’t discern from the code how to specify the correct SPI pins to create the SPI object.
I found some example code on the micropython.org site looks like this:
spi =SPI(1,baudrate=500000,polarity=0,phase=0,sck=Pin(18),mosi=Pin(5),miso=Pin(19))
but I need to know how to specify the SCK, MISO and MOSI pins on the STM32 Processor board using Pin in order to create the SPI device used to then create and then mount the SDCard object.
Any help much appreciated…
By falling back on defaults and finding from the documentation in the code I’ve learned how to refer to pins: using “Pin.board.NAME”, not “Pin.NAME”. So that part of the mystery solved.
I’ve managed to mount an SD card:
from machine import Pin, SPI
import sdcard, os
spi = SPI(1, baudrate=10000000, polarity=0, phase=0)
sd = sdcard.SDCard(spi, Pin(Pin.board.SPI_CS))
os.mount(sd, '/sd')
print('ls /sd: {}'.format(os.listdir('/sd')))
and while it is able to list its contents (using the last line above) the SD card does not stay mounted.
And really, what I was trying to accomplish was to mimic the behaviour of the Pyboard, which is to check if there is an SD card available on startup, mount it at “/pyboard/sd/”] and execute “/pyboard/sd/main.py” (instead of “/pyboard/flash/main.py”) if such a file exists.
As that doesn’t happen by default is somewhat surprising given it seems I’m running almost the same firmware as on the Pyboard (from what I understand). It would hopefully be the default behaviour on a board that has an SD card socket and an SD card in that socket.
Does anyone have any idea how to auto-mount an SD card to make this happen? (perhaps I should post this under a new forum topic…)