Instead of changing directory temporarily, mount the SD card to /sd
but do not change to it at all inside boot.py
. Modify your boot.py
to avoid os.chdir
entirely:
def mount_sd():
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()
Also make sure boot.py
completes quickly — any delays in boot.py
(e.g., slow SD init) might interfere with main.py
execution on some boards.