SDcard in SPI mode using Loboris port?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: SDcard in SPI mode using Loboris port?

Post by loboris » Fri Mar 23, 2018 11:17 pm

If you have couple od SMD 10K resistors, it will be easier to use.

Image

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: SDcard in SPI mode using Loboris port?

Post by OutoftheBOTS_ » Sat Mar 24, 2018 1:15 am

:lol:

symac
Posts: 11
Joined: Thu Jan 04, 2018 2:01 pm

Re: SDcard in SPI mode using Loboris port?

Post by symac » Sat Mar 24, 2018 4:43 pm

With all these posts it seems that reading a microsd card on an ESP32 in python should be doable :) I don't have a microsd-SD card adapter and I'd like to be able to use my microsdcard board so I have tried again now that I (think I) fully understand the pullup thing and that I know that the microsdcard might be the origin of error.

The first thing I wanted to try was coming back to SPI mode based on OutoftheBOTS_ message that shows that it can work. So far I have replicated the assembling in the post (plus added a 10k pullup on MOSI/D15 because it seems to be required according to this page). And I have two errors. If I try to replicate the code given by OutoftheBOTS_ :

Code: Select all

>>> import uos
>>> import os
>>> uos.sdconfig(uos.SDMODE_SPI, clk=14, mosi=15, miso=2, cs=13)
>>> os.mountsd("/sd")
The latest step gives me the following error :

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert str to int
If I remove the parameter "/sd" it's fine, any idea why (even if I don't think it's my main issue, I'd like to understand what is going wrong)?

As I don't think it is the main issue, I am trying without the "/sd" parameter. What seems to appear now is that it might be, as loboris suggested an issue with my SDCard? Indeed if I try with a sandisk 2Gb (that I got with a lowcost gopro, not sure it is really a legacy SanDisk), the error I get is :

Code: Select all

>>> uos.mountsd()
E (267388) sdspi_host: sdspi_host_start_command: cmd=51 error=0x108
E (267389) sdmmc_cmd: sdmmc_card_init: send_scr (2) returned 0x108
E (267392) vfs_native: Failed to initialize SDcard: invalid response).
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 5] EIO
If I replace the card with a 16Gb philips, the message is a bit different as cmd=51 is replaced by cmd=10. These two values, 51 and 10 are constant if I re-run the command, each one associated with one of the card. 51 for the sandisk, 10 for the philips.

Does anybody know what this value mean? Can I assume that my mounting is correct and the process just stops at a specific point depending on the quality of the card, and that a "perfect" card might be able to finish the process? I only have got these 2 microsd card available at the moment, but I might try to find another one if it seems to be a possibility.

Thanks for all the messages that have already been posted, I am confident I will get to the point I can read my microsd card :)

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: SDcard in SPI mode using Loboris port?

Post by loboris » Sat Mar 24, 2018 5:28 pm

symac wrote:
Sat Mar 24, 2018 4:43 pm
The latest step gives me the following error :

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert str to int
If I remove the parameter "/sd" it's fine, any idea why (even if I don't think it's my main issue, I'd like to understand what is going wrong)?
uos.mountsd() does not expect a string argument as describe in the Wiki.
SD Card is always mounted on /sd.
The only argument (optional) that can be accepted is True or False.
If True is given, directory is changed to /sd after successful mount.

If you get the error in uos.mountsd(), it means the communication with sdcard is unsuccessful or it cannot be properly initialized for the requested mode.

User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

Re: SDcard in SPI mode using Loboris port?

Post by liudr » Sat Mar 24, 2018 9:11 pm

May I ask for the reason of pullup resistors on all SPI pins? I read some other sources online that have pins pulled to a well-defined state is good in general and when there is no sd card or when booting up. I tried to find sd specifications but didn't find the right files for physical specifications.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: SDcard in SPI mode using Loboris port?

Post by OutoftheBOTS_ » Sat Mar 24, 2018 9:32 pm

I have edited my prevoius post to correct the os.mountsd(True) so other following the post will get correct info.

I made a typo when typing in code into the repl so had to retype 1 line of code so when I cut and paste to post here I cut around the typo but also mistakenly cut out os.chdir("/sd") that I used so I edited my post and instead of added the line I just changed the os.mountsd() but didn't realize when changing directory during mounting you don't specify the directory but rather pass True.

I did just make a 2 minute video of me doing the whole process for other to see it working properly https://youtu.be/y_rFSaA5XeQ

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: SDcard in SPI mode using Loboris port?

Post by loboris » Sat Mar 24, 2018 9:38 pm

liudr wrote:
Sat Mar 24, 2018 9:11 pm
I tried to find sd specifications but didn't find the right files for physical specifications.
SD Specifications: Physical Layer Simplified Specification Ver6.00

symac
Posts: 11
Joined: Thu Jan 04, 2018 2:01 pm

Re: SDcard in SPI mode using Loboris port?

Post by symac » Sun Mar 25, 2018 8:06 am

OutoftheBOTS_ wrote:
Sat Mar 24, 2018 9:32 pm
I have edited my prevoius post to correct the os.mountsd(True) so other following the post will get correct info.
Thanks for the explanation, I was thinking that I had read it without being woken up as I didn't understand where I had copied this line from :)
OutoftheBOTS_ wrote:
Sat Mar 24, 2018 9:32 pm
I did just make a 2 minute video of me doing the whole process for other to see it working properly https://youtu.be/y_rFSaA5XeQ
Thanks for the video, really seems to be exactly what I am doing, so I definitely suspect a microsd card error because of this cmd=51 / cmd=10 that depends on the card used. I am going to try today to go back to 1-line mode and see if anything changes, otherwise, I will try to get some sandisk micro sd cards as suggested by Loboris.

symac
Posts: 11
Joined: Thu Jan 04, 2018 2:01 pm

Re: SDcard in SPI mode using Loboris port?

Post by symac » Thu Mar 29, 2018 8:57 pm

I am continuing trying this. With two new microsd cards :
- A Sandisk 2go (from a blackberry smartphone), freshly formatted Fat32, I get the same error message than previously with the cmd=51 error code :

Code: Select all

E (69025) sdspi_host: sdspi_host_start_command: cmd=51 error=0x108
E (69026) sdmmc_cmd: sdmmc_card_init: send_scr (2) returned 0x108
E (69029) vfs_native: Failed to initialize SDcard: invalid response).
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 5] EIO
- A Sandisk 16Go bought yesterday and Fat32 formatted, I get another error message :

Code: Select all

E (84436) sdmmc_cmd: sdmmc_card_init: send_if_cond (1) returned 0x108
E (84437) vfs_native: Failed to initialize SDcard: invalid response).
I have tried a bit using the 1-SD mode but I can't get more positive result. Will be away from computer for 2 weeks, leaving that extra information here in case someone has some clue. Otherwise, I will give a try to @liudr's solution now that I have an extra SD/MicroSD basic card adapter that came with the 16Gb card I bought yesterday, because I'd like to skip the "reading from a microsd card" step to go further with my micropython's experiments :)

S.

User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

Re: SDcard in SPI mode using Loboris port?

Post by liudr » Sat Jul 28, 2018 5:24 pm

I hope OP found how to run the SD card by now. It's both funny and sad that I am running into the same problem now with my own prototype. In hoping to test the sd card, I had to use the dev board in the photo I posted on this thread (couldn't remember how I wired it without this photo). Took me a while to find this thread and the photo. Card works on the dev board but not my own design board :?

Post Reply