Skip to content

Commit f8f40ad

Browse files
committed
fix(sdmmc): fix reset of pins above slot width
Closes #15328
1 parent 2e708d1 commit f8f40ad

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

components/esp_driver_sdmmc/src/sdmmc_host.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -851,16 +851,30 @@ static int sdmmc_host_decrease_init_slot_num(void)
851851
#endif
852852
}
853853

854+
static void reset_pin_if_valid(gpio_num_t gpio_num)
855+
{
856+
if (gpio_num != GPIO_NUM_NC && GPIO_IS_VALID_GPIO(gpio_num)) {
857+
gpio_reset_pin(gpio_num);
858+
}
859+
}
860+
854861
static void sdmmc_host_deinit_slot_internal(int slot)
855862
{
856-
int8_t gpio_pin_num;
857863
sdmmc_slot_io_info_t* gpio = &s_host_ctx.slot_ctx[slot].slot_gpio_num;
858864
// Disconnect signals and reset used GPIO pins
859-
for (size_t i = 0; i < (sizeof(gpio->val) / (sizeof(gpio->val[0]))); i++) {
860-
gpio_pin_num = gpio->val[i];
861-
if (gpio_pin_num != GPIO_NUM_NC && GPIO_IS_VALID_GPIO(gpio_pin_num)) {
862-
gpio_reset_pin(gpio_pin_num);
863-
}
865+
reset_pin_if_valid(gpio->clk);
866+
reset_pin_if_valid(gpio->cmd);
867+
reset_pin_if_valid(gpio->d0);
868+
if (s_host_ctx.slot_ctx[slot].slot_width >= 4) {
869+
reset_pin_if_valid(gpio->d1);
870+
reset_pin_if_valid(gpio->d2);
871+
reset_pin_if_valid(gpio->d3);
872+
}
873+
if (s_host_ctx.slot_ctx[slot].slot_width == 8) {
874+
reset_pin_if_valid(gpio->d4);
875+
reset_pin_if_valid(gpio->d5);
876+
reset_pin_if_valid(gpio->d6);
877+
reset_pin_if_valid(gpio->d7);
864878
}
865879
// Reset the slot context
866880
memset(&(s_host_ctx.slot_ctx[slot]), 0, sizeof(slot_ctx_t));

0 commit comments

Comments
 (0)