SD卡SDIO初始化问题
-
13302657252
- Posts: 17
- Joined: Thu Jun 01, 2023 10:58 am
SD卡SDIO初始化问题
遇到个奇怪的问题,使用SD卡 SDIO方式实现了SD卡读写卡,只能使用D0 1位方式,这个都可以,但是上电初始化在以下方式才会成功:
1:上电后马上拔掉再插电,就可以每次初始SD成功
2:焊接加热后,也可以头几次初始化成功,冷却后就不行了。
其他情况就不行,这个怎样搞,换了卡座,使用了ESP-IDF最高版本,我换了引脚都一样。我使用的是ESP32S3.网上说spi方式可以,但是我的spi用光了,只能用SDIO方式,请问有没有解决办法?
1:上电后马上拔掉再插电,就可以每次初始SD成功
2:焊接加热后,也可以头几次初始化成功,冷却后就不行了。
其他情况就不行,这个怎样搞,换了卡座,使用了ESP-IDF最高版本,我换了引脚都一样。我使用的是ESP32S3.网上说spi方式可以,但是我的spi用光了,只能用SDIO方式,请问有没有解决办法?
Re: SD卡SDIO初始化问题
Hi @13302657252 ,
could you please switch Verbose logging on and share the logs here? Although it sounds like a hardware trouble, it may be helpful to see what's going on in the code
could you please switch Verbose logging on and share the logs here? Although it sounds like a hardware trouble, it may be helpful to see what's going on in the code
-
13302657252
- Posts: 17
- Joined: Thu Jun 01, 2023 10:58 am
Re: SD卡SDIO初始化问题
谢谢你的答复,我设置成logoutput 为verbose编译后试了很多次没有SDcard初始化错误,把logoutput设成debug,information就有这种错误,我把verbose的log,debug的log,放到附件,代码用的时sdmmc例子代码。
Code: Select all
/* 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.
*/
// This example uses SDMMC peripheral to communicate with SD card.
#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "driver/sdmmc_host.h"
static const char *TAG = "example";
//SDMMC_FREQ_HIGHSPEED
#define MOUNT_POINT "/sdcard"
#define SDMMC_HOST_DEFAULT1() {\
.flags = SDMMC_HOST_FLAG_8BIT | \
SDMMC_HOST_FLAG_4BIT | \
SDMMC_HOST_FLAG_1BIT | \
SDMMC_HOST_FLAG_DDR, \
.slot = SDMMC_HOST_SLOT_0, \
.max_freq_khz = 20000, \
.io_voltage = 3.3f, \
.init = &sdmmc_host_init, \
.set_bus_width = &sdmmc_host_set_bus_width, \
.get_bus_width = &sdmmc_host_get_slot_width, \
.set_bus_ddr_mode = &sdmmc_host_set_bus_ddr_mode, \
.set_card_clk = &sdmmc_host_set_card_clk, \
.do_transaction = &sdmmc_host_do_transaction, \
.deinit = &sdmmc_host_deinit, \
.io_int_enable = sdmmc_host_io_int_enable, \
.io_int_wait = sdmmc_host_io_int_wait, \
.command_timeout_ms = 0, \
}
void app_main(void)
{
// gpio_config_t io_conf;
// io_conf.intr_type = GPIO_INTR_DISABLE;
// io_conf.mode = GPIO_MODE_INPUT;
// io_conf.pin_bit_mask = 1ULL<<35;
// io_conf.pull_down_en = 0;
// io_conf.pull_up_en = 1;
// gpio_config(&io_conf);
// io_conf.intr_type = GPIO_INTR_DISABLE;
// io_conf.mode = GPIO_MODE_INPUT;
// io_conf.pin_bit_mask = 1ULL<<47;
// io_conf.pull_down_en = 0;
// io_conf.pull_up_en = 1;
// gpio_config(&io_conf);
esp_err_t ret;
// Options for mounting the filesystem.
// If format_if_mount_failed is set to true, SD card will be partitioned and
// formatted in case when mounting fails.
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
#ifdef CONFIG_EXAMPLE_FORMAT_IF_MOUNT_FAILED
.format_if_mount_failed = true,
#else
.format_if_mount_failed = false,
#endif // EXAMPLE_FORMAT_IF_MOUNT_FAILED
.max_files = 5,
.allocation_unit_size = 16 * 1024
};
sdmmc_card_t *card;
const char mount_point[] = MOUNT_POINT;
ESP_LOGI(TAG, "Initializing SD card");
// Use settings defined above to initialize SD card and mount FAT filesystem.
// Note: esp_vfs_fat_sdmmc/sdspi_mount is all-in-one convenience functions.
// Please check its source code and implement error recovery when developing
// production applications.
ESP_LOGI(TAG, "Using SDMMC peripheral");
sdmmc_host_t host = SDMMC_HOST_DEFAULT1();
// This initializes the slot without card detect (CD) and write protect (WP) signals.
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
// Set bus width to use:
#ifdef CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
slot_config.width = 4;
#else
slot_config.width = 1;
#endif
// On chips where the GPIOs used for SD card can be configured, set them in
// the slot_config structure:
#ifdef CONFIG_IDF_TARGET_ESP32S3
slot_config.clk = CONFIG_EXAMPLE_PIN_CLK; //48;
slot_config.cmd = CONFIG_EXAMPLE_PIN_CMD; //35; //CONFIG_EXAMPLE_PIN_CMD;
slot_config.d0 = CONFIG_EXAMPLE_PIN_D0; //47;
slot_config.d1 = -1;
slot_config.d2 =-1;
slot_config.d3 = -1;
#ifdef CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
slot_config.d1 = CONFIG_EXAMPLE_PIN_D1;
slot_config.d2 = CONFIG_EXAMPLE_PIN_D2;
slot_config.d3 = CONFIG_EXAMPLE_PIN_D3;
#endif // CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
#endif // CONFIG_IDF_TARGET_ESP32S3
// Enable internal pullups on enabled pins. The internal pullups
// are insufficient however, please make sure 10k external pullups are
// connected on the bus. This is for debug / example purpose only.
slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
ESP_LOGI(TAG, "Mounting filesystem");
ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card);
if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount filesystem. "
"If you want the card to be formatted, set the EXAMPLE_FORMAT_IF_MOUNT_FAILED menuconfig option.");
} else {
ESP_LOGE(TAG, "Failed to initialize the card (%s). "
"Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret));
}
return;
}
ESP_LOGI(TAG, "Filesystem mounted");
// Card has been initialized, print its properties
sdmmc_card_print_info(stdout, card);
// Use POSIX and C standard library functions to work with files:
// First create a file.
const char *file_hello = MOUNT_POINT"/hello.txt";
ESP_LOGI(TAG, "Opening file %s", file_hello);
FILE *f = fopen(file_hello, "w");
if (f == NULL) {
ESP_LOGE(TAG, "Failed to open file for writing");
return;
}
fprintf(f, "Hello %s!\n", card->cid.name);
fclose(f);
ESP_LOGI(TAG, "File written");
const char *file_foo = MOUNT_POINT"/foo.txt";
// Check if destination file exists before renaming
struct stat st;
if (stat(file_foo, &st) == 0) {
// Delete it if it exists
unlink(file_foo);
}
// Rename original file
ESP_LOGI(TAG, "Renaming file %s to %s", file_hello, file_foo);
if (rename(file_hello, file_foo) != 0) {
ESP_LOGE(TAG, "Rename failed");
return;
}
// Open renamed file for reading
ESP_LOGI(TAG, "Reading file %s", file_foo);
f = fopen(file_foo, "r");
if (f == NULL) {
ESP_LOGE(TAG, "Failed to open file for reading");
return;
}
// Read a line from file
char line[64];
fgets(line, sizeof(line), f);
fclose(f);
// Strip newline
char *pos = strchr(line, '\n');
if (pos) {
*pos = '\0';
}
ESP_LOGI(TAG, "Read from file: '%s'", line);
// All done, unmount partition and disable SDMMC peripheral
esp_vfs_fat_sdcard_unmount(mount_point, card);
ESP_LOGI(TAG, "Card unmounted");
}
- Attachments
-
- LOGOUTPUT=VERBOSE_correct.txt
- (71.88 KiB) Downloaded 13 times
-
- LOGOUTPUT=DEBUG_error.txt
- (9.19 KiB) Downloaded 13 times
-
13302657252
- Posts: 17
- Joined: Thu Jun 01, 2023 10:58 am
-
ESP_rrtandler
- Posts: 52
- Joined: Wed May 31, 2023 6:54 pm
Re: SD卡SDIO初始化问题
Hi @13302657252 ,
The "2. After soldering and heating, initialization succeeds the first few times, but fails after cooling." suggests some problem related to the reliability of the physical wiring rather than software issue.
Could you please clarify:
1. Whether you have only single prototype circuit or work with multiple prototype devices.
2. If you have multiple ones, does the same issue appear on all of them or only on single one ?
3. If you have only one prototype, please clarify which part of the circuit are you soldering and heating ?
The "2. After soldering and heating, initialization succeeds the first few times, but fails after cooling." suggests some problem related to the reliability of the physical wiring rather than software issue.
Could you please clarify:
1. Whether you have only single prototype circuit or work with multiple prototype devices.
2. If you have multiple ones, does the same issue appear on all of them or only on single one ?
3. If you have only one prototype, please clarify which part of the circuit are you soldering and heating ?
-
13302657252
- Posts: 17
- Joined: Thu Jun 01, 2023 10:58 am
Re: SD卡SDIO初始化问题
Hi, my reply :
Could you please clarify:
1. Whether you have only single prototype circuit or work with multiple prototype devices.
Reply: work with all boards with same issue.
2. If you have multiple ones, does the same issue appear on all of them or only on single one ?
Reply:same issue appear on all of them
3. If you have only one prototype, please clarify which part of the circuit are you soldering and heating ?
Reply:solder the pullup resistors or bypass cap connected to power pin of sd card
我在上个回复了一个新现象,因为上1个人要我抓verbose的log, 发现了这个现象。如果我在menuconfig中配置log output为verbose,那么就没有问题,反正反复试了很多次都没有问题,如果改其他如info,debug,等等选项就会出现sd卡初始化失败的现象。没有抓到verbose错误的log,把info的SD卡错误是的log附上了。
期待你们的进一步回答。
Could you please clarify:
1. Whether you have only single prototype circuit or work with multiple prototype devices.
Reply: work with all boards with same issue.
2. If you have multiple ones, does the same issue appear on all of them or only on single one ?
Reply:same issue appear on all of them
3. If you have only one prototype, please clarify which part of the circuit are you soldering and heating ?
Reply:solder the pullup resistors or bypass cap connected to power pin of sd card
我在上个回复了一个新现象,因为上1个人要我抓verbose的log, 发现了这个现象。如果我在menuconfig中配置log output为verbose,那么就没有问题,反正反复试了很多次都没有问题,如果改其他如info,debug,等等选项就会出现sd卡初始化失败的现象。没有抓到verbose错误的log,把info的SD卡错误是的log附上了。
期待你们的进一步回答。
-
13302657252
- Posts: 17
- Joined: Thu Jun 01, 2023 10:58 am
-
ESP_rrtandler
- Posts: 52
- Joined: Wed May 31, 2023 6:54 pm
Re: SD卡SDIO初始化问题
Hi @13302657252 ,
Thanks for the answers to my questions. When I put everything together, the initialisation of the card works correctly if:
- Card is removed and inserted into the slot after reset of the chip
- The verbose log level is enabled.
- and the strange behavior related to the soldering (when the circuit is hot, warm), it initializes correctly, when cooled down, it. fails.
To me it looks like the the timing problem of the card reset. The verbose log level actually slows down all the calls and also gives the card some time to recover after reset. The error message from the failed init is:
E (1800) example: Failed to initialize the card (ESP_ERR_TIMEOUT). Make sure SD card lines have pull-up resistors in place.
Could you share schematic of your circuit, type of the ESP32 devkit and the version of IDF and example you want to run ?
Thanks for the answers to my questions. When I put everything together, the initialisation of the card works correctly if:
- Card is removed and inserted into the slot after reset of the chip
- The verbose log level is enabled.
- and the strange behavior related to the soldering (when the circuit is hot, warm), it initializes correctly, when cooled down, it. fails.
To me it looks like the the timing problem of the card reset. The verbose log level actually slows down all the calls and also gives the card some time to recover after reset. The error message from the failed init is:
E (1800) example: Failed to initialize the card (ESP_ERR_TIMEOUT). Make sure SD card lines have pull-up resistors in place.
Could you share schematic of your circuit, type of the ESP32 devkit and the version of IDF and example you want to run ?
-
13302657252
- Posts: 17
- Joined: Thu Jun 01, 2023 10:58 am
Re: SD卡SDIO初始化问题
@ESP_rrtandler
I attach the sch of pic , pcb of pic, code, the code is from exampel of esp-idf 4.5,5.1, i may send sch pcb original files to you pls give me email address.
I attach the sch of pic , pcb of pic, code, the code is from exampel of esp-idf 4.5,5.1, i may send sch pcb original files to you pls give me email address.
- Attachments
-
- 22.PNG (191.75 KiB) Viewed 1352 times
-
- 333.PNG (165.14 KiB) Viewed 1352 times
Who is online
Users browsing this forum: PetalBot and 3 guests
