2025-05-08 6:32 AM
Hello Community,
I'm working on a storage module using SDcard for my project.
The chip I'm using is STM32H743XIH6.
At present, the SD card has been successfully read and written in the polling (ordinary) mode. However, I have never succeeded in reading and writing the SD card in DMA mode.
Could you please provide a complete illustrated tutorial of the configuration process?
For now, there is no need to introduce fatfs. Just read and write a block in DMA mode.
If possible, please also provide a configured.ioc file and the test code.
PS:
STM32CubeMX Version: 6.14.1
2025-05-08 6:41 AM
Hello @Cai and welcome to the community,
Did you already refer to the example provided by the STM32CubeH7 package under this link: Projects/STM32H743I-EVAL/Applications/FatFs/FatFs_uSD_DMA_Standalone
2025-05-08 6:50 AM
Hello @Cai,
I also suggest exploring the example available at the following link:
STM32CubeH7 SD ReadWrite DMA Example
I hope my answer has helped you. When your question is answered, please select this topic as solution that answered you, it will help others find that answer faster.
Thanks for your contribution.
Dor_RH
2025-05-08 8:49 PM
Sorry, my problem hasn't been solved.
I still don't know how to configure it.
Could you please provide the configuration process in STM32CubeMX?
This is my current configuration.
The following is my test code.
void SD_BasicTest2()
{
puts("Test2 reading and writing SD cards in DMA mode");
/*Save the original data and write it back after testing to prevent damage to the file system*/
uint8_t saveBuffer[512] = {0x00};
uint32_t blockTest = 0xFF;//The block address for testing
uint8_t writeBuffer[512] = {0x00};
for(int i=0; i<sizeof(writeBuffer); i++)
{
writeBuffer[i] = i % 256;
}
uint8_t readBuffer[512] = {0x00};
puts("Starting DMA read/write test");
HAL_Delay(100);
if(HAL_SD_WriteBlocks_DMA(&hsd1, writeBuffer, blockTest, 1) != HAL_OK)
{
puts("Write failed");
return;
}
else
{
printf("Write successful. First 4 bytes: %X %X %X %X\n", writeBuffer[0], writeBuffer[1], writeBuffer[2], writeBuffer[3]);
}
HAL_Delay(100);
if(HAL_SD_ReadBlocks_DMA(&hsd1, readBuffer, blockTest, 1) != HAL_OK)
{
puts("Read failed!");
return;
}
else
{
printf("Read successful. First 4 bytes: %X %X %X %X\n", readBuffer[0], readBuffer[1], readBuffer[2], readBuffer[3]);
}
HAL_Delay(100);
if(memcmp(writeBuffer, readBuffer, sizeof(writeBuffer)) == 0)
{
puts("Data matched. Test passed.");
}
else
{
puts("Data mismatch. Test failed.");
}
puts("Restoring original data to prevent file system corruption");
if(HAL_SD_WriteBlocks_DMA(&hsd1, saveBuffer, blockTest, 1) != HAL_OK)
{
puts("Write failed");
}
HAL_Delay(100);
}
2025-05-14 2:05 AM
Sorry, the problem hasn't been solved.
I'm still not clear about how to configure the DMA function of the STM32H7 series SD card.
2025-05-14 3:27 AM
Hello @Cai,
You might find this post helpful: [STM32H7] How to use SDMMC with MDMA. It may assist you in your application by providing insights and solutions.
I hope this information is helpful. If it resolves your query, please mark this topic as the solution to assist others in finding the answer more quickly. Thank you for your contribution.
Best regards,
Dor_RH
2025-05-16 8:07 PM
Hello, I still haven't succeeded.
May I ask if the use of the DMA function involves the configuration of the MPU?
I haven't enabled the function of the memory protection unit at present.
Can it be used normally if the MPU is not configured?
If configuration is needed, please provide the correct configuration information.