AnsweredAssumed Answered

STM32F411-NUCLEO, SD card callback not called

Question asked by thomas.dave on Apr 26, 2018
Latest reply on Apr 26, 2018 by thomas.dave

I am a bit of a noob so please excuse me, though I have tried my best here. Some info:

 

  • NUCLEO-F411RE board
  • STM32CubeMX v 4.25.0
  • STM32F4 package v 1.21.0

 

I have been trying to get a real basic SD card test working using SDIO and cubemx. I have only SYS, RCC, SDIO and FATFS configured in cubemx with default values.

 

My main.c has the following to try to mount my SD card, which is FAT32-formatted and can be read using mbed on an DISCO-STM32F7.

 

/* USER CODE BEGIN 2 */
     FRESULT res;
     res = f_mount(&SDFatFS, SDPath, 1);
     if (res != FR_OK)
     {
          printf("Failed to mount");
     }
  /* USER CODE END 2 */

 

I followed the code line by line and using a salae I can see the SD card responding. I narrowed it down to the read failing when it tries to read the first byte to check if it's an FAT partition. I found the callback set up in the DMA transfer being set in stm32f4xx_hal_sd.c:

 

    /* Set the DMA transfer complete callback */
    hsd->hdmarx->XferCpltCallback = SD_DMAReceiveCplt;

 

I saw that this wasn't being triggered and realized that DMA needed to be enabled in cubeMX, one channel set up for SDIO. With that in place that callback now gets triggered, which in turn calls HAL_SD_RxCpltCallback:

/**
  * @brief Rx Transfer completed callbacks
  * @param hsd Pointer SD handle
  * @retval None
  */

__weak void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hsd);

  /* NOTE : This function should not be modified, when the callback is needed,
            the HAL_SD_RxCpltCallback can be implemented in the user file
   */

}

which looks like it is a dead end?

The read timeout in SD_read requires ReadStatus to be set to escape the loop

 

    while((ReadStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT))
    {
    }

But this is set in a function called BSP_SD_ReadCpltCallback

/**
  * @brief Rx Transfer completed callbacks
  * @param hsd: SD handle
  * @retval None
  */


  /*
   ===============================================================================
    Select the correct function signature depending on your platform.
    please refer to the file "stm32xxxx_eval_sd.h" to verify the correct function
    prototype
   ===============================================================================
  */

//void BSP_SD_ReadCpltCallback(uint32_t SdCard)
void BSP_SD_ReadCpltCallback(void)
{
  ReadStatus = 1;
}

So it looks like the wrong callback is being triggered. Is this a bug in the generation, or am I supposed to do something here?

 

Thanks

Dave

Outcomes