<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[SD Card wont init or do anything]]></title><description><![CDATA[<p dir="auto">I have a M5Stack Core Basic 2.7. I am attempting to use the SD card slot. It is a 16GB SDHC card that is formatted to FAT32. I created a simple block code in UIFlow2.0 that is:<br />
Setup(Init Built in hardware-&gt;Init SD Card-&gt;Print(SDCard Listdir()). Init SD card is defined as:<br />
sdcard.SDCard(slot=2, width=1, sck=18, miso=19, mosi=23, cs=4, freq=1000000)</p>
<p dir="auto">This gives the error of:<br />
[Errno 22] EINVAL<br />
E (3390) spi: spi_bus_initialize(758): SPI bus already initialized.<br />
File "hardware/sdcard.py", line 21, in sdcard<br />
OSError: (-259, 'ESP_ERR_INVALID_STATE')</p>
<p dir="auto">I tried adding a spi.deinit block but this doesn't even seem to be in the source code.<br />
I have also tried the test_sdcard.py file in the uiflow-micropython repo and same thing happens.<br />
What am I doing wrong? I have had this working on the same board and SD card with arduino but the micropython one doesn't seem to work at all.<br />
Here is the code as well:</p>
<pre><code>import os, sys, io
import M5
from M5 import *
from hardware import sdcard
label0 = None
def setup():
  global label0
  M5.begin()
  Widgets.fillScreen(0x222222)
  label0 = Widgets.Label("label0", 117, 208, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
  sdcard.SDCard(slot=2, width=1, sck=18, miso=19, mosi=23, cs=4, freq=1000000)
  print(os.listdir('/sdcard/'))
def loop():
  global label0
  M5.update()
if __name__ == '__main__':
  try:
    setup()
    while True:
      loop()
  except (Exception, KeyboardInterrupt) as e:
    try:
      from utility import print_error_msg
      print_error_msg(e)
    except ImportError:
      print("please update to latest firmware")

</code></pre>
]]></description><link>https://community.m5stack.com/topic/7163/sd-card-wont-init-or-do-anything</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 11:05:56 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/7163.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 06 Jan 2025 14:48:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SD Card wont init or do anything on Wed, 26 Nov 2025 15:23:45 GMT]]></title><description><![CDATA[<p dir="auto">Thank you so much for posting this. This works perfectly for my M5 Paper as well (changing out the hardware numbers as needed). I was able to write some custom blocks based on this. &lt;3</p>
]]></description><link>https://community.m5stack.com/post/30238</link><guid isPermaLink="true">https://community.m5stack.com/post/30238</guid><dc:creator><![CDATA[mapache]]></dc:creator><pubDate>Wed, 26 Nov 2025 15:23:45 GMT</pubDate></item><item><title><![CDATA[Reply to SD Card wont init or do anything on Thu, 20 Nov 2025 22:11:19 GMT]]></title><description><![CDATA[<p dir="auto">This code works on the SD card for me, Remember to format Fat32 and keep device size 32GB or less</p>
<pre><code>import machine
import os
import time

# --- Configuration for M5Stack CoreS3 SD Card ---
SD_SCK = 36
SD_MISO = 35
SD_MOSI = 37
SD_CS = 4

# Configuration for machine.SDCard
SD_SLOT = 2       # Typically used for SPI access on ESP32/S3
SD_FREQ = 1000000 # 1MHz frequency for reliable initialization
MOUNT_POINT = "/sd"
TEST_FILE_PATH = MOUNT_POINT + "/cores3_test_log.txt"

def initialize_and_mount_sd():
    """Initializes the SD card interface and mounts the filesystem."""
    print("Attempting to initialize SD card...")
    try:
        # Initialize the SDCard object using the specific pins for the CoreS3
        sd = machine.SDCard(
            slot=SD_SLOT,
            sck=machine.Pin(SD_SCK),
            miso=machine.Pin(SD_MISO),
            mosi=machine.Pin(SD_MOSI),
            cs=machine.Pin(SD_CS),
            freq=SD_FREQ
        )
        print("Hardware initialized.")

        # Mount the SD card filesystem (VfsFat)
        vfs = os.VfsFat(sd)
        os.mount(vfs, MOUNT_POINT)
        print(f"SD Card successfully mounted at {MOUNT_POINT}")
        return vfs
    except Exception as e:
        print(f"ERROR initializing or mounting SD card: {e}")
        print("Please ensure the SD card is inserted correctly and formatted (FAT32).")
        return None

def write_demo(filepath):
    """Writes sample data to a file on the SD card."""
    print(f"\n--- Writing Demo ---")
    content = "Hello from M5Stack CoreS3!\n"
    content += f"MicroPython SD Card Test.\nTimestamp: {time.time()}"

    try:
        # Open the file in write mode ('w')
        with open(filepath, "w") as f:
            bytes_written = f.write(content)
        print(f"Successfully wrote {bytes_written} bytes to {filepath}")
        return True
    except Exception as e:
        print(f"ERROR writing to file: {e}")
        return False

def read_demo(filepath):
    """Reads data from the file on the SD card."""
    print(f"\n--- Reading Demo ---")
    try:
        # Open the file in read mode ('r')
        with open(filepath, "r") as f:
            data = f.read()
        print(f"Contents of {filepath}:")
        print("-" * 30)
        print(data)
        print("-" * 30)
    except Exception as e:
        print(f"ERROR reading from file: {e}")

def list_directory_demo(path):
    """Lists the contents of the directory with file sizes."""
    print(f"\n--- Directory Listing Demo ({path}) ---")
    try:
        items = os.listdir(path)
        if not items:
            print("(Empty Directory)")
            return

        print(f"{'Name':&lt;25} {'Size (Bytes)':&gt;15}")
        print("-" * 41)
        for item in items:
            try:
                # os.stat returns a tuple; index 6 contains the file size
                stats = os.stat(path + "/" + item)
                size = stats[6]
                print(f"{item:&lt;25} {size:&gt;15}")
            except Exception as e:
                print(f"{item:&lt;25} (Error getting stats)")
    except Exception as e:
        print(f"ERROR listing directory: {e}")

def unmount_sd(mount_point):
    """Unmounts the SD card filesystem."""
    print("\n--- Unmounting ---")
    try:
        # Crucial to prevent corruption
        os.umount(mount_point)
        print("SD Card unmounted successfully.")
    except Exception as e:
        print(f"ERROR unmounting SD Card: {e}")

def main():
    print("Starting M5Stack CoreS3 SD Card Demo")
    
    # 1. Initialize and Mount
    vfs = initialize_and_mount_sd()

    if vfs:
        # 2. List initial contents
        list_directory_demo(MOUNT_POINT)
        
        # 3. Write data
        if write_demo(TEST_FILE_PATH):
            # 4. Read data back
            read_demo(TEST_FILE_PATH)
        
        # 5. List contents again to show the new file and size
        list_directory_demo(MOUNT_POINT)
        
        # 6. Unmount
        unmount_sd(MOUNT_POINT)
    else:
        print("Demo aborted due to SD card initialization failure.")

if __name__ == "__main__":
    main()
</code></pre>
]]></description><link>https://community.m5stack.com/post/30218</link><guid isPermaLink="true">https://community.m5stack.com/post/30218</guid><dc:creator><![CDATA[rweaving]]></dc:creator><pubDate>Thu, 20 Nov 2025 22:11:19 GMT</pubDate></item><item><title><![CDATA[Reply to SD Card wont init or do anything on Wed, 15 Jan 2025 01:34:18 GMT]]></title><description><![CDATA[<pre><code>import os, sys, io
import M5
from M5 import *
from hardware import sdcard



label0 = None


def setup():
  global label0

  M5.begin()
  Widgets.fillScreen(0x222222)
  label0 = Widgets.Label("label0", 21, 46, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)

  sdcard.SDCard(slot=2, width=1, sck=18, miso=19, mosi=23, cs=4, freq=1000000)
  label0.setText(str(os.listdir('/sd/')))


def loop():
  global label0
  M5.update()


if __name__ == '__main__':
  try:
    setup()
    while True:
      loop()
  except (Exception, KeyboardInterrupt) as e:
    try:
      from utility import print_error_msg
      print_error_msg(e)
    except ImportError:
      print("please update to latest firmware")

</code></pre>
]]></description><link>https://community.m5stack.com/post/27885</link><guid isPermaLink="true">https://community.m5stack.com/post/27885</guid><dc:creator><![CDATA[lbuque]]></dc:creator><pubDate>Wed, 15 Jan 2025 01:34:18 GMT</pubDate></item></channel></rss>