Questions about the SD file system

Hello Zerynth.
I’m trying to work with the file system on the SD card. It is connected via a MicroSD card adapter to my ESP32 Devkit v1.
In the Zerynth example program (Zerynth Studio r2.3.0-base):
fatfs.mount (‘0:’, {“drv”: SPI0, “cs”: D5, “clock”: 1000000}) are working fine.

ww = (‘0: zerynth.txt’, ‘w +’) gives an error
Thread 1 exited with exception OSError @ [007B: 0093: 0000: 0000: 0000: 0000: 0000: 0000].
I used different cards: 1GB Micro SD and 4GB Micro SD HC (FAT32), but the result is the same.
How to overcome this situation?
I have questions about mounting options, but ask them later.

Good, I will continue.
When calling the fatfs.mount function the clock parameter I simply consider 1000000 to be constant.
The cs parameter also does not cause me any questions.
But what values ​​the drv parameter can take is not clear to me. It is clear only that these values ​​are not arbitrary. Then what?

Are you trying the file system example?
Are you sure about the hardware connections?

Regarding the drv, drv parameter sets a certain SPI driver for the SD card.
so if the board have 2 SPI drivers, We can use SPI0,SPI1



And when to use SPI0, when to use SPI1?
What do these numbers mean: 0 or 1?
And if I use only one SD card?

For example, You can use an SPI0 for the SD card and SPI1 for another sensor/device.
You can choose either of them for the SD card, and the other for any other task that needs SPI, if there are any.

Does the numbering order matter or can these numbers be assigned in random order?
What is the meaning of the numbers in the labels of the SPI?

They can be assigned in any order.
The numbers act as a handler for the different SPI drivers available with each board.

All the errors with the SD card, I can explain primarily the incorrect numbering of contacts. :expressionless:
According to the documentation for my ESP32 Devkit v1 module, I connect:
CS - D5 (I specify it in the mount, parameter “cs”)
SCK - D18
MOSI - D23
MISO - D19
And how does Zerynth interpret this for the ESP32 Devkit v1 module?
In the documentation Zerynth I see only a common pinout. No indication of lines of SPI, I2C, …

It is strange that only one of me does not work.
I checked the voltage on the contacts of the card reader.
I checked the card reader with an SD card on another ESP8266 device.
I checked my ESP32 contact D5 in the Buzzer_with_PWM example.
Everything is good.
But any examples for SD cards using SPI do not work on my ESP32.

Hello @TakOtOg,

if you click, inside Zerynth Studio, on the Device Pinmap button


and then switch to the Peripheral view (bottom-left blue button), you are able to see the number of the SPI peripheral you are connecting your SD card to.
Let me know :slight_smile:

Very good, but I do not see CS pin there. How to specify it?

Hello @TakOtOg,

you can choose any pin as CS

CS - D5 (I specify it in the mount, parameter “cs”)
SCK - D18
MOSI - D23
MISO - D19
I already gave my connection scheme and it does not work,:smirk: although everything is assigned according to Device Pinmap.
How to be?

Have you replaced SPI0 with SPI1 in fatfs.mount (‘0:’, {“drv”: SPI0, “cs”: D5, “clock”: 1000000})?

Yes, I tried and SPI0 and SPI1 and different contacts on the board. Because ESP32 has 2 SPI lines

Most likely I am doing something wrong, but what?
Perhaps the diagnosis of the error will give something, but what and where to look?
Here are the crash strings in the console:

E (19136) sdmmc_sd: sdmmc_init_sd_if_cond: send_if_cond (1) returned 0x108
Thread 1 exited with exception OSError @ [007B: 0093: 0000: 0000: 0000: 0000: 0000: 0000]
ets Jun 8 2016 00:22:57
rst: 0xc (SW_CPU_RESET), boot: 0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP: 0xee
clk_drv: 0x00, q_drv: 0x00, d_drv: 0x00, cs0_drv: 0x00, hd_drv: 0x00, wp_drv: 0x00
mode: DIO, clock div: 2
load: 0x3fff0018, len: 4
load: 0x3fff001c, len: 3648
ho 0 tail 12 room 4
load: 0x40078000, len: 9928
ho 0 tail 12 room 4
load: 0x40080400, len: 5788
entry 0x400806c0
E (43) boot: OTA: 0/0 0/0 0/1
E (43) boot: Starting vm 0

What are they talking about?
Where generally to look for any error codes with decoding?

This is an interesting situation.
The Zerynth team cannot or does not want to answer the natural question about the methods of diagnosing its product. :smirk:
Or is my question too naive and should I know from my birth?

Hello @TakOtOg,

Zerynth Filesystem support is based on FatFS project, and for the hardware interface (for ESP32 boards) we directly call ESP-IDF functions.
The error you see (E (19136) sdmmc_sd: sdmmc_init_sd_if_cond: send_if_cond (1) returned 0x108) is actually coming directly from the Espressif software layer.
Since we are not able to reproduce this error on our side, I would suggest to try a simple Spi SD example using the ESP-IDF to check if your setup is ok.

Let me know :slight_smile:

Here is the same sad situation.
And what are my settings,
only in the correct connection of the SPI contacts?