File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments