实现ESP32-WROVER-IE写入数据到SD卡中时无法初始化sd卡(idf 4.4)

Songluu
Posts: 5
Joined: Fri Nov 04, 2022 4:26 am

实现ESP32-WROVER-IE写入数据到SD卡中时无法初始化sd卡(idf 4.4)

Postby Songluu » Wed Nov 16, 2022 8:44 am

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:6676
load:0x40078000,len:14848
ho 0 tail 12 room 4
load:0x40080400,len:3792
0x40080400: _init at ??:?

entry 0x40080694
I (29) boot: ESP-IDF v4.4.1-405-g6c5fb29c2c 2nd stage bootloader
I (29) boot: compile time 20:27:28
I (29) boot: chip revision: 3
I (33) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (40) boot.esp32: SPI Speed : 40MHz
I (45) boot.esp32: SPI Mode : DIO
I (50) boot.esp32: SPI Flash Size : 2MB
I (54) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (63) boot: ## Label Usage Type ST Offset Length
I (70) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (78) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (85) boot: 2 factory factory app 00 00 00010000 00100000
I (93) boot: End of partition table
I (97) boot_comm: chip revision: 3, min. application chip revision: 0
I (104) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=293c4h (168900) map
I (174) esp_image: segment 1: paddr=000393ec vaddr=3ffb0000 size=03a1ch ( 14876) load
I (180) esp_image: segment 2: paddr=0003ce10 vaddr=40080000 size=03208h ( 12808) load
I (185) esp_image: segment 3: paddr=00040020 vaddr=400d0020 size=a31b4h (668084) map
I (430) esp_image: segment 4: paddr=000e31dc vaddr=40083208 size=12c4ch ( 76876) load
I (462) esp_image: segment 5: paddr=000f5e30 vaddr=50000000 size=00010h ( 16) load
I (473) boot: Loaded app from partition at offset 0x10000
I (473) boot: Disabling RNG early entropy source...
I (484) cpu_start: Pro cpu up.
I (485) cpu_start: Starting app cpu, entry point is 0x4008137c
0x4008137c: call_start_cpu1 at /home/ssr-zenan/esp/esp-idf/components/esp_system/port/cpu_start.c:160

I (0) cpu_start: App cpu up.
I (501) cpu_start: Pro cpu start user code
I (501) cpu_start: cpu freq: 160000000
I (501) cpu_start: Application information:
I (505) cpu_start: Project name: active-ap
I (510) cpu_start: App version: 1
I (515) cpu_start: Compile time: Nov 16 2022 14:16:40
I (521) cpu_start: ELF file SHA256: 3bf09510a1c68176...
I (527) cpu_start: ESP-IDF: v4.4.1-405-g6c5fb29c2c
I (533) heap_init: Initializing. RAM available for dynamic allocation:
I (540) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (546) heap_init: At 3FFB8DC8 len 00027238 (156 KiB): DRAM
I (553) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (559) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (565) heap_init: At 40095E54 len 0000A1AC (40 KiB): IRAM
I (573) spi_flash: detected chip: generic
I (576) spi_flash: flash io: dio
W (580) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (598) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.








-----------------------
ESP32 CSI Tool Settings
-----------------------
PROJECT_NAME: ACTIVE_AP
CONFIG_ESPTOOLPY_MONITOR_BAUD: 115200
CONFIG_ESP_CONSOLE_UART_BAUDRATE: 115200
IDF_VER: v4.4.1-405-g6c5fb29c2c
-----------------------
WIFI_CHANNEL: 4
ESP_WIFI_SSID: myssid
ESP_WIFI_PASSWORD: mypassword
SHOULD_COLLECT_CSI: 1
SHOULD_COLLECT_ONLY_LLTF: 1
SEND_CSI_TO_SERIAL: 1
SEND_CSI_TO_SD: 1
-----------------------








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.
I (765) wifi:wifi driver task: 3ffc1aa0, prio:23, stack:6656, core=0
I (768) system_api: Base MAC address is not set
I (772) system_api: read default base MAC address from EFUSE
I (787) wifi:wifi firmware version: 84ed08c
I (787) wifi:wifi certification version: v7.0
I (787) wifi:config NVS flash: enabled
I (790) wifi:config nano formating: disabled
I (795) wifi:Init data frame dynamic rx buffer num: 32
I (799) wifi:Init management frame dynamic rx buffer num: 32
I (805) wifi:Init management short buffer num: 32
I (809) wifi:Init dynamic tx buffer num: 32
I (813) wifi:Init static rx buffer size: 2212
I (817) wifi:Init static rx buffer num: 10
I (821) wifi:Init dynamic rx buffer num: 32
I (825) wifi_init: rx ba win: 6
I (828) wifi_init: tcpip mbox: 32
I (832) wifi_init: udp mbox: 6
I (836) wifi_init: tcp mbox: 6
I (840) wifi_init: tcp tx win: 5744
I (844) wifi_init: tcp rx win: 5744
I (848) wifi_init: tcp mss: 1440
I (852) wifi_init: WiFi IRAM OP enabled
I (857) wifi_init: WiFi RX IRAM OP enabled
I (868) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (980) wifi:mode : softAP (3c:e9:0e:10:1d:45)
I (984) wifi:Total power save buffer number: 16
I (985) wifi:Init max length of beacon: 752/752
I (986) wifi:Init max length of beacon: 752/752
I (989) wifi:Set ps type: 0

代码如下:

Code: Select all

#ifndef ESP32_CSI_SD_COMPONENT_H
#define ESP32_CSI_SD_COMPONENT_H

#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/sdspi_host.h"
#include "sdmmc_cmd.h"

#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
    sdmmc_host_t host = SDSPI_HOST_DEFAULT();
    sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
    slot_config.gpio_miso = (gpio_num_t) PIN_NUM_MISO;
    slot_config.gpio_mosi = (gpio_num_t) PIN_NUM_MOSI;
    slot_config.gpio_sck = (gpio_num_t) PIN_NUM_CLK;
    slot_config.gpio_cs = (gpio_num_t) PIN_NUM_CS;

    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;
    esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &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 format_if_mount_failed = true."
            );
        } else {
            ESP_LOGE("sd.h",
                     "Failed to initialize the card (%s). "
                     "  If you do not have an SD card attached, please ignore this message."
                     "  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");
    }
#endif
}

/*
 * Printf for both serial AND sd card (if available and configured)
 */
void outprintf(const char *format, ...) {
    va_list args;
    va_start(args, format);

#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

SD卡模块如下图,SD卡:Sandisk SDHC 32G
微信图片_20221116151458.jpg
微信图片_20221116151458.jpg (143.82 KiB) Viewed 1068 times

Who is online

Users browsing this forum: No registered users and 150 guests