Oliver
October 11, 2019, 9:21am
1
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?
nliviu
October 11, 2019, 10:39am
2
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
Oliver
October 11, 2019, 11:30am
3
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
nliviu
October 11, 2019, 11:37am
4
You need to define the pins used by the library
Oliver
October 11, 2019, 11:47am
5
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
Oliver
October 11, 2019, 12:02pm
6
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?
nliviu
October 11, 2019, 12:47pm
7
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.
Oliver
October 11, 2019, 3:19pm
8
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.
/* SD card and FAT filesystem example.
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include "esp_err.h"
#include "esp_log.h"
#include "esp_vfs_fat.h"
#include "driver/sdmmc_host.h"
#include "driver/sdmmc_defs.h"
#include "sdmmc_cmd.h"
static const char* TAG = "example";
This file has been truncated. show original
Oliver:
Olimex EVB
I have similar board and trying to make it work
Oliver
October 16, 2019, 4:11pm
10
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…
nliviu
October 17, 2019, 8:58am
13
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
Oliver
October 17, 2019, 10:02am
14
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.
nliviu
October 17, 2019, 11:29am
15
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
Oliver
October 17, 2019, 12:48pm
18
@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