FATFS middleware: invert card detect logic level
I'm using STM32CubeMX 6.5.0, MCU STM32L4A6ZGTx on NUCLEO-L4A6ZG, and an Adafruit 4682 Micro SD SPI or SDIO Card Breakout Board.
On this board, the card detect line (DET) "is connected to GND internally when there's no card, but when one is inserted it is pulled up to 3V with a 4.7kΩ resistor. That means that when the pin's logic level is False there's no card and when it's True there is."
However, the middleware seems to assume the inverse.
FATFS\Target\fatfs_platform.c:
uint8_t BSP_PlatformIsDetected(void) {
uint8_t status = SD_PRESENT;
/* Check SD card detect pin */
if(HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) != GPIO_PIN_RESET)
{
status = SD_NOT_PRESENT;
}
/* USER CODE BEGIN 1 */
/* user code can be inserted here */
/* USER CODE END 1 */
return status;
}What is the best way to solve this?
For now, I just did this:
uint8_t BSP_PlatformIsDetected(void) {
uint8_t status = SD_PRESENT;
/* Check SD card detect pin */
if(HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) != GPIO_PIN_RESET)
{
status = SD_NOT_PRESENT;
}
/* USER CODE BEGIN 1 */
// Adafruit 4682's logic level is False there's no card and when it's True there is
if (status == SD_NOT_PRESENT)
status = SD_PRESENT;
else
status = SD_NOT_PRESENT;
/* USER CODE END 1 */
return status;
}