Skip to content

SD card DMA callbacks not firing - f_write/f_close return FR_DISK_ERR after 30s timeout #684

@CyberDuck79

Description

@CyberDuck79

Hello Electro-smith team !
Here is a problem I have encountered when trying to implement SD card writes on the daisy patch.
I must admit that without an LLM to help me debug I would never found the fix by myself.
The fix is not ideal as polling mode is slightly slower and blocks the CPU during transfers, but for my use case (saving presets), it is sufficient.

Description

When using FatFS with the SDMMC peripheral on Daisy Patch, SD card writes always fail with FR_DISK_ERR (error 1) after a 30-second timeout. The file is created but remains at 0 bytes. Switching to polling mode in sd_diskio.c fixes the issue.

Hardware

  • Board: Daisy Patch
  • SD Card: FAT32, MBR partition scheme (tested with multiple cards)

Problem

The DMA completion callbacks (BSP_SD_WriteCpltCallback / BSP_SD_ReadCpltCallback) in sd_diskio.c are never called. This causes the while loop in SD_write() to spin until SD_TIMEOUT (30 seconds) expires:

// sd_diskio.c line ~220
while((WriteStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT)) {}

WriteStatus stays 0 because BSP_SD_WriteCpltCallback() never fires.

Workaround

Replacing DMA calls with polling versions fixes the issue:

// In SD_read():
// Change: BSP_SD_ReadBlocks_DMA(...)
// To:     BSP_SD_ReadBlocks(..., SD_TIMEOUT)

// In SD_write():
// Change: BSP_SD_WriteBlocks_DMA(...)
// To:     BSP_SD_WriteBlocks(..., SD_TIMEOUT)

Full diff: master...CyberDuck79:libDaisy:fix/sd-polling-mode

Steps to Reproduce

  1. Use the official SDMMC example pattern on Daisy Patch
  2. Try to write any file with f_write() / f_close()
  3. Observe 30-second hang, then FR_DISK_ERR
  4. File exists but size = 0

Environment

  • libDaisy version: master (latest)
  • Toolchain: arm-none-eabi-gcc 14.2.1

Questions

  • Is the SDMMC DMA/interrupt configuration correct for Daisy Patch?
  • Are there known issues with IDMA on STM32H750?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions