cancel
Showing results for 
Search instead for 
Did you mean: 

How to check from firmware whether SD card inserted in slot ?

vadim2
Associate II
Posted on July 31, 2017 at 18:48

Hi, engineers. I am currently working on project, containing SD card. My HW is custom chinese board with STM23f407VET6 mounted and microSD slot connected to SDIO (proper pullup resistors seem to be in place). I made some auto-generated project skeleton (necessary hal and ll drivers, fatfs) with cubeMX, but I can't figure out from the HAL docs, how to perform software check, whether card is inserted into holder. Moreover, I don't see any clear examples from cubeF4 package, which would give me clear answer. Experiments on hardware still gave me no anser - HAL_SD_InitCard() returns HAL_OK without any card inserted in slot, wth? Will appreciate, if someone explains me where I messed up.

5 REPLIES 5
Posted on July 31, 2017 at 20:07

>>

My HW is custom chinese board with STM23f407VET6 mounted and microSD slot connected to SDIO (proper pullup resistors seem to be in place)

Unfortunately that gives us about zero insight into the design, or board in question...

So figure out what GPIO is committed to the Card Detect switch on the socket, and apply that understanding to the code being generated.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Danish1
Lead II
Posted on July 31, 2017 at 22:02

Not all MicroSD sockets have hardware card-detect. And even if it does, it might not be wired to a GPIO line.

SD cards have a built-in resistor to aid card-detect on CD/DAT3. This resistor is nominally 50 kOhm* and goes between this pin and Vcc (unless/until you issue the command to turn it off).

So if your 'proper pull-up' includes a >=270 k pull-down on CD/DAT3, you can detect the insertion of a card by when this pin goes high. This is what I do.

If you don't have any resistor on that line, you can 'poll' the pin by driving it low and then turning it to a floating input and seeing if it goes high within an interval consistent with charging a few pF of pcb track by the built-in resistor.

*I think the spec is between 10 k and 90 k.

My information came from NXP AN10911 which was referenced from 

https://hackaday.io/project/1347-fpga-computereval-board/log/9878-microsd-fatfs-in-dma

 which also suggested the polling technique.

Hope this helps,

Danish

Posted on August 01, 2017 at 03:31

I'd say the odds are better than 60/40, but there are admittedly some bone-head designs out there, for the most part even the laziest ones just copied a good working design.

These had some reasonably thoughtful design, and did.

https://community.st.com/0D50X00009XkgXwSAJ

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 01, 2017 at 08:54

That switch is available and properly connected. Actually you referenced my board from vcc-gnd.com in your comment below, it is almost same, except MCU is  

STM23f407VET6

. I think I was little bit unclear in my question: how do i check card availability only with SDIO interface. For example I have one damaged microSD in my desk, so if it is inserted into the slot, the switch will react, but that SD card behaves like tiny piece of plastic - it doesn't even consume anything. So after switch on that slot is closed, how do I check is that card OK?
Posted on August 01, 2017 at 19:36

STM23?

The board in question is using an 

STM32F407VET6 

>>

how do I check is that card OK?

At a command level, if it doesn't respond to the initial commands and configuration at 400KHz, then assume it's not working. The card also returns size, geometry, speed information, review that also.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..