]> granicus.if.org Git - esp-idf/blob - components/driver/sdmmc_host.c
heap: test: don’t warn about oversized mallocs
[esp-idf] / components / driver / sdmmc_host.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 <stdbool.h>
16 #include <stddef.h>
17 #include <sys/param.h>
18 #include "esp_log.h"
19 #include "esp_intr_alloc.h"
20 #include "soc/io_mux_reg.h"
21 #include "rom/gpio.h"
22 #include "driver/gpio.h"
23 #include "driver/sdmmc_host.h"
24 #include "driver/periph_ctrl.h"
25 #include "sdmmc_private.h"
26 #include "freertos/semphr.h"
27 #include "soc/sdmmc_periph.h"
28
29 #define SDMMC_EVENT_QUEUE_LENGTH 32
30
31
32 static void sdmmc_isr(void* arg);
33 static void sdmmc_host_dma_init();
34
35
36 static const char* TAG = "sdmmc_periph";
37 static intr_handle_t s_intr_handle;
38 static QueueHandle_t s_event_queue;
39 static SemaphoreHandle_t s_io_intr_event;
40
41 size_t s_slot_width[2] = {1,1};
42
43 void sdmmc_host_reset()
44 {
45     // Set reset bits
46     SDMMC.ctrl.controller_reset = 1;
47     SDMMC.ctrl.dma_reset = 1;
48     SDMMC.ctrl.fifo_reset = 1;
49     // Wait for the reset bits to be cleared by hardware
50     while (SDMMC.ctrl.controller_reset || SDMMC.ctrl.fifo_reset || SDMMC.ctrl.dma_reset) {
51         ;
52     }
53 }
54
55 /* We have two clock divider stages:
56  * - one is the clock generator which drives SDMMC peripheral,
57  *   it can be configured using SDMMC.clock register. It can generate
58  *   frequencies 160MHz/(N + 1), where 0 < N < 16, I.e. from 10 to 80 MHz.
59  * - 4 clock dividers inside SDMMC peripheral, which can divide clock
60  *   from the first stage by 2 * M, where 0 < M < 255
61  *   (they can also be bypassed).
62  *
63  * For cards which aren't UHS-1 or UHS-2 cards, which we don't support,
64  * maximum bus frequency in high speed (HS) mode is 50 MHz.
65  * Note: for non-UHS-1 cards, HS mode is optional.
66  * Default speed (DS) mode is mandatory, it works up to 25 MHz.
67  * Whether the card supports HS or not can be determined using TRAN_SPEED
68  * field of card's CSD register.
69  *
70  * 50 MHz can not be obtained exactly, closest we can get is 53 MHz.
71  *
72  * The first stage divider is set to the highest possible value for the given
73  * frequency, and the the second stage dividers are used if division factor
74  * is >16.
75  *
76  * Of the second stage dividers, div0 is used for card 0, and div1 is used
77  * for card 1.
78  */
79
80 static void sdmmc_host_set_clk_div(int div)
81 {
82     // Set frequency to 160MHz / div
83     // div = p + 1
84     // duty cycle = (h + 1)/(p + 1) (should be = 1/2)
85     assert (div > 1 && div <= 16);
86     int p = div - 1;
87     int h = div / 2 - 1;
88
89     SDMMC.clock.div_factor_p = p;
90     SDMMC.clock.div_factor_h = h;
91     SDMMC.clock.div_factor_m = p;
92     // Set phases for in/out clocks
93     SDMMC.clock.phase_dout = 4;     // 180 degree phase on the output clock
94     SDMMC.clock.phase_din = 4;      // 180 degree phase on the input clock
95     SDMMC.clock.phase_core = 0;
96     // Wait for the clock to propagate
97     ets_delay_us(10);
98 }
99
100 static void sdmmc_host_input_clk_disable()
101 {
102     SDMMC.clock.val = 0;
103 }
104
105 static void sdmmc_host_clock_update_command(int slot)
106 {
107     // Clock update command (not a real command; just updates CIU registers)
108     sdmmc_hw_cmd_t cmd_val = {
109         .card_num = slot,
110         .update_clk_reg = 1,
111         .wait_complete = 1
112     };
113     bool repeat = true;
114     while(repeat) {
115         sdmmc_host_start_command(slot, cmd_val, 0);
116         while (true) {
117             // Sending clock update command to the CIU can generate HLE error.
118             // According to the manual, this is okay and we must retry the command.
119             if (SDMMC.rintsts.hle) {
120                 SDMMC.rintsts.hle = 1;
121                 repeat = true;
122                 break;
123             }
124             // When the command is accepted by CIU, start_command bit will be
125             // cleared in SDMMC.cmd register.
126             if (SDMMC.cmd.start_command == 0) {
127                 repeat = false;
128                 break;
129             }
130         }
131     }
132 }
133
134 esp_err_t sdmmc_host_set_card_clk(int slot, uint32_t freq_khz)
135 {
136     if (!(slot == 0 || slot == 1)) {
137         return ESP_ERR_INVALID_ARG;
138     }
139     const int clk40m = 40000;
140
141     // Disable clock first
142     SDMMC.clkena.cclk_enable &= ~BIT(slot);
143     sdmmc_host_clock_update_command(slot);
144
145     int host_div = 0;   /* clock divider of the host (SDMMC.clock) */
146     int card_div = 0;   /* 1/2 of card clock divider (SDMMC.clkdiv) */
147
148     // Calculate new dividers
149     if (freq_khz >= SDMMC_FREQ_HIGHSPEED) {
150         host_div = 4;       // 160 MHz / 4 = 40 MHz
151         card_div = 0;
152     } else if (freq_khz == SDMMC_FREQ_DEFAULT) {
153         host_div = 8;       // 160 MHz / 8 = 20 MHz
154         card_div = 0;
155     } else if (freq_khz == SDMMC_FREQ_PROBING) {
156         host_div = 10;      // 160 MHz / 10 / (20 * 2) = 400 kHz
157         card_div = 20;
158     } else {
159         host_div = 2;
160         card_div = (clk40m + freq_khz * 2 - 1) / (freq_khz * 2); // round up
161     }
162
163     ESP_LOGD(TAG, "slot=%d host_div=%d card_div=%d freq=%dkHz",
164             slot, host_div, card_div,
165             2 * APB_CLK_FREQ / host_div / ((card_div == 0) ? 1 : card_div * 2) / 1000);
166
167     // Program CLKDIV and CLKSRC, send them to the CIU
168     switch(slot) {
169         case 0:
170             SDMMC.clksrc.card0 = 0;
171             SDMMC.clkdiv.div0 = card_div;
172             break;
173         case 1:
174             SDMMC.clksrc.card1 = 1;
175             SDMMC.clkdiv.div1 = card_div;
176             break;
177     }
178     sdmmc_host_set_clk_div(host_div);
179     sdmmc_host_clock_update_command(slot);
180
181     // Re-enable clocks
182     SDMMC.clkena.cclk_enable |= BIT(slot);
183     SDMMC.clkena.cclk_low_power |= BIT(slot);
184     sdmmc_host_clock_update_command(slot);
185
186     // set data timeout
187     const uint32_t data_timeout_ms = 100;
188     uint32_t data_timeout_cycles = data_timeout_ms * freq_khz;
189     const uint32_t data_timeout_cycles_max = 0xffffff;
190     if (data_timeout_cycles > data_timeout_cycles_max) {
191         data_timeout_cycles = data_timeout_cycles_max;
192     }
193     SDMMC.tmout.data = data_timeout_cycles;
194     // always set response timeout to highest value, it's small enough anyway
195     SDMMC.tmout.response = 255;
196     return ESP_OK;
197 }
198
199 esp_err_t sdmmc_host_start_command(int slot, sdmmc_hw_cmd_t cmd, uint32_t arg) {
200     if (!(slot == 0 || slot == 1)) {
201         return ESP_ERR_INVALID_ARG;
202     }
203     if ((SDMMC.cdetect.cards & BIT(slot)) != 0) {
204         return ESP_ERR_NOT_FOUND;
205     }
206     if (cmd.data_expected && cmd.rw && (SDMMC.wrtprt.cards & BIT(slot)) != 0) {
207         return ESP_ERR_INVALID_STATE;
208     }
209     while (SDMMC.cmd.start_command == 1) {
210         ;
211     }
212     SDMMC.cmdarg = arg;
213     cmd.card_num = slot;
214     cmd.start_command = 1;
215     SDMMC.cmd = cmd;
216     return ESP_OK;
217 }
218
219 esp_err_t sdmmc_host_init()
220 {
221     if (s_intr_handle) {
222         return ESP_ERR_INVALID_STATE;
223     }
224
225     periph_module_enable(PERIPH_SDMMC_MODULE);
226
227     // Enable clock to peripheral. Use smallest divider first.
228     sdmmc_host_set_clk_div(2);
229
230     // Reset
231     sdmmc_host_reset();
232     ESP_LOGD(TAG, "peripheral version %x, hardware config %08x", SDMMC.verid, SDMMC.hcon);
233
234     // Clear interrupt status and set interrupt mask to known state
235     SDMMC.rintsts.val = 0xffffffff;
236     SDMMC.intmask.val = 0;
237     SDMMC.ctrl.int_enable = 0;
238
239     // Allocate event queue
240     s_event_queue = xQueueCreate(SDMMC_EVENT_QUEUE_LENGTH, sizeof(sdmmc_event_t));
241     if (!s_event_queue) {
242         return ESP_ERR_NO_MEM;
243     }
244     s_io_intr_event = xSemaphoreCreateBinary();
245     if (!s_io_intr_event) {
246         vQueueDelete(s_event_queue);
247         s_event_queue = NULL;
248         return ESP_ERR_NO_MEM;
249     }
250     // Attach interrupt handler
251     esp_err_t ret = esp_intr_alloc(ETS_SDIO_HOST_INTR_SOURCE, 0, &sdmmc_isr, s_event_queue, &s_intr_handle);
252     if (ret != ESP_OK) {
253         vQueueDelete(s_event_queue);
254         s_event_queue = NULL;
255         vSemaphoreDelete(s_io_intr_event);
256         s_io_intr_event = NULL;
257         return ret;
258     }
259     // Enable interrupts
260     SDMMC.intmask.val =
261             SDMMC_INTMASK_CD |
262             SDMMC_INTMASK_CMD_DONE |
263             SDMMC_INTMASK_DATA_OVER |
264             SDMMC_INTMASK_RCRC | SDMMC_INTMASK_DCRC |
265             SDMMC_INTMASK_RTO | SDMMC_INTMASK_DTO | SDMMC_INTMASK_HTO |
266             SDMMC_INTMASK_SBE | SDMMC_INTMASK_EBE |
267             SDMMC_INTMASK_RESP_ERR | SDMMC_INTMASK_HLE; //sdio is enabled only when use.
268     SDMMC.ctrl.int_enable = 1;
269
270     // Enable DMA
271     sdmmc_host_dma_init();
272
273     // Initialize transaction handler
274     ret = sdmmc_host_transaction_handler_init();
275     if (ret != ESP_OK) {
276         vQueueDelete(s_event_queue);
277         s_event_queue = NULL;
278         vSemaphoreDelete(s_io_intr_event);
279         s_io_intr_event = NULL;
280         esp_intr_free(s_intr_handle);
281         s_intr_handle = NULL;
282         return ret;
283     }
284
285     return ESP_OK;
286 }
287
288 static void configure_pin(int pin)
289 {
290     const int sdmmc_func = 3;
291     const int drive_strength = 3;
292     assert(pin!=-1);
293     gpio_pulldown_dis(pin);
294
295     uint32_t reg = GPIO_PIN_MUX_REG[pin];
296     assert(reg != UINT32_MAX);
297     PIN_INPUT_ENABLE(reg);
298     PIN_FUNC_SELECT(reg, sdmmc_func);
299     PIN_SET_DRV(reg, drive_strength);
300 }
301
302 esp_err_t sdmmc_host_init_slot(int slot, const sdmmc_slot_config_t* slot_config)
303 {
304     bool pullup = slot_config->flags & SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
305     if (pullup) {
306         sdmmc_host_pullup_en(slot, slot_config->width);
307     }
308     if (!s_intr_handle) {
309         return ESP_ERR_INVALID_STATE;
310     }
311     if (!(slot == 0 || slot == 1)) {
312         return ESP_ERR_INVALID_ARG;
313     }
314     if (slot_config == NULL) {
315         return ESP_ERR_INVALID_ARG;
316     }
317     int gpio_cd = slot_config->gpio_cd;
318     int gpio_wp = slot_config->gpio_wp;
319     uint8_t slot_width = slot_config->width;
320
321     // Configure pins
322     const sdmmc_slot_info_t* pslot = &sdmmc_slot_info[slot];
323
324     if (slot_width == SDMMC_SLOT_WIDTH_DEFAULT) {
325         slot_width = pslot->width;
326     }
327     else if (slot_width > pslot->width) {
328         return ESP_ERR_INVALID_ARG;
329     }
330     s_slot_width[slot] = slot_width;
331
332     configure_pin(pslot->clk_gpio);
333     configure_pin(pslot->cmd_gpio);
334     configure_pin(pslot->d0_gpio);
335
336     if (slot_width >= 4) {
337         configure_pin(pslot->d1_gpio);
338         configure_pin(pslot->d2_gpio);
339         //force pull-up D3 to make slave detect SD mode. connect to peripheral after width configuration.
340         gpio_config_t gpio_conf = {
341             .pin_bit_mask = BIT(pslot->d3_gpio),
342             .mode = GPIO_MODE_OUTPUT ,
343             .pull_up_en = 0,
344             .pull_down_en = 0,
345             .intr_type = GPIO_INTR_DISABLE,
346         };
347         gpio_config( &gpio_conf );
348         gpio_set_level( pslot->d3_gpio, 1 );
349         if (slot_width == 8) {
350             configure_pin(pslot->d4_gpio);
351             configure_pin(pslot->d5_gpio);
352             configure_pin(pslot->d6_gpio);
353             configure_pin(pslot->d7_gpio);
354         }
355     }
356
357     // SDIO slave interrupt is edge sensitive to ~(int_n | card_int | card_detect)
358     // set this and card_detect to high to enable sdio interrupt
359     gpio_matrix_in(GPIO_FUNC_IN_HIGH, pslot->card_int, false);
360
361     // Set up Card Detect input
362     int matrix_in_cd;
363     if (gpio_cd != SDMMC_SLOT_NO_CD) {
364         ESP_LOGD(TAG, "using GPIO%d as CD pin", gpio_cd);
365         gpio_pad_select_gpio(gpio_cd);
366         gpio_set_direction(gpio_cd, GPIO_MODE_INPUT);
367         matrix_in_cd = gpio_cd;
368     } else {
369         // if not set, default to CD low (card present)
370         matrix_in_cd = GPIO_FUNC_IN_LOW;
371     }
372     gpio_matrix_in(matrix_in_cd, pslot->card_detect, false);
373
374     // Set up Write Protect input
375     int matrix_in_wp;
376     if (gpio_wp != SDMMC_SLOT_NO_WP) {
377         ESP_LOGD(TAG, "using GPIO%d as WP pin", gpio_wp);
378         gpio_pad_select_gpio(gpio_wp);
379         gpio_set_direction(gpio_wp, GPIO_MODE_INPUT);
380         matrix_in_wp = gpio_wp;
381     } else {
382         // if not set, default to WP high (not write protected)
383         matrix_in_wp = GPIO_FUNC_IN_HIGH;
384     }
385     // WP signal is normally active low, but hardware expects
386     // an active-high signal, so invert it in GPIO matrix
387     gpio_matrix_in(matrix_in_wp, pslot->write_protect, true);
388
389     // By default, set probing frequency (400kHz) and 1-bit bus
390     esp_err_t ret = sdmmc_host_set_card_clk(slot, 400);
391     if (ret != ESP_OK) {
392         return ret;
393     }
394     ret = sdmmc_host_set_bus_width(slot, 1);
395     if (ret != ESP_OK) {
396         return ret;
397     }
398     return ESP_OK;
399 }
400
401 esp_err_t sdmmc_host_deinit()
402 {
403     if (!s_intr_handle) {
404         return ESP_ERR_INVALID_STATE;
405     }
406     esp_intr_free(s_intr_handle);
407     s_intr_handle = NULL;
408     vQueueDelete(s_event_queue);
409     s_event_queue = NULL;
410     vQueueDelete(s_io_intr_event);
411     s_io_intr_event = NULL;
412     sdmmc_host_input_clk_disable();
413     sdmmc_host_transaction_handler_deinit();
414     periph_module_disable(PERIPH_SDMMC_MODULE);
415     return ESP_OK;
416 }
417
418 esp_err_t sdmmc_host_wait_for_event(int tick_count, sdmmc_event_t* out_event)
419 {
420     if (!out_event) {
421         return ESP_ERR_INVALID_ARG;
422     }
423     if (!s_event_queue) {
424         return ESP_ERR_INVALID_STATE;
425     }
426     int ret = xQueueReceive(s_event_queue, out_event, tick_count);
427     if (ret == pdFALSE) {
428         return ESP_ERR_TIMEOUT;
429     }
430     return ESP_OK;
431 }
432
433 esp_err_t sdmmc_host_set_bus_width(int slot, size_t width)
434 {
435     if (!(slot == 0 || slot == 1)) {
436         return ESP_ERR_INVALID_ARG;
437     }
438     if (sdmmc_slot_info[slot].width < width) {
439         return ESP_ERR_INVALID_ARG;
440     }
441     const uint16_t mask = BIT(slot);
442     if (width == 1) {
443         SDMMC.ctype.card_width_8 &= ~mask;
444         SDMMC.ctype.card_width &= ~mask;
445     } else if (width == 4) {
446         SDMMC.ctype.card_width_8 &= ~mask;
447         SDMMC.ctype.card_width |= mask;
448         configure_pin(sdmmc_slot_info[slot].d3_gpio);   // D3 was set to GPIO high to force slave into SD 1-bit mode, until 4-bit mode is set
449     } else if (width == 8){
450         SDMMC.ctype.card_width_8 |= mask;
451         configure_pin(sdmmc_slot_info[slot].d3_gpio);   // D3 was set to GPIO high to force slave into SD 1-bit mode, until 4-bit mode is set
452     } else {
453         return ESP_ERR_INVALID_ARG;
454     }
455     ESP_LOGD(TAG, "slot=%d width=%d", slot, width);
456     return ESP_OK;
457 }
458
459 size_t sdmmc_host_get_slot_width(int slot)
460 {
461     assert( slot == 0 || slot == 1 );
462     return s_slot_width[slot];
463 }
464
465 static void sdmmc_host_dma_init()
466 {
467     SDMMC.ctrl.dma_enable = 1;
468     SDMMC.bmod.val = 0;
469     SDMMC.bmod.sw_reset = 1;
470     SDMMC.idinten.ni = 1;
471     SDMMC.idinten.ri = 1;
472     SDMMC.idinten.ti = 1;
473 }
474
475
476 void sdmmc_host_dma_stop()
477 {
478     SDMMC.ctrl.use_internal_dma = 0;
479     SDMMC.ctrl.dma_reset = 1;
480     SDMMC.bmod.fb = 0;
481     SDMMC.bmod.enable = 0;
482 }
483
484 void sdmmc_host_dma_prepare(sdmmc_desc_t* desc, size_t block_size, size_t data_size)
485 {
486     // Set size of data and DMA descriptor pointer
487     SDMMC.bytcnt = data_size;
488     SDMMC.blksiz = block_size;
489     SDMMC.dbaddr = desc;
490
491     // Enable everything needed to use DMA
492     SDMMC.ctrl.dma_enable = 1;
493     SDMMC.ctrl.use_internal_dma = 1;
494     SDMMC.bmod.enable = 1;
495     SDMMC.bmod.fb = 1;
496     sdmmc_host_dma_resume();
497 }
498
499 void sdmmc_host_dma_resume()
500 {
501     SDMMC.pldmnd = 1;
502 }
503
504 esp_err_t sdmmc_host_io_int_enable(int slot)
505 {
506     configure_pin(sdmmc_slot_info[slot].d1_gpio);
507     return ESP_OK;
508 }
509
510 esp_err_t sdmmc_host_io_int_wait(int slot, TickType_t timeout_ticks)
511 {   
512     /* SDIO interrupts are negedge sensitive ones: the status bit is only set
513      * when first interrupt triggered.
514      *
515      * If D1 GPIO is low when entering this function, we know that interrupt
516      * (in SDIO sense) has occurred and we don't need to use SDMMC peripheral
517      * interrupt.
518      */
519
520     SDMMC.intmask.sdio &= ~BIT(slot);   /* Disable SDIO interrupt */
521     SDMMC.rintsts.sdio = BIT(slot);
522     if (gpio_get_level(sdmmc_slot_info[slot].d1_gpio) == 0) {
523         return ESP_OK;
524     }
525     /* Otherwise, need to wait for an interrupt. Since D1 was high,
526      * SDMMC peripheral interrupt is guaranteed to trigger on negedge.
527      */
528     xSemaphoreTake(s_io_intr_event, 0);
529     SDMMC.intmask.sdio |= BIT(slot);    /* Re-enable SDIO interrupt */
530     
531     if (xSemaphoreTake(s_io_intr_event, timeout_ticks) == pdTRUE) {
532         return ESP_OK;
533     } else {
534         return ESP_ERR_TIMEOUT;
535     }
536 }
537
538 /**
539  * @brief SDMMC interrupt handler
540  *
541  * All communication in SD protocol is driven by the master, and the hardware
542  * handles things like stop commands automatically.
543  * So the interrupt handler doesn't need to do much, we just push interrupt
544  * status into a queue, clear interrupt flags, and let the task currently
545  * doing communication figure out what to do next.
546  * This also applies to SDIO interrupts which are generated by the slave.
547  *
548  * Card detect interrupts pose a small issue though, because if a card is
549  * plugged in and out a few times, while there is no task to process
550  * the events, event queue can become full and some card detect events
551  * may be dropped. We ignore this problem for now, since the there are no other
552  * interesting events which can get lost due to this.
553  */
554 static void sdmmc_isr(void* arg) {
555     QueueHandle_t queue = (QueueHandle_t) arg;
556     sdmmc_event_t event;
557     int higher_priority_task_awoken = pdFALSE;
558
559     uint32_t pending = SDMMC.mintsts.val & 0xFFFF;
560     SDMMC.rintsts.val = pending;
561     event.sdmmc_status = pending;
562
563     uint32_t dma_pending = SDMMC.idsts.val;
564     SDMMC.idsts.val = dma_pending;
565     event.dma_status = dma_pending & 0x1f;
566
567     if (pending != 0 || dma_pending != 0) {
568         xQueueSendFromISR(queue, &event, &higher_priority_task_awoken);
569     }
570
571     uint32_t sdio_pending = SDMMC.mintsts.sdio;
572     if (sdio_pending) {
573         // disable the interrupt (no need to clear here, this is done in sdmmc_host_io_wait_int)
574         SDMMC.intmask.sdio &= ~sdio_pending;
575         xSemaphoreGiveFromISR(s_io_intr_event, &higher_priority_task_awoken);
576     }
577
578     if (higher_priority_task_awoken == pdTRUE) {
579         portYIELD_FROM_ISR();
580     }
581 }
582
583 esp_err_t sdmmc_host_pullup_en(int slot, int width)
584 {
585     if (width > sdmmc_slot_info[slot].width) {
586         //in esp32 we only support 8 bit in slot 0, note this is occupied by the flash by default
587         return ESP_ERR_INVALID_ARG;
588     }
589     //according to the spec, the host control the clk, we don't to pull it up here
590     gpio_pullup_en(sdmmc_slot_info[slot].cmd_gpio);
591     gpio_pullup_en(sdmmc_slot_info[slot].d0_gpio);
592     if (width >= 4) {
593         gpio_pullup_en(sdmmc_slot_info[slot].d1_gpio);
594         gpio_pullup_en(sdmmc_slot_info[slot].d2_gpio);
595         gpio_pullup_en(sdmmc_slot_info[slot].d3_gpio);
596     }
597     if (width == 8) {
598         gpio_pullup_en(sdmmc_slot_info[slot].d4_gpio);
599         gpio_pullup_en(sdmmc_slot_info[slot].d5_gpio);
600         gpio_pullup_en(sdmmc_slot_info[slot].d6_gpio);
601         gpio_pullup_en(sdmmc_slot_info[slot].d7_gpio);
602     }
603     return ESP_OK;
604 }