diff --git a/components/esp_driver_sdmmc/test_apps/sdmmc/components/sdmmc_tests/CMakeLists.txt b/components/esp_driver_sdmmc/test_apps/sdmmc/components/sdmmc_tests/CMakeLists.txt index 599b9ffba3..96fe18ea96 100644 --- a/components/esp_driver_sdmmc/test_apps/sdmmc/components/sdmmc_tests/CMakeLists.txt +++ b/components/esp_driver_sdmmc/test_apps/sdmmc/components/sdmmc_tests/CMakeLists.txt @@ -9,7 +9,8 @@ if(CONFIG_SOC_SDMMC_HOST_SUPPORTED) "sdmmc_test_erase_sd.c" "sdmmc_test_trim_sd.c" "sdmmc_test_discard_sd.c" - "sdmmc_test_sanitize_sd.c") + "sdmmc_test_sanitize_sd.c" + "sdmmc_test_various_cmds.c") endif() set(priv_requires "sdmmc" diff --git a/components/esp_driver_sdmmc/test_apps/sdmmc/components/sdmmc_tests/sdmmc_test_various_cmds.c b/components/esp_driver_sdmmc/test_apps/sdmmc/components/sdmmc_tests/sdmmc_test_various_cmds.c new file mode 100644 index 0000000000..2f05d0ceca --- /dev/null +++ b/components/esp_driver_sdmmc/test_apps/sdmmc/components/sdmmc_tests/sdmmc_test_various_cmds.c @@ -0,0 +1,73 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "sdkconfig.h" +#include +#include +#include "unity.h" +#include "esp_log.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "driver/sdmmc_defs.h" +#include "driver/sdmmc_host.h" +#include "sdmmc_cmd.h" +#include "esp_private/sdmmc_common.h" +#include "sdmmc_test_begin_end_sd.h" + +#if !SOC_SDMMC_HOST_SUPPORTED +#error "Targets with SDMMC host supported only" +#endif // !SOC_SDMMC_HOST_SUPPORTED + +static const char* TAG = "sdmmc_test_various_cmds"; + +static void sdmmc_write_sectors_cmd25_error_test_acmd22(sdmmc_card_t* card, uint32_t write_size) +{ + esp_err_t err = ESP_OK; + size_t block_size = (size_t)card->csd.sector_size; + size_t block_count = write_size / block_size; + void* buf = heap_caps_calloc(1, write_size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT | MALLOC_CAP_DMA); + TEST_ASSERT_NOT_NULL(buf); + + if (!host_is_spi(card)) { + err = sdmmc_wait_for_idle(card, 0); // wait for the card to be idle (in transfer state) + if (err != ESP_OK) { + free(buf); + } + TEST_ESP_OK(err); + } + + // Try to write to the card + err = sdmmc_write_sectors(card, buf, 0, block_count); + free(buf); + TEST_ESP_OK(err); + + // Check if the number of written blocks is equal to the number ACMD22 returns + // ACMD22 is usually only called if CMD25 fails but here we call it anyway to test it + size_t sucessfully_written_blocks; + err = sdmmc_send_cmd_num_of_written_blocks(card, &sucessfully_written_blocks); + TEST_ESP_OK(err); + TEST_ASSERT_EQUAL_size_t(sucessfully_written_blocks, block_count); + ESP_LOGI(TAG, "%s: ACMD22 successfully written %zu blocks out of %zu", __func__, sucessfully_written_blocks, block_count); +} + +static void do_one_mmc_acmd22_test(int slot, int width, int freq_khz, int ddr) +{ + sdmmc_card_t card; + sdmmc_test_sd_skip_if_board_incompatible(slot, width, freq_khz, ddr); + sdmmc_test_sd_begin(slot, width, freq_khz, ddr, &card); + sdmmc_card_print_info(stdout, &card); + sdmmc_write_sectors_cmd25_error_test_acmd22(&card, 4096 * 4); + sdmmc_test_sd_end(&card); +} + +TEST_CASE("send ACMD22 after writing multiple blocks to check real number of successfully written blocks, slot 0, 1-bit", "[sdmmc]") +{ + do_one_mmc_acmd22_test(SLOT_0, 1, SDMMC_FREQ_HIGHSPEED, NO_DDR); +} + +TEST_CASE("send ACMD22 after writing multiple blocks to check real number of successfully written blocks, slot 1, 1-bit", "[sdmmc]") +{ + do_one_mmc_acmd22_test(SLOT_1, 1, SDMMC_FREQ_HIGHSPEED, NO_DDR); +} diff --git a/components/sdmmc/sdmmc_common.h b/components/sdmmc/include/esp_private/sdmmc_common.h similarity index 99% rename from components/sdmmc/sdmmc_common.h rename to components/sdmmc/include/esp_private/sdmmc_common.h index 53e0e6e671..be8bb7ff4b 100644 --- a/components/sdmmc/sdmmc_common.h +++ b/components/sdmmc/include/esp_private/sdmmc_common.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2006 Uwe Stuehler - * Adaptations to ESP-IDF Copyright (c) 2016-2018 Espressif Systems (Shanghai) PTE LTD + * Adaptations to ESP-IDF Copyright (c) 2016-2024 Espressif Systems (Shanghai) PTE LTD * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above diff --git a/components/sdmmc/sdmmc_cmd.c b/components/sdmmc/sdmmc_cmd.c index ae8cb739a6..3f633adb19 100644 --- a/components/sdmmc/sdmmc_cmd.c +++ b/components/sdmmc/sdmmc_cmd.c @@ -5,7 +5,7 @@ */ #include -#include "sdmmc_common.h" +#include "esp_private/sdmmc_common.h" static const char* TAG = "sdmmc_cmd"; diff --git a/components/sdmmc/sdmmc_common.c b/components/sdmmc/sdmmc_common.c index 88554ed7d2..169a95dd9b 100644 --- a/components/sdmmc/sdmmc_common.c +++ b/components/sdmmc/sdmmc_common.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2006 Uwe Stuehler - * Adaptations to ESP-IDF Copyright (c) 2016-2018 Espressif Systems (Shanghai) PTE LTD + * Adaptations to ESP-IDF Copyright (c) 2016-2024 Espressif Systems (Shanghai) PTE LTD * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,7 +18,7 @@ #include #include "esp_log.h" #include "esp_timer.h" -#include "sdmmc_common.h" +#include "esp_private/sdmmc_common.h" static const char* TAG = "sdmmc_common"; diff --git a/components/sdmmc/sdmmc_init.c b/components/sdmmc/sdmmc_init.c index cd8a517e92..3e62209d36 100644 --- a/components/sdmmc/sdmmc_init.c +++ b/components/sdmmc/sdmmc_init.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2006 Uwe Stuehler - * Adaptations to ESP-IDF Copyright (c) 2016-2018 Espressif Systems (Shanghai) PTE LTD + * Adaptations to ESP-IDF Copyright (c) 2016-2024 Espressif Systems (Shanghai) PTE LTD * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -15,7 +15,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "sdmmc_common.h" +#include "esp_private/sdmmc_common.h" #include "sd_pwr_ctrl_by_on_chip_ldo.h" #include "sd_pwr_ctrl.h" diff --git a/components/sdmmc/sdmmc_io.c b/components/sdmmc/sdmmc_io.c index 970657dfe1..64492f2da3 100644 --- a/components/sdmmc/sdmmc_io.c +++ b/components/sdmmc/sdmmc_io.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2006 Uwe Stuehler - * Adaptations to ESP-IDF Copyright (c) 2016-2018 Espressif Systems (Shanghai) PTE LTD + * Adaptations to ESP-IDF Copyright (c) 2016-2024 Espressif Systems (Shanghai) PTE LTD * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,7 +16,7 @@ */ #include -#include "sdmmc_common.h" +#include "esp_private/sdmmc_common.h" #include "esp_attr.h" #include "esp_compiler.h" diff --git a/components/sdmmc/sdmmc_mmc.c b/components/sdmmc/sdmmc_mmc.c index 5662462aa2..a4fed8a4c9 100644 --- a/components/sdmmc/sdmmc_mmc.c +++ b/components/sdmmc/sdmmc_mmc.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2006 Uwe Stuehler - * Adaptations to ESP-IDF Copyright (c) 2016-2018 Espressif Systems (Shanghai) PTE LTD + * Adaptations to ESP-IDF Copyright (c) 2016-2024 Espressif Systems (Shanghai) PTE LTD * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -17,7 +17,7 @@ #include #include -#include "sdmmc_common.h" +#include "esp_private/sdmmc_common.h" static const char* TAG = "sdmmc_mmc"; diff --git a/components/sdmmc/sdmmc_sd.c b/components/sdmmc/sdmmc_sd.c index d9f5564acb..45b13beb6e 100644 --- a/components/sdmmc/sdmmc_sd.c +++ b/components/sdmmc/sdmmc_sd.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2006 Uwe Stuehler - * Adaptations to ESP-IDF Copyright (c) 2016-2018 Espressif Systems (Shanghai) PTE LTD + * Adaptations to ESP-IDF Copyright (c) 2016-2024 Espressif Systems (Shanghai) PTE LTD * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,7 +19,7 @@ #include "esp_check.h" #include "esp_timer.h" #include "esp_cache.h" -#include "sdmmc_common.h" +#include "esp_private/sdmmc_common.h" static const char* TAG = "sdmmc_sd"; diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index dced1b1ab5..712e7b5791 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -503,8 +503,8 @@ components/protocomm/include/transports/protocomm_console.h components/protocomm/include/transports/protocomm_httpd.h components/riscv/include/riscv/csr.h components/riscv/include/riscv/encoding.h +components/sdmmc/include/esp_private/sdmmc_common.h components/sdmmc/sdmmc_common.c -components/sdmmc/sdmmc_common.h components/sdmmc/sdmmc_init.c components/sdmmc/sdmmc_io.c components/sdmmc/sdmmc_mmc.c