mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
sdmmc: add vTaskDelay to loops to prevent potential WDT trigger
Also change timeout to 120 seconds in fatfs sdcard pytest to prevent failing during formatting.
This commit is contained in:
parent
74d6215b7f
commit
381d0fe032
@ -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;
|
||||
@ -159,11 +161,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) {
|
||||
@ -185,6 +183,8 @@ static esp_err_t sdmmc_host_clock_update_command(int slot)
|
||||
repeat = false;
|
||||
break;
|
||||
}
|
||||
|
||||
vTaskDelay(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,7 +237,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;
|
||||
}
|
||||
|
||||
@ -262,7 +263,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;
|
||||
}
|
||||
|
||||
@ -271,7 +273,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;
|
||||
}
|
||||
|
||||
@ -319,6 +322,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;
|
||||
@ -342,7 +346,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;
|
||||
}
|
||||
|
||||
@ -552,7 +556,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);
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user