XIAO RP2350 with Micropython v1.24.0-preview.201.g269a0e0e1 does not start main.py

Hi @ahsrabrifat,
Thank you for your reply and suggestion. I tried your boot.py code however it returns this error.

MPY: soft reboot
Traceback (most recent call last):
  File "boot.py", line 13, in <module>
  File "boot.py", line 2, in mount_sd
NameError: name 'SDCard' isn't defined

The version of Micropython flashed in my XIAO RP2350 does not have an sdcard module in it.
See the commands I gave in Thonny, Shell:

>>> import machine
>>> dir(machine)
['__class__', '__name__', 'ADC', 'I2C', 'I2S', 'PWM', 'PWRON_RESET', 'Pin', 'RTC', 'SPI', 'Signal', 'SoftI2C', 'SoftSPI', 'Timer', 'UART', 'USBDevice', 'WDT', 'WDT_RESET', '__dict__', 'bitstream', 'bootloader', 'deepsleep', 'dht_readinto', 'disable_irq', 'enable_irq', 'freq', 'idle', 'lightsleep', 'mem16', 'mem32', 'mem8', 'reset', 'reset_cause', 'soft_reset', 'time_pulse_us', 'unique_id']
>>> dir(machine.sdcard)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'sdcard'
>>> 

So, that is why I downloaded a sdcard.py file and put it in /lib.

After adding:

from lib.sdcard import SDCard
from machine import Pin

an error that PIN_SD_CS was not defined.

I added:

    sd = SDCard(machine.Pin(machine.Pin.board.GP28))

next the error:

MPY: soft reboot
Traceback (most recent call last):
  File "boot.py", line 16, in <module>
  File "boot.py", line 5, in mount_sd
TypeError: function takes 3 positional arguments but 2 were given

because class SDCard starts with:

class SDCard:
    def __init__(self, spi, cs, baudrate=1320000):
        self.spi = spi
        self.cs = cs

then errors that os and sys were not defined
I ended up with this code of 28 lines that worked:

from lib.sdcard import SDCard
from machine import Pin
import os, sys

def mount_sd():
    PIN_SD_SCK  = machine.Pin.board.GP2
    PIN_SD_MOSI = machine.Pin.board.GP3
    PIN_SD_MISO = machine.Pin.board.GP4
    PIN_SD_CS   = machine.Pin.board.GP28

    # Setup for SD Card
    sd_spi = machine.SPI(0, 
        sck=machine.Pin(PIN_SD_SCK,   machine.Pin.OUT),
        mosi=machine.Pin(PIN_SD_MOSI, machine.Pin.OUT),
        miso=machine.Pin(PIN_SD_MISO, machine.Pin.OUT))

    sd = SDCard(sd_spi, machine.Pin(PIN_SD_CS))
    try:
        os.mount(sd, "/sd")
        print("SDCard mounted")
        return True
    except OSError as exc:
        print("mounting SDCard failed")
        sys.print_exception(exc)
        return False

if __name__ == '__main__':
    mount_sd()

Resul at boot:


MPY: soft reboot
SDCard mounted
MicroPython v1.24.0-preview.201.g269a0e0e1 on 2024-08-09; Raspberry Pi Pico2 with RP2350

Type "help()" for more information.

>>> 

As you can see: this runs your boot.py with my changes OK however still not running main.py.
Maybe the micropython version is not good (enough) for this XIAO RP2350.