Skip to content

Commit f02515b

Browse files
committed
initial add - define board pins for SD Card and mount file system working for rp2350 and esp32 IOT RBs
1 parent 45753e0 commit f02515b

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
3+
import machine
4+
from machine import Pin, SPI
5+
import sdcard
6+
7+
8+
import os
9+
import uos
10+
import time
11+
12+
# Define the boards we support with this deme - This is a dictionary the key being
13+
# the board uname.machine value, and value a tuple that contains SPI bus number and CS ping number.
14+
SupportedBoards = {
15+
"SparkFun IoT RedBoard RP2350 with RP2350": (1, 9),
16+
"SparkFun IoT RedBoard ESP32 with ESP32": (2, 5)
17+
}
18+
19+
20+
def mount_sd_card():
21+
22+
# is this a supported board?
23+
board_name = os.uname().machine
24+
if board_name not in SupportedBoards:
25+
print("This board is not supported")
26+
return False
27+
28+
# Get the SPI bus and CS pin for this board
29+
spi_bus, cs_pin = SupportedBoards[board_name]
30+
31+
# Create the SPI object
32+
spi = SPI(spi_bus, baudrate=1000000, polarity=0, phase=0)
33+
# Create the CS pin object
34+
cs = Pin(cs_pin, Pin.OUT)
35+
36+
# Create the SD card object
37+
try:
38+
sd = sdcard.SDCard(spi, cs)
39+
except Exception as e:
40+
print("[Error] ", e)
41+
return False
42+
43+
# Mount the SD card
44+
try:
45+
vfs = uos.VfsFat(sd)
46+
uos.mount(vfs, "/sd")
47+
except Exception as e:
48+
print("[Error] Failed to mount the SD Card", e)
49+
return False
50+
51+
print("SD Card mounted successfully")
52+
53+
return True

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy