STM32L4 HAL SDIO File operations with FATFS using DMA.
I am trying to perform SD Card file operations using STM32 HAL in STM32L451RCT6. I have been successful in mounting the SD Card, but read and write operations are not working. Here are the details of my IOC Configuration:
1. FatFS Configuration




2. SDMMC Configuration




3. Clock configuration (Note: Since I am using UART and I2C as well, their clocks are also configured.

Here is the code implementation:
MX_SDMMC1_SD_Init();
MX_FATFS_Init();
if (f_mount(&SDFatFS, "", 1) != FR_OK) {
Error_Handler();
}
if(HAL_SD_GetCardInfo(&hsd1, &card_info) != HAL_OK) {
Error_Handler();
}
if(HAL_SD_GetCardStatus(&hsd1, &card_status) != HAL_OK) {
Error_Handler();
}

The remaining code is where the problem occurs and it goes into the error handler:
if (f_open(&myFile, "sample.txt", FA_CREATE_ALWAYS | FA_WRITE | FA_READ) != FR_OK) {
Error_Handler();
}
if (f_write(&myFile, "sample text", strlen("sample text"), &byteCount) != FR_OK) {
Error_Handler();
}
if (f_close(&myFile) != FR_OK) {
Error_Handler();
}
When I call f_open() and f_write(), it is not implementing the sdmmc interrupt callback and gets stuck in the SD_Read or SD_Write() function until the timeout of 30 seconds. In the below code snippet, the WriteStatus is updated to 1 in the BSP_SD_WriteCpltCallback() function.

Can someone please identify and tell me, what I am doing wrong?
Thanks in advance.
Regards,
Kunaal
