2018-04-25 04:52 PM
I am a bit of a noob so please excuse me, though I have tried my best here. Some info:
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
2018-04-26 08:11 AM
CubeMX is a veritable cluster when it comes to SDIO + DMA
I might suggest you look at some of the hand-crafted HAL examples, and port those to your board
STM32Cube_FW_F4_V1.21.0\Projects\STM324xG_EVAL\Applications\FatFs\FatFs_uSD
Have SDIO/SDMMC working on a handful of NUCLEO-64 boards, unfortunately not the F411RE
2018-04-26 02:30 PM
Thanks Clive,
I did find a workaround directly related to my findings, renaming those callback functions which fixed the mounting/reading, but I am still failing on f_close if i open a file for editing (DMA error callback is triggered), it looks like the correct DMA stream is being used I guess I need to dig around a bit more into how that all works to find the failure point. I will have another look at the cubemx stuff later and failing that will look at another example like you said. Might be a bit better of a learning experience to pull one of those apart.
2018-08-23 04:30 AM
Hi,
I do have the same issue. Could you please specify how and where you renamed the callback functions?
2019-01-30 05:16 PM
For anyone else getting similar SD card issues with DMA I thought I'd share that it can work. I'm using v5.0 of CubeMX and can confirm that the SD card is working on my STM32F769 discovery board. In MX, you've got to enable DMA for RX and TX as well as the global interrupt, that's the only catch, everything else configures automatically for you. You'll find some code to mount/open/write/read a file in the eval board examples.