Open Sunlu2333 opened 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.
Can you share the specific idea of obtaining CSI output to SD card in real time?
My code is as follows:
//#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() {
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);
}
/*
vprintf(format, args);
if (f != NULL) {
vfprintf(f, format, args);
}
va_end(args);
}
void sd_flush() {
fflush(f);
fclose(f);
f = fopen(filename, "a");
}
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.
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:
Desktop (please complete the following information):
Additional context Add any other context about the problem here.