Skip to main content
Graduate
February 19, 2024
Question

SD-Card function BSP_SD_IsDetected backwards?

  • February 19, 2024
  • 3 replies
  • 2476 views

It looks like the BSP_SD_IsDetected function from the sample codes is working backwards.

 

According to the SD-Card spec this pin has a weak pullup (50 kΩ) inside the card. So the STM32 should have a weaker pull down on the pin and detect the presence of the card if there is a high on the pin.

But the sample code activates the pull up and checks for a low as the indicator of the SD-Card presence.

    This topic has been closed for replies.

    3 replies

    Super User
    February 19, 2024

    >SD-Card spec this pin has a weak pullup (50 kΩ) inside the card

    Source please ?

    afaik

    Micro SD-cards - we talk about - right ?

    Here the card holder usually has a switch to case/gnd, so its easy to detect a card-is-in , ie with a pin+pullup connected to this switch. Other way is just send command -- and wait for response, or not.

    Cd is this card-detect pin:

    AScha3_0-1708373384712.png

    AScha3_0-1708375979331.png

     

    Graduate
    February 19, 2024

    Source: Simplified Physical Layer Specification

    https://www.sdcard.org/downloads/pls/pdf/?p=Part1_Physical_Layer_Simplified_Specification_Ver9.10.jpg&f=Part1PhysicalLayerSimplifiedSpecificationVer9.10Fin_20231201.pdf&e=EN_SS9_1

     

    That is pin 1 on SD/miniSD and Pin 2 on micro.

     

    While the other options may wirk too, detecting the card presence via the CD/Dat3 pin is what the sample code does.

    Graduate II
    February 19, 2024

    Most sockets have a mechanical switch which grounds when a card is in the socket. It's rather rare for one to use the pull-up in the card itself, as again most sockets for SDIO/SDMMC need pull-ups for signal integrity with pins changing direction in 4-bit modes, and not using 1-bit modes beyond initialization.

    Graduate
    February 20, 2024

    Please, this question is about the sample code, not about the SD-Card specs or various sockets.

    So again: The sample code for the F7 series seems to do the card detection wrong. I wonder if this has ever been tested?

    Here is the function:

    uint8_t BSP_SD_IsDetected(void)

    {

    __IO uint8_t status = SD_PRESENT;

     

    /* Check SD card detect pin */

    if (HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) == GPIO_PIN_SET)

    {

    status = SD_NOT_PRESENT;

    }

     

    return status;

    }

     

    So it definitely decides that the card is not present when the CD-pin is high. In the definitions the D3/CD pin is defined as the SD_DETECT_PIN and the internal pullup of the microcontroller is activated. This definitely can never work.

    Super User
    February 20, 2024

    Use this button to properly post source code:

    AndrewNeil_0-1708425709012.png