I have these declaration at the beginning of my code
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "sdmmc_cmd.h"
#include "esp_vfs_fat.h"
#include "driver/sdmmc_host.h"
#include "driver/sdspi_host.h"
#include "driver/sdmmc_types.h"
#include "esp_err.h"
#include "hal/spi_types.h"
#include "driver/spi_common.h"
#include "driver/spi_master.h"
#include "driver/gpio.h"
#define PIN_MISO 12
#define PIN_MOSI 13
#define PIN_SCK 14
#define PIN_CS 15
#define MAX_CHAR_SIZE 100
#define TAG "SD_CARD"
#define TARJETA_SD "/sdcard"
esp_err_t initSD();
and sd funtion
Code: Select all
esp_err_t initSD(){
sdmmc_card_t* card;
esp_err_t ret;
esp_vfs_fat_sdmmc_mount_config_t mount_conf = {
.format_if_mount_failed = false,
.max_files = 5,
.allocation_unit_size = 16 * 1024
};
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
spi_bus_config_t buscfg = {
.miso_io_num = PIN_MISO,
.mosi_io_num = PIN_MOSI,
.sclk_io_num = PIN_SCK,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 4096
};
ret = spi_bus_initialize(host.slot, &buscfg, SDSPI_DEFAULT_DMA);
if (ret != ESP_OK) {
printf("\nERROR SPI BUS\n");
return ret;
}
sdspi_device_config_t slot_config = {
.host_id = host.slot,
.gpio_cs = PIN_CS,
.gpio_cd = -1,
.gpio_wp = -1,
.gpio_int = -1,
};
ret = esp_vfs_fat_sdspi_mount("/sdcard", &host, &slot_config, &mount_conf, &card);
if(ret != ESP_OK){
if(ret == ESP_FAIL){
printf("\nESP_FAIL ERROR: 0x%x\n", ret);
}
else
{
printf("\nERROR ret: 0x%x\n", ret);
}
return ESP_FAIL;
}
sdmmc_card_print_info(stdout, card);
return ESP_OK;
}
I am using the wokwi simulator, I don't know if it is a problem with the simulator or something is wrong with me, I get these errors:
Code: Select all
rst:0x1 (POWERON_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:0x3fff0030,len:1156
load:0x40078000,len:11456
ho 0 tail 12 room 4
load:0x40080400,len:2972
entry 0x400805dc
[0;31mE (876) sdmmc_sd: sdmmc_init_sd_if_cond: send_if_cond (1) returned 0x108[0m
[0;31mE (876) vfs_fat_sdmmc: sdmmc_card_init failed (0x108).[0m
ERROR ret: 0x108
>Failed to boot sd<
Failed to open file for writing
Error file create
Failed to open file for reading
Error read
I used to have a project similar to this that did work but I don't know if it's a problem now because of wokwi or if I need to change something.
In espressif the error 0x108 is: ESP_ERR_INVALID_RESPONSE (0x108): Received response was invalid