SPI SD Card - Make File System Crashing

1. My goal is: Make a file system on a sd card in a reader connected via SPI bus, and then mount, and read files

2. My actions are:

Connected SD card creader via SPI pin out:

CS → gpio5
SCK → gpio18
MOSI → gpio23
MISO → gpio19
GND → GND
VCC → 3.3V

Empty App and added following to mos.yml:

config_schema:

  • [“app”, “o”, {title: “My application”}]
  • [“spi.enable”, true]
  • [“sys.esp32_adc_vref”, 3300] # ADC Vref is 3.3V
  • [“spi.mosi_gpio”, 23]
  • [“spi.miso_gpio”, 19]
  • [“spi.sclk_gpio”, 18]
  • [“spi.freq”, 20000000]
  • [“spi.cs0_gpio”, 5] # VFS Flash

libs:

build_vars:
MGOS_ENABLE_SPI_GPIO: 1 # for SPI flash

Build, and flash app. Then use RPC to call:

mos call FS.Mkfs ‘{“dev_type”: “spi_flash”, “dev_opts”: “{"freq": 20000000, "cs": 0}”, “fs_type”: “SPIFFS”, “fs_opts”: “{"size": 1000}”}’

3. The result I see is:

On bootup:

mgos_spi_gpioo.c:72 SPI GPIO init ok (MISO:19, MOSI: 23, SCLK:18; CS0/1/2: 5/0/0)

When running the command:

Error: Context deadline exceeded

Then mongoose OS crashes and reboots

4. My expectation & question is: What am I missing to make this work?

AFAIK, you can’t handle a SD card as a flash memory.

You might want to use my sdlib. There is also a test-sdlib application.

1 Like

Gosh that was a silly mistake, sorry!

I’m now attempting to use your library within my application however I am having issues with the CS pin.

I’ve tried with gpio5 and gpio15, but I still get errors when trying to initalise the SD card.

I get Error 264 ESP_ERR_INVALID_RESPONSE and a message about making sure I am using pull-up resistors

On the gpio pin I use for CS I get OutputEn: 1 and Pullup: 0
Where as on the other pins it seems to be correct Pullup: 1

You need to define the pins used by the library

Sorry I forgot to mention that I have edited the pin defintions in the mos.yml, to the pins setout in the first post and then updated when trying gpio5 and 15

I’ve tried with gpio22 and gpio25 now for the CS pin, and every time it’s the same.

What does OutputEn: 1 mean? Do I need to specify the pin mode anywhere or is the config in mos.yml enough?

Could my SD card reader be broken?

I’ve checked the schematic diagram of the modules I use, and found that they have a 10k resistor connected to 3.3V on the MISO, MOSI, SCK and CS lines.

Your library, code, and attached PDF are seem to be specific to a discontinued development board.

I was using a ESP32 with a seperately attached SD Card reader, I then moved onto another ESP32 board I own: Olimex EVB

I was able to sort my problem on my own with the help of some example code from the specific board I am using.

I have similar board and trying to make it work

Did you try the c file I attached from the Olimex repo?

Can it be part of app for mongoose os? I have no idea how to integrate it to my app

Ok. I tried the code above. It woks!. Now I can read and write files. And open created files on my PC.
May be nliviu’s library not work with my board…:thinking:

Olimex EVB sd/mmc interface uses 1 line mode which is not handled by my library yet.
I’ll add a cflag for it.

1 Like

That’s good to hear, I wonder how far away this library is from general use. At the moment it seems to only work for a couple of specific boards.

It has been used by several people with different boards and sd card modules without problems.

I work with Olimex board too.

It would be great that you library support this types of olimex boards

@nliviu that’s positive, but I’d argue that it’s not ready for general use if it’s not working with popular boards.

1 Like