M
Matheus Felipe
I'm prototyping an application using a STM32F407 board that contains a SD Card slot, as depicted below:
The communication is set to be 1 Bit, following the SDIO specification.
The fact is that when I run the "HAL_SD_Init" function from HAL library during the board startup routine, sometimes it works perfectly and my application runs fine (read, write, all operations OK), but sometimes not and it seems totally random and intermittent.
I even surrounded the HAL_SD_Init method with a while statement (for testing purpose only) in a way that the board just continues the startup routine if the SD Initialization was succesful and, in the meanwhile, I keep toggling the card on the slot, inserting and removing it until it magically works and the code continues its execution.
Since the code seems fine, I connected the logic analyzer and tried to analyze an OK and a NOK case in the physical domain:
Final thoughts and observations:
Let me know if there are any questions.
The communication is set to be 1 Bit, following the SDIO specification.
The fact is that when I run the "HAL_SD_Init" function from HAL library during the board startup routine, sometimes it works perfectly and my application runs fine (read, write, all operations OK), but sometimes not and it seems totally random and intermittent.
I even surrounded the HAL_SD_Init method with a while statement (for testing purpose only) in a way that the board just continues the startup routine if the SD Initialization was succesful and, in the meanwhile, I keep toggling the card on the slot, inserting and removing it until it magically works and the code continues its execution.
Code:
while(HAL_SD_Init(&hsd) != HAL_OK);
Since the code seems fine, I connected the logic analyzer and tried to analyze an OK and a NOK case in the physical domain:
OK CASE:
Main remarks:
- Command sequence in Command line (CMD) seems OK - CMD0 sent, CMD8 sent, CMD8 answered as expected, and then everything proceeds normally.
- The Data Line (D0) is maintained in a high-level, idling, as expected for this phase.
NOK CASE:
Main remarks:
- Command sequence in Command line (CMD) seems OK but unanswered - CMD0 sent, CMD8 sent, but NO answer in command line.
- On the other hand, the Data Line (D0) is not idling, but seems to be communicating something (I didn't find anything about this in the SDIO spec).
Final thoughts and observations:
- Once a NOK behavior is ongoing, it's not gonna work if I don't try to remove and reinsert the card physically, i.e., I can keep polling the card infinitely or even turn off the board, wait a few moments and turn it on again. Simply won't work.
- I tried changing the SD CLK to higher and lower values during the initialization phase, but no effect. It continues somewhat random and intermittent.
- I can't figure out what the SD card is trying to return when it doesn't answer my command in the CMD line but does answer something in the D0 line. If contacts were loose, I wouldn't expect the card to return anything.
- The contacts doesn't seem loose or misaligned (visual analysis). I tried to insert it more to the left, more to the right, applying a down-up and up-down pressure, but no pattern detected. So far, no clue.
- This card works fine when inserted into a Micro SD adapter and plugged into my PC.
Let me know if there are any questions.