2015-09-18 10:24 AM
Hi ST,
When configuring the FatFS in Platform settings, I can configure the pin for card detect function. When using this config, following code in generated: uint8_t BSP_SD_IsDetected(void) { __IO uint8_t status = SD_PRESENT; /* Check SD card detect pin */ if (HAL_GPIO_ReadPin(SD_PORT,SD_PIN) == GPIO_PIN_RESET) { status = SD_NOT_PRESENT; } return status; } but this code is wrong because of wrong polarity. The CD pin of the socket (all I know) make a short to GND when card is inserted. So the function returns oposite status of the real situation. Either the polarity have to be adjustable or the code snipet have to be reversed. Thanks, Osto #cube-bug-fatfs2015-09-19 06:58 AM
This is technically not a bug always.
Some of card socket uses 2 pins for card detect, like switch. One to desired polarity and one to microcontroller. Desired polarity will be on MCU pin when card is inserted.I agree with you, at least they should add option in CubeMX to select which polarity you use.2015-09-22 09:49 AM
Hi guys,
It is true that the function BSP_SD_IsDetected() is implemented in differents ways from one example to another depending on the hardware. However, if the user generates a code with CubeMx after enabling Fatfs/SDIO, the function is empty and user can implement it as he wants. so, there is no need to add polarity. -Shahrzad-