Could not format the SD card by command : os.VfsFat.mkfs(sd)

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
woot_srx
Posts: 7
Joined: Fri Sep 29, 2017 7:49 am

Could not format the SD card by command : os.VfsFat.mkfs(sd)

Post by woot_srx » Wed Oct 09, 2019 3:55 am

I could mount the SD card then write and read files, but sometime I found files corrupted.
So I want to format the SD card by os.VfsFat.mkfs(sd) but I got error.

My code for mounting SD card:

Code: Select all

=== from machine import Pin,SPI
=== import json, sdcard, os,time
=== def SD_BEGIN():
===     spi = SPI(sck=Pin(13), mosi=Pin(23), miso=Pin(22))
===     spi.init()  # Ensure right baudrate
===     sd = sdcard.SDCard(spi, Pin(21)) # Compatible with PCB
===     vfs = os.VfsFat(sd)
===     os.mount(vfs, '/sd')
===     print('Filesystem check')
===     print(os.listdir())
===     print(os.listdir('/sd'))
=== SD_BEGIN()
Filesystem check
['sd', 'boot.py', 'sdcard.py', 'LOG']
['System Volume Information', '010001.txt']
>>>
When I format the SD card, I got error

Code: Select all

=== from machine import Pin,SPI
=== import json, sdcard, os,time
=== spi = SPI(sck=Pin(13), mosi=Pin(23), miso=Pin(22))
=== spi.init()  # Ensure right baudrate
=== sd = sdcard.SDCard(spi, Pin(21)) # Compatible with PCB
=== os.VfsFat.mkfs(sd)
Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
OSError: [Errno 5] EIO
>>>
Could you please suggest me? How shall i do?

Thank you in advance.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Could not format the SD card by command : os.VfsFat.mkfs(sd)

Post by Roberthh » Wed Oct 09, 2019 6:07 am

For an example about how-to, you may look in https://github.com/micropython/micropyt ... 32/modules at the files inisetup.py and flashbdev.py.

woot_srx
Posts: 7
Joined: Fri Sep 29, 2017 7:49 am

Re: Could not format the SD card by command : os.VfsFat.mkfs(sd)

Post by woot_srx » Fri Oct 11, 2019 4:21 am

Roberthh wrote:
Wed Oct 09, 2019 6:07 am
For an example about how-to, you may look in https://github.com/micropython/micropyt ... 32/modules at the files inisetup.py and flashbdev.py.
Thank you so much, i will study according your suggestion.

Post Reply