Possible errors in the implementation of "hal_sd" and "fatfs"
- January 9, 2022
- 2 replies
- 1535 views
Hello,
I use the current tools: STM32CubeIDE 1.8.0, STM32CubeMX 6.4.0 and STM32Cube_FW_H7_V1.9.1.
I have a couple of issues with current implementation of the connection between SDMMC and FATFS:
The first problem in the platform driver "fatfs_platform.c, function" BSP_PlatformIsDetected ":
This code queries
if (HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) != GPIO_PIN_RESET)but my card reader (direct connection between the card slot and the default pins of the SDMMC1 interface and 3.3V supply) returns "GPIO_PIN_SET" for this pin if the card is in the slot.
I don't know if it is a specific fault of my card reader (Adafruit 4682 - “MicroSD SPI or SDIO Card Breakout Board�?), so I changed the code and don't want to investigate it any further.
The second problem is much more serious. During the initialization the "SD_SendSDStatus" procedure is called (see attachment) and here it doesn't leave the status query loop ("stm32h7xx_hal_sd.c", lines 3258ff):
/* Get status data */
while (!__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXOVERR | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_DATAEND))
{
if (__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXFIFOHF))
{
for (count = 0U; count < 8U; count++)
{
*pData = SDMMC_ReadFIFO(hsd->Instance);
pData++;
}
}
if ((HAL_GetTick() - tickstart) >= SDMMC_DATATIMEOUT)
{
return HAL_SD_ERROR_TIMEOUT;
}
}The code seems to be illogical to me: it should wait until these 4 bits are cleared, but instead it waits until one of these bits is set (one of these errors occurs)! Or am I reading this code wrong? This loop runs with a timeout of about one year ... Really, I don't want to wait so long.
In addition, according to some sources (also "AN5200 - Getting Started with STM32H7 Series SDMMC host controller") and examples from the Internet, some parameters for DMA and MDMA must be set/changed in STM32CubeMX, but I cannot enter or change anything there. I can only activate the interrupts for SDMMC1 interface in NVIC settings.
Can somebody help me to get it running?
Thanks in advance,
Michael
