]> granicus.if.org Git - esp-idf/blob - components/sdmmc/test/test_sd.c
Merge branch 'bugfix/fix_mesh_proxy_adv_with_wrong_dev_name' into 'master'
[esp-idf] / components / sdmmc / test / test_sd.c
1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include "unity.h"
19 #include "driver/gpio.h"
20 #include "driver/sdmmc_host.h"
21 #include "driver/sdspi_host.h"
22 #include "driver/sdmmc_defs.h"
23 #include "sdmmc_cmd.h"
24 #include "esp_log.h"
25 #include "esp_heap_caps.h"
26 #include <time.h>
27 #include <sys/time.h>
28 #include <unistd.h>
29
30 // Can't test eMMC (slot 0) and PSRAM together
31 #ifndef CONFIG_ESP32_SPIRAM_SUPPORT
32 #define WITH_EMMC_TEST
33 #endif
34
35 /* power supply enable pin */
36 #define SD_TEST_BOARD_VSEL_EN_GPIO  27
37
38 /* power supply voltage select pin */
39 #define SD_TEST_BOARD_VSEL_GPIO     26
40 #define SD_TEST_BOARD_VSEL_3V3      1
41 #define SD_TEST_BOARD_VSEL_1V8      0
42
43 /* time to wait for reset / power-on */
44 #define SD_TEST_BOARD_PWR_RST_DELAY_MS  5
45 #define SD_TEST_BOARD_PWR_ON_DELAY_MS   50
46
47 /* gpio which is not connected to actual CD pin, used to simulate CD behavior */
48 #define CD_WP_TEST_GPIO 18
49
50
51 static void sd_test_board_power_on(void)
52 {
53     gpio_set_direction(SD_TEST_BOARD_VSEL_GPIO, GPIO_MODE_OUTPUT);
54     gpio_set_level(SD_TEST_BOARD_VSEL_GPIO, SD_TEST_BOARD_VSEL_3V3);
55     gpio_set_direction(SD_TEST_BOARD_VSEL_EN_GPIO, GPIO_MODE_OUTPUT);
56     gpio_set_level(SD_TEST_BOARD_VSEL_EN_GPIO, 0);
57     usleep(SD_TEST_BOARD_PWR_RST_DELAY_MS * 1000);
58     gpio_set_level(SD_TEST_BOARD_VSEL_EN_GPIO, 1);
59     usleep(SD_TEST_BOARD_PWR_ON_DELAY_MS * 1000);
60 }
61
62 static void sd_test_board_power_off(void)
63 {
64     gpio_set_level(SD_TEST_BOARD_VSEL_EN_GPIO, 0);
65     gpio_set_direction(SD_TEST_BOARD_VSEL_GPIO, GPIO_MODE_INPUT);
66     gpio_set_level(SD_TEST_BOARD_VSEL_GPIO, 0);
67     gpio_set_direction(SD_TEST_BOARD_VSEL_EN_GPIO, GPIO_MODE_INPUT);
68 }
69
70
71 TEST_CASE("MMC_RSP_BITS", "[sd]")
72 {
73     uint32_t data[2] = { 0x01234567, 0x89abcdef };
74     TEST_ASSERT_EQUAL_HEX32(0x7,   MMC_RSP_BITS(data, 0, 4));
75     TEST_ASSERT_EQUAL_HEX32(0x567, MMC_RSP_BITS(data, 0, 12));
76     TEST_ASSERT_EQUAL_HEX32(0xf0,  MMC_RSP_BITS(data, 28, 8));
77     TEST_ASSERT_EQUAL_HEX32(0x3,   MMC_RSP_BITS(data, 1, 3));
78     TEST_ASSERT_EQUAL_HEX32(0x11,  MMC_RSP_BITS(data, 59, 5));
79 }
80
81 static void probe_sd(int slot, int width, int freq_khz, int ddr)
82 {
83     sd_test_board_power_on();
84     sdmmc_host_t config = SDMMC_HOST_DEFAULT();
85     config.slot = slot;
86     config.max_freq_khz = freq_khz;
87     sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
88     if (width == 1) {
89         config.flags = SDMMC_HOST_FLAG_1BIT;
90         slot_config.width = 1;
91     } else if (width == 4) {
92         config.flags &= ~SDMMC_HOST_FLAG_8BIT;
93         slot_config.width = 4;
94     } else {
95         assert(!ddr && "host driver does not support 8-line DDR mode yet");
96     }
97     if (!ddr) {
98         config.flags &= ~SDMMC_HOST_FLAG_DDR;
99     }
100     TEST_ESP_OK(sdmmc_host_init());
101     TEST_ESP_OK(sdmmc_host_init_slot(slot, &slot_config));
102     sdmmc_card_t* card = malloc(sizeof(sdmmc_card_t));
103     TEST_ASSERT_NOT_NULL(card);
104     TEST_ESP_OK(sdmmc_card_init(&config, card));
105     sdmmc_card_print_info(stdout, card);
106     uint8_t* buffer = heap_caps_malloc(512, MALLOC_CAP_DMA);
107     TEST_ESP_OK(sdmmc_read_sectors(card, buffer, 0, 1));
108     free(buffer);
109     TEST_ESP_OK(sdmmc_host_deinit());
110     free(card);
111     sd_test_board_power_off();
112 }
113
114 static void probe_spi(int freq_khz, int pin_miso, int pin_mosi, int pin_sck, int pin_cs)
115 {
116     sd_test_board_power_on();
117     sdmmc_host_t config = SDSPI_HOST_DEFAULT();
118     sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
119     slot_config.gpio_miso = pin_miso;
120     slot_config.gpio_mosi = pin_mosi;
121     slot_config.gpio_sck = pin_sck;
122     slot_config.gpio_cs = pin_cs;
123
124     TEST_ESP_OK(sdspi_host_init());
125     TEST_ESP_OK(sdspi_host_init_slot(config.slot, &slot_config));
126     sdmmc_card_t* card = malloc(sizeof(sdmmc_card_t));
127     TEST_ASSERT_NOT_NULL(card);
128     TEST_ESP_OK(sdmmc_card_init(&config, card));
129     sdmmc_card_print_info(stdout, card);
130     TEST_ESP_OK(sdspi_host_deinit());
131     free(card);
132     sd_test_board_power_off();
133 }
134
135
136 TEST_CASE("probe SD, slot 1, 4-bit", "[sd][test_env=UT_T1_SDMODE]")
137 {
138     probe_sd(SDMMC_HOST_SLOT_1, 4, SDMMC_FREQ_PROBING, 0);
139     probe_sd(SDMMC_HOST_SLOT_1, 4, SDMMC_FREQ_DEFAULT, 0);
140     probe_sd(SDMMC_HOST_SLOT_1, 4, SDMMC_FREQ_HIGHSPEED, 0);
141 }
142
143 TEST_CASE("probe SD, slot 1, 1-bit", "[sd][test_env=UT_T1_SDMODE]")
144 {
145     probe_sd(SDMMC_HOST_SLOT_1, 1, SDMMC_FREQ_PROBING, 0);
146     probe_sd(SDMMC_HOST_SLOT_1, 1, SDMMC_FREQ_DEFAULT, 0);
147     probe_sd(SDMMC_HOST_SLOT_1, 1, SDMMC_FREQ_HIGHSPEED, 0);
148 }
149
150 #ifdef WITH_EMMC_TEST
151 TEST_CASE("probe eMMC, slot 0, 4-bit, DDR", "[sd][test_env=EMMC]")
152 {
153     probe_sd(SDMMC_HOST_SLOT_0, 4, SDMMC_FREQ_HIGHSPEED, 1);
154 }
155
156 TEST_CASE("probe eMMC, slot 0, 8-bit", "[sd][test_env=EMMC]")
157 {
158     probe_sd(SDMMC_HOST_SLOT_0, 8, SDMMC_FREQ_PROBING, 0);
159     probe_sd(SDMMC_HOST_SLOT_0, 8, SDMMC_FREQ_DEFAULT, 0);
160     probe_sd(SDMMC_HOST_SLOT_0, 8, SDMMC_FREQ_HIGHSPEED, 0);
161 }
162 #endif // WITH_EMMC_TEST
163
164 TEST_CASE("probe SD, slot 0, 4-bit", "[sd][test_env=UT_T1_SDCARD][ignore]")
165 {
166     probe_sd(SDMMC_HOST_SLOT_0, 4, SDMMC_FREQ_PROBING, 0);
167     probe_sd(SDMMC_HOST_SLOT_0, 4, SDMMC_FREQ_DEFAULT, 0);
168     probe_sd(SDMMC_HOST_SLOT_0, 4, SDMMC_FREQ_HIGHSPEED, 0);
169 }
170
171 TEST_CASE("probe SD, slot 0, 1-bit", "[sd][test_env=UT_T1_SDCARD][ignore]")
172 {
173     probe_sd(SDMMC_HOST_SLOT_0, 1, SDMMC_FREQ_PROBING, 0);
174     probe_sd(SDMMC_HOST_SLOT_0, 1, SDMMC_FREQ_DEFAULT, 0);
175     probe_sd(SDMMC_HOST_SLOT_0, 1, SDMMC_FREQ_HIGHSPEED, 0);
176 }
177
178 TEST_CASE("probe SD in SPI mode, slot 1", "[sd][test_env=UT_T1_SPIMODE]")
179 {
180     probe_spi(SDMMC_FREQ_DEFAULT, 2, 15, 14, 13);
181 }
182
183 TEST_CASE("probe SD in SPI mode, slot 0", "[sd][test_env=UT_T1_SDCARD][ignore]")
184 {
185     probe_spi(SDMMC_FREQ_DEFAULT, 7, 11, 6, 10);
186 }
187
188
189 // Fill buffer pointed to by 'dst' with 'count' 32-bit ints generated
190 // from 'rand' with the starting value of 'seed'
191 static void fill_buffer(uint32_t seed, uint8_t* dst, size_t count) {
192     srand(seed);
193     for (size_t i = 0; i < count; ++i) {
194         uint32_t val = rand();
195         memcpy(dst + i * sizeof(uint32_t), &val, sizeof(val));
196     }
197 }
198
199 // Check if the buffer pointed to by 'dst' contains 'count' 32-bit
200 // ints generated from 'rand' with the starting value of 'seed'
201 static void check_buffer(uint32_t seed, const uint8_t* src, size_t count) {
202     srand(seed);
203     for (size_t i = 0; i < count; ++i) {
204         uint32_t val;
205         memcpy(&val, src + i * sizeof(uint32_t), sizeof(val));
206         TEST_ASSERT_EQUAL_HEX32(rand(), val);
207     }
208 }
209
210 static void do_single_write_read_test(sdmmc_card_t* card,
211         size_t start_block, size_t block_count, size_t alignment)
212 {
213     size_t block_size = card->csd.sector_size;
214     size_t total_size = block_size * block_count;
215     printf(" %8d |  %3d  |   %d   |    %4.1f  ", start_block, block_count, alignment, total_size / 1024.0f);
216
217     uint32_t* buffer = heap_caps_malloc(total_size + 4, MALLOC_CAP_DMA);
218     size_t offset = alignment % 4;
219     uint8_t* c_buffer = (uint8_t*) buffer + offset;
220     fill_buffer(start_block, c_buffer, total_size / sizeof(buffer[0]));
221
222     struct timeval t_start_wr;
223     gettimeofday(&t_start_wr, NULL);
224     TEST_ESP_OK(sdmmc_write_sectors(card, c_buffer, start_block, block_count));
225     struct timeval t_stop_wr;
226     gettimeofday(&t_stop_wr, NULL);
227     float time_wr = 1e3f * (t_stop_wr.tv_sec - t_start_wr.tv_sec) + 1e-3f * (t_stop_wr.tv_usec - t_start_wr.tv_usec);
228
229     memset(buffer, 0xbb, total_size + 4);
230
231     struct timeval t_start_rd;
232     gettimeofday(&t_start_rd, NULL);
233     TEST_ESP_OK(sdmmc_read_sectors(card, c_buffer, start_block, block_count));
234     struct timeval t_stop_rd;
235     gettimeofday(&t_stop_rd, NULL);
236     float time_rd = 1e3f * (t_stop_rd.tv_sec - t_start_rd.tv_sec) + 1e-3f * (t_stop_rd.tv_usec - t_start_rd.tv_usec);
237
238     printf(" |   %6.2f    |      %5.2f      |    %6.2f     |     %5.2f\n",
239             time_wr, total_size / (time_wr / 1000) / (1024 * 1024),
240             time_rd, total_size / (time_rd / 1000) / (1024 * 1024));
241     check_buffer(start_block, c_buffer, total_size / sizeof(buffer[0]));
242     free(buffer);
243 }
244
245 static void read_write_test(sdmmc_card_t* card)
246 {
247     sdmmc_card_print_info(stdout, card);
248     printf("  sector  | count | align | size(kB)  | wr_time(ms) | wr_speed(MB/s)  |  rd_time(ms)  | rd_speed(MB/s)\n");
249     do_single_write_read_test(card, 0, 1, 4);
250     do_single_write_read_test(card, 0, 4, 4);
251     do_single_write_read_test(card, 1, 16, 4);
252     do_single_write_read_test(card, 16, 32, 4);
253     do_single_write_read_test(card, 48, 64, 4);
254     do_single_write_read_test(card, 128, 128, 4);
255     do_single_write_read_test(card, card->csd.capacity - 64, 32, 4);
256     do_single_write_read_test(card, card->csd.capacity - 64, 64, 4);
257     do_single_write_read_test(card, card->csd.capacity - 8, 1, 4);
258     do_single_write_read_test(card, card->csd.capacity/2, 1, 4);
259     do_single_write_read_test(card, card->csd.capacity/2, 4, 4);
260     do_single_write_read_test(card, card->csd.capacity/2, 8, 4);
261     do_single_write_read_test(card, card->csd.capacity/2, 16, 4);
262     do_single_write_read_test(card, card->csd.capacity/2, 32, 4);
263     do_single_write_read_test(card, card->csd.capacity/2, 64, 4);
264     do_single_write_read_test(card, card->csd.capacity/2, 128, 4);
265     do_single_write_read_test(card, card->csd.capacity/2, 1, 1);
266     do_single_write_read_test(card, card->csd.capacity/2, 8, 1);
267     do_single_write_read_test(card, card->csd.capacity/2, 128, 1);
268 }
269
270 void test_sd_rw_blocks(int slot, int width)
271 {
272     sdmmc_host_t config = SDMMC_HOST_DEFAULT();
273     config.max_freq_khz = SDMMC_FREQ_HIGHSPEED;
274     config.slot = slot;
275     sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
276     if (width != 0) {
277         slot_config.width = width;
278     }
279     if (slot_config.width == 8) {
280         config.flags &= ~SDMMC_HOST_FLAG_DDR;
281     }
282     TEST_ESP_OK(sdmmc_host_init());
283     TEST_ESP_OK(sdmmc_host_init_slot(slot, &slot_config));
284     sdmmc_card_t* card = malloc(sizeof(sdmmc_card_t));
285     TEST_ASSERT_NOT_NULL(card);
286     TEST_ESP_OK(sdmmc_card_init(&config, card));
287     read_write_test(card);
288     free(card);
289     TEST_ESP_OK(sdmmc_host_deinit());
290 }
291
292 TEST_CASE("SDMMC read/write test (SD slot 1)", "[sd][test_env=UT_T1_SDMODE]")
293 {
294     sd_test_board_power_on();
295     test_sd_rw_blocks(1, 4);
296     sd_test_board_power_off();
297 }
298
299 #ifdef WITH_EMMC_TEST
300 TEST_CASE("SDMMC read/write test (eMMC slot 0, 4 line DDR)", "[sd][test_env=EMMC]")
301 {
302     sd_test_board_power_on();
303     test_sd_rw_blocks(0, 4);
304     sd_test_board_power_off();
305 }
306
307 TEST_CASE("SDMMC read/write test (eMMC slot 0, 8 line)", "[sd][test_env=EMMC]")
308 {
309     sd_test_board_power_on();
310     test_sd_rw_blocks(0, 8);
311     sd_test_board_power_off();
312 }
313 #endif // WITH_EMMC_TEST
314
315 TEST_CASE("SDMMC read/write test (SD slot 1, in SPI mode)", "[sdspi][test_env=UT_T1_SPIMODE]")
316 {
317     sd_test_board_power_on();
318     sdmmc_host_t config = SDSPI_HOST_DEFAULT();
319     sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
320     TEST_ESP_OK(sdspi_host_init());
321     TEST_ESP_OK(sdspi_host_init_slot(config.slot, &slot_config));
322     sdmmc_card_t* card = malloc(sizeof(sdmmc_card_t));
323     TEST_ASSERT_NOT_NULL(card);
324     TEST_ESP_OK(sdmmc_card_init(&config, card));
325     read_write_test(card);
326     free(card);
327     TEST_ESP_OK(sdspi_host_deinit());
328     sd_test_board_power_off();
329 }
330
331 TEST_CASE("reads and writes with an unaligned buffer", "[sd][test_env=UT_T1_SDMODE]")
332 {
333     sd_test_board_power_on();
334     sdmmc_host_t config = SDMMC_HOST_DEFAULT();
335     sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
336     TEST_ESP_OK(sdmmc_host_init());
337
338     TEST_ESP_OK(sdmmc_host_init_slot(SDMMC_HOST_SLOT_1, &slot_config));
339     sdmmc_card_t* card = malloc(sizeof(sdmmc_card_t));
340     TEST_ASSERT_NOT_NULL(card);
341     TEST_ESP_OK(sdmmc_card_init(&config, card));
342
343     const size_t buffer_size = 4096;
344     const size_t block_count = buffer_size / 512;
345     const size_t extra = 4;
346     uint8_t* buffer = heap_caps_malloc(buffer_size + extra, MALLOC_CAP_DMA);
347
348     // Check read behavior: do aligned write, then unaligned read
349     const uint32_t seed = 0x89abcdef;
350     fill_buffer(seed, buffer, buffer_size / sizeof(uint32_t));
351     TEST_ESP_OK(sdmmc_write_sectors(card, buffer, 0, block_count));
352     memset(buffer, 0xcc, buffer_size + extra);
353     TEST_ESP_OK(sdmmc_read_sectors(card, buffer + 1, 0, block_count));
354     check_buffer(seed, buffer + 1, buffer_size / sizeof(uint32_t));
355
356     // Check write behavior: do unaligned write, then aligned read
357     fill_buffer(seed, buffer + 1, buffer_size / sizeof(uint32_t));
358     TEST_ESP_OK(sdmmc_write_sectors(card, buffer + 1, 8, block_count));
359     memset(buffer, 0xcc, buffer_size + extra);
360     TEST_ESP_OK(sdmmc_read_sectors(card, buffer, 8, block_count));
361     check_buffer(seed, buffer, buffer_size / sizeof(uint32_t));
362
363     free(buffer);
364     free(card);
365     TEST_ESP_OK(sdmmc_host_deinit());
366     sd_test_board_power_off();
367 }
368
369 static void test_cd_input(int gpio_cd_num, const sdmmc_host_t* config)
370 {
371     sdmmc_card_t* card = malloc(sizeof(sdmmc_card_t));
372     TEST_ASSERT_NOT_NULL(card);
373
374     // SDMMC host should have configured CD as input.
375     // Enable output as well (not using the driver, to avoid touching input
376     // enable bits).
377     gpio_matrix_out(gpio_cd_num, SIG_GPIO_OUT_IDX, false, false);
378     REG_WRITE(GPIO_ENABLE_W1TS_REG, BIT(gpio_cd_num));
379
380     // Check that card initialization fails if CD is high
381     REG_WRITE(GPIO_OUT_W1TS_REG, BIT(gpio_cd_num));
382     usleep(1000);
383     TEST_ESP_ERR(ESP_ERR_NOT_FOUND, sdmmc_card_init(config, card));
384
385     // Check that card initialization succeeds if CD is low
386     REG_WRITE(GPIO_OUT_W1TC_REG, BIT(gpio_cd_num));
387     usleep(1000);
388     TEST_ESP_OK(sdmmc_card_init(config, card));
389
390     free(card);
391 }
392
393 TEST_CASE("CD input works in SD mode", "[sd][test_env=UT_T1_SDMODE]")
394 {
395     sd_test_board_power_on();
396     sdmmc_host_t config = SDMMC_HOST_DEFAULT();
397     sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
398     slot_config.gpio_cd = CD_WP_TEST_GPIO;
399     TEST_ESP_OK(sdmmc_host_init());
400     TEST_ESP_OK(sdmmc_host_init_slot(SDMMC_HOST_SLOT_1, &slot_config));
401
402     test_cd_input(CD_WP_TEST_GPIO, &config);
403
404     TEST_ESP_OK(sdmmc_host_deinit());
405     sd_test_board_power_off();
406 }
407
408 TEST_CASE("CD input works in SPI mode", "[sd][test_env=UT_T1_SPIMODE]")
409 {
410     sd_test_board_power_on();
411     sdmmc_host_t config = SDSPI_HOST_DEFAULT();
412     sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
413     slot_config.gpio_cd = CD_WP_TEST_GPIO;
414     TEST_ESP_OK(sdspi_host_init());
415     TEST_ESP_OK(sdspi_host_init_slot(config.slot, &slot_config));
416
417     test_cd_input(CD_WP_TEST_GPIO, &config);
418
419     TEST_ESP_OK(sdspi_host_deinit());
420     sd_test_board_power_off();
421 }
422
423 static void test_wp_input(int gpio_wp_num, const sdmmc_host_t* config)
424 {
425     sdmmc_card_t* card = malloc(sizeof(sdmmc_card_t));
426     TEST_ASSERT_NOT_NULL(card);
427
428     // SDMMC host should have configured WP as input.
429     // Enable output as well (not using the driver, to avoid touching input
430     // enable bits).
431     gpio_matrix_out(gpio_wp_num, SIG_GPIO_OUT_IDX, false, false);
432     REG_WRITE(GPIO_ENABLE_W1TS_REG, BIT(gpio_wp_num));
433
434     // Check that the card can be initialized with WP low
435     REG_WRITE(GPIO_OUT_W1TC_REG, BIT(gpio_wp_num));
436     TEST_ESP_OK(sdmmc_card_init(config, card));
437
438     uint32_t* data = heap_caps_calloc(1, 512, MALLOC_CAP_DMA);
439
440     // Check that card write succeeds if WP is high
441     REG_WRITE(GPIO_OUT_W1TS_REG, BIT(gpio_wp_num));
442     usleep(1000);
443     TEST_ESP_OK(sdmmc_write_sectors(card, &data, 0, 1));
444
445     // Check that write fails if WP is low
446     REG_WRITE(GPIO_OUT_W1TC_REG, BIT(gpio_wp_num));
447     usleep(1000);
448     TEST_ESP_ERR(ESP_ERR_INVALID_STATE, sdmmc_write_sectors(card, &data, 0, 1));
449     // ...but reads still work
450     TEST_ESP_OK(sdmmc_read_sectors(card, &data, 0, 1));
451
452     free(data);
453     free(card);
454 }
455
456 TEST_CASE("WP input works in SD mode", "[sd][test_env=UT_T1_SDMODE]")
457 {
458     sd_test_board_power_on();
459     sdmmc_host_t config = SDMMC_HOST_DEFAULT();
460     sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
461     slot_config.gpio_wp = CD_WP_TEST_GPIO;
462     TEST_ESP_OK(sdmmc_host_init());
463     TEST_ESP_OK(sdmmc_host_init_slot(SDMMC_HOST_SLOT_1, &slot_config));
464
465     test_wp_input(CD_WP_TEST_GPIO, &config);
466
467     TEST_ESP_OK(sdmmc_host_deinit());
468     sd_test_board_power_off();
469 }
470
471 TEST_CASE("WP input works in SPI mode", "[sd][test_env=UT_T1_SPIMODE]")
472 {
473     sd_test_board_power_on();
474     sdmmc_host_t config = SDSPI_HOST_DEFAULT();
475     sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
476     slot_config.gpio_wp = CD_WP_TEST_GPIO;
477     TEST_ESP_OK(sdspi_host_init());
478     TEST_ESP_OK(sdspi_host_init_slot(config.slot, &slot_config));
479
480     test_wp_input(CD_WP_TEST_GPIO, &config);
481
482     TEST_ESP_OK(sdspi_host_deinit());
483     sd_test_board_power_off();
484 }