Skip to content

Commit 722cc23

Browse files
committed
fix(sdmmc): fix reset of pins above slot width
Closes espressif#15328
1 parent 36ae237 commit 722cc23

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
@@ -849,16 +849,30 @@ static int sdmmc_host_decrease_init_slot_num(void)
849849
#endif
850850
}
851851

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

0 commit comments

Comments
 (0)