diff --git a/components/driver/sdmmc/sdmmc_host.c b/components/driver/sdmmc/sdmmc_host.c index 158e4eded8..16e33cbf92 100644 --- a/components/driver/sdmmc/sdmmc_host.c +++ b/components/driver/sdmmc/sdmmc_host.c @@ -10,6 +10,7 @@ #include "esp_log.h" #include "esp_intr_alloc.h" #include "esp_timer.h" +#include "esp_check.h" #include "soc/soc_caps.h" #include "soc/soc_pins.h" #include "soc/gpio_periph.h" @@ -81,6 +82,7 @@ esp_err_t sdmmc_host_reset(void) if (esp_timer_get_time() - t0 > SDMMC_HOST_RESET_TIMEOUT_US) { return ESP_ERR_TIMEOUT; } + vTaskDelay(1); } return ESP_OK; @@ -189,11 +191,7 @@ static esp_err_t sdmmc_host_clock_update_command(int slot) bool repeat = true; while(repeat) { - esp_err_t err = sdmmc_host_start_command(slot, cmd_val, 0); - if (err != ESP_OK) { - ESP_LOGE(TAG, "sdmmc_host_start_command() failed"); - return err; - } + ESP_RETURN_ON_ERROR(sdmmc_host_start_command(slot, cmd_val, 0), TAG, "sdmmc_host_start_command returned 0x%x", err_rc_); int64_t t0 = esp_timer_get_time(); while (true) { @@ -215,6 +213,8 @@ static esp_err_t sdmmc_host_clock_update_command(int slot) repeat = false; break; } + + vTaskDelay(1); } } @@ -267,7 +267,8 @@ esp_err_t sdmmc_host_set_card_clk(int slot, uint32_t freq_khz) SDMMC.clkena.cclk_enable &= ~BIT(slot); esp_err_t err = sdmmc_host_clock_update_command(slot); if (err != ESP_OK) { - ESP_LOGE(TAG, "disable clk failed"); + ESP_LOGE(TAG, "disabling clk failed"); + ESP_LOGE(TAG, "%s: sdmmc_host_clock_update_command returned 0x%x", __func__, err); return err; } @@ -292,7 +293,8 @@ esp_err_t sdmmc_host_set_card_clk(int slot, uint32_t freq_khz) sdmmc_host_set_clk_div(host_div); err = sdmmc_host_clock_update_command(slot); if (err != ESP_OK) { - ESP_LOGE(TAG, "set clk div failed"); + ESP_LOGE(TAG, "setting clk div failed"); + ESP_LOGE(TAG, "%s: sdmmc_host_clock_update_command returned 0x%x", __func__, err); return err; } @@ -301,7 +303,8 @@ esp_err_t sdmmc_host_set_card_clk(int slot, uint32_t freq_khz) SDMMC.clkena.cclk_low_power |= BIT(slot); err = sdmmc_host_clock_update_command(slot); if (err != ESP_OK) { - ESP_LOGE(TAG, "re-enable clk failed"); + ESP_LOGE(TAG, "re-enabling clk failed"); + ESP_LOGE(TAG, "%s: sdmmc_host_clock_update_command returned 0x%x", __func__, err); return err; } @@ -352,6 +355,7 @@ esp_err_t sdmmc_host_start_command(int slot, sdmmc_hw_cmd_t cmd, uint32_t arg) { if (esp_timer_get_time() - t0 > SDMMC_HOST_START_CMD_TIMEOUT_US) { return ESP_ERR_TIMEOUT; } + vTaskDelay(1); } SDMMC.cmdarg = arg; cmd.card_num = slot; @@ -375,7 +379,7 @@ esp_err_t sdmmc_host_init(void) // Reset esp_err_t err = sdmmc_host_reset(); if (err != ESP_OK) { - ESP_LOGE(TAG, "sdmmc_host_reset() failed"); + ESP_LOGE(TAG, "%s: sdmmc_host_reset returned 0x%x", __func__, err); return err; } @@ -585,7 +589,8 @@ esp_err_t sdmmc_host_init_slot(int slot, const sdmmc_slot_config_t* slot_config) // By default, set probing frequency (400kHz) and 1-bit bus esp_err_t ret = sdmmc_host_set_card_clk(slot, 400); if (ret != ESP_OK) { - ESP_LOGE(TAG, "sdmmc_host_set_card_clk() 400kHz failed"); + ESP_LOGE(TAG, "setting probing freq and 1-bit bus failed"); + ESP_LOGE(TAG, "%s: sdmmc_host_set_card_clk returned 0x%x", __func__, ret); return ret; } ret = sdmmc_host_set_bus_width(slot, 1); diff --git a/components/fatfs/test_apps/sdcard/pytest_fatfs_sdcard.py b/components/fatfs/test_apps/sdcard/pytest_fatfs_sdcard.py index 4ec667dd14..61b97c4cf8 100644 --- a/components/fatfs/test_apps/sdcard/pytest_fatfs_sdcard.py +++ b/components/fatfs/test_apps/sdcard/pytest_fatfs_sdcard.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 import pytest @@ -19,7 +19,7 @@ def test_fatfs_sdcard_generic_sdmmc(dut: Dut) -> None: dut.write('') dut.expect_exact('Enter test for running.') dut.write('[sdmmc]') - dut.expect_unity_test_output() + dut.expect_unity_test_output(timeout=120) @pytest.mark.esp32 @@ -38,7 +38,7 @@ def test_fatfs_sdcard_generic_sdspi(dut: Dut) -> None: dut.write('') dut.expect_exact('Enter test for running.') dut.write('[sdspi]') - dut.expect_unity_test_output() + dut.expect_unity_test_output(timeout=120) @pytest.mark.esp32 @@ -55,7 +55,7 @@ def test_fatfs_sdcard_psram_sdmmc(dut: Dut) -> None: dut.write('') dut.expect_exact('Enter test for running.') dut.write('[sdmmc]') - dut.expect_unity_test_output() + dut.expect_unity_test_output(timeout=120) @pytest.mark.esp32 @@ -72,4 +72,4 @@ def test_fatfs_sdcard_psram_sdspi(dut: Dut) -> None: dut.write('') dut.expect_exact('Enter test for running.') dut.write('[sdspi]') - dut.expect_unity_test_output() + dut.expect_unity_test_output(timeout=120) diff --git a/components/sdmmc/sdmmc_cmd.c b/components/sdmmc/sdmmc_cmd.c index 9279532104..1851a8ca94 100644 --- a/components/sdmmc/sdmmc_cmd.c +++ b/components/sdmmc/sdmmc_cmd.c @@ -3,8 +3,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include "esp_timer.h" +#include "esp_timer.h" #include "sdmmc_common.h" static const char* TAG = "sdmmc_cmd"; @@ -467,6 +467,7 @@ esp_err_t sdmmc_write_sectors_dma(sdmmc_card_t* card, const void* src, if (++count % 10 == 0) { ESP_LOGV(TAG, "waiting for card to become ready (%d)", count); } + vTaskDelay(1); } /* SPI mode: although card busy indication is based on the busy token, * SD spec recommends that the host checks the results of programming by sending @@ -572,6 +573,7 @@ esp_err_t sdmmc_read_sectors_dma(sdmmc_card_t* card, void* dst, if (++count % 10 == 0) { ESP_LOGV(TAG, "waiting for card to become ready (%d)", count); } + vTaskDelay(1); } return ESP_OK; } diff --git a/components/sdmmc/sdmmc_sd.c b/components/sdmmc/sdmmc_sd.c index 63d6bf2ca5..50147fef6d 100644 --- a/components/sdmmc/sdmmc_sd.c +++ b/components/sdmmc/sdmmc_sd.c @@ -14,8 +14,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "esp_timer.h" +#include "esp_timer.h" #include "sdmmc_common.h" static const char* TAG = "sdmmc_sd"; @@ -152,6 +152,7 @@ esp_err_t sdmmc_init_sd_wait_data_ready(sdmmc_card_t* card) if (++count % 16 == 0) { ESP_LOGV(TAG, "waiting for card to become ready (%d)", count); } + vTaskDelay(1); } return ESP_OK; }