Skip to content

Commit 832e10a

Browse files
committed
mimxrt/sdcard: Fix deadlock in sdcard_power_off when no card present.
The sdcard_power_off function was unconditionally sending GO_IDLE_STATE command even when the card was never successfully initialized or not present. This caused a deadlock in USDHC_WaitCommandDone which has an infinite loop waiting for command completion. The fix checks card->state->initialized before attempting to send the command, preventing communication with non-existent hardware. Signed-off-by: Andrew Leech <[email protected]>
1 parent 2762fe6 commit 832e10a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ports/mimxrt/sdcard.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,11 @@ bool sdcard_power_on(mimxrt_sdcard_obj_t *card) {
986986
}
987987

988988
bool sdcard_power_off(mimxrt_sdcard_obj_t *card) {
989-
(void)sdcard_cmd_go_idle_state(card);
989+
// Only send GO_IDLE_STATE command if card was successfully initialized
990+
// Sending commands to a non-existent card will deadlock waiting for response
991+
if (card->state->initialized) {
992+
(void)sdcard_cmd_go_idle_state(card);
993+
}
990994

991995
// Reset card bus clock
992996
USDHC_SetDataBusWidth(card->usdhc_inst, kUSDHC_DataBusWidth1Bit);

0 commit comments

Comments
 (0)