StevenMHernandez / ESP32-CSI-Tool

Extract Channel State Information from WiFi-enabled ESP32 Microcontroller. Active and Passive modes available. (https://stevenmhernandez.github.io/ESP32-CSI-Tool/)
https://stevenmhernandez.github.io/ESP32-CSI-Tool/
MIT License
262 stars 72 forks source link

E (748) vfs_fat_sdmmc: slot init failed (0x103). #74

Open Sunlu2333 opened 1 year ago

Sunlu2333 commented 1 year ago

Describe the bug E (748) vfs_fat_sdmmc: slot init failed (0x103). E (749) sd.h: Failed to initialize the card (ESP_ERR_INVALID_STATE). If you do not have an SD card attached, please ignore this message. Make sure SD card lines have pull-up resistors in place.

Tool Settings

To Reproduce Steps to reproduce the behavior:

  1. Build project(s) active_ap, active_sta
  2. Flash project(s) active_ap, active_sta
  3. External device setup AP/STA: ESP32-WROVER-IE Sandisk Micro SDHC 32G

微信图片_20221116151458

  1. See error

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

Sunlu2333 commented 1 year ago

According to the example 'sdspi' provided by esp-idf, I modified the code. But I encountered a new problem. I can initialize and write a single file, but I cannot write the obtained CSI data into csv file. image

Can you share the specific idea of obtaining CSI output to SD card in real time?

Sunlu2333 commented 1 year ago

My code is as follows:

ifndef ESP32_CSI_SD_COMPONENT_H

define ESP32_CSI_SD_COMPONENT_H

include

include

include <sys/unistd.h>

include <sys/stat.h>

include "esp_err.h"

include "esp_log.h"

include "esp_vfs_fat.h"

include "driver/sdspi_host.h"

include "driver/sdmmc_host.h"

include "driver/spi_common.h"

include "sdmmc_cmd.h"

include "sdkconfig.h"

define MOUNT_POINT "/sdcard"

define PIN_NUM_MISO 19

define PIN_NUM_MOSI 23

define PIN_NUM_CLK 18

define PIN_NUM_CS 5

//#define PIN_NUM_MISO 2 //#define PIN_NUM_MOSI 15 //#define PIN_NUM_CLK 14 //#define PIN_NUM_CS 13

FILE *f; char filename[24] = {0};

void _sd_pick_next_file() { int i = -1; struct stat st; while (true) { i++; printf("Checking %i.csv\n", i); sprintf(filename, "/sdcard/%i.csv", i);

    if (stat(filename, &st) != 0) {
        break;
    }

    printf("File size: %li\n", st.st_size);
}

}

void sd_init() {

ifdef CONFIG_SEND_CSI_TO_SD

esp_err_t ret;

esp_vfs_fat_sdmmc_mount_config_t mount_config = {
    .format_if_mount_failed = false,
    .max_files = 1,
    .allocation_unit_size = 16 * 1024
};

sdmmc_card_t *card;
const char mount_point[] = MOUNT_POINT;

//ESP_LOGI("sd.h","Initializing SD card");
ESP_LOGI("sd.h", "Using SPI peripheral");

sdmmc_host_t host = SDSPI_HOST_DEFAULT();
host.max_freq_khz = 10000;   //

spi_bus_config_t bus_cfg = {
    .mosi_io_num = PIN_NUM_MOSI,
.miso_io_num = PIN_NUM_MISO,
.sclk_io_num = PIN_NUM_CLK,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 4000,
};

// SPI总线初始化
//ret = spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CH2);
ret = spi_bus_initialize(SPI3_HOST, &bus_cfg, SPI_DMA_CH1);
if (ret != ESP_OK) {
ESP_LOGE("sd.h","Failed to initialize bus.");
return;
}

// 这将初始化没有卡检测(CD)和写保护(WP)信号的插槽。
// 如果您的主板有这些信号,请修改slot_config.gpio_cd和slot_config.gpio_wp。
sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
slot_config.gpio_cs = (gpio_num_t) PIN_NUM_CS;
slot_config.host_id = SPI3_HOST;

// 挂载文件系统
ret = esp_vfs_fat_sdspi_mount(mount_point, &host, &slot_config, &mount_config, &card);

if (ret != ESP_OK) {
    if (ret == ESP_FAIL) {
    ESP_LOGE("sd.h",
            "Failed to mount filesystem."
    "If you want the card to be formatted, set the EXAMPLE_FORMAT_IF_MOUNT_FAILED menuconfig option.");
} else {
    ESP_LOGE("sd.h",
            "Failed to initialize the card(%s)."
        "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret));
}
return;
} else{
    sdmmc_card_print_info(stdout, card);

_sd_pick_next_file();
f = fopen(filename, "a");
}  

// 卸载分区并禁用SDMMC或SPI外设
//esp_vfs_fat_sdcard_unmount(mount_point, card);
//卸载总线
//spi_bus_free(host.slot);

endif

}

/*

ifdef CONFIG_SEND_CSI_TO_SERIAL

vprintf(format, args);

endif

ifdef CONFIG_SEND_CSI_TO_SD

if (f != NULL) {
    vfprintf(f, format, args);
}

endif

va_end(args);

}

void sd_flush() {

ifdef CONFIG_SEND_CSI_TO_SD

fflush(f);
fclose(f);
f = fopen(filename, "a");

endif

}

endif //ESP32_CSI_SD_COMPONENT_H

Sunlu2333 commented 1 year ago

Another point that puzzles me is that when I set up to collect CSI only through the SD card, I still seem to be able to collect CSI from the serial port. image image