Add HAL_SD_ErrorCallback to handle DMA errors gracefully #685
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Problem
When SD card DMA operations fail (e.g., due to buffer memory placement issues), the
SD_read()andSD_write()functions insd_diskio.cwait in a loop untilSD_TIMEOUTexpires. This can cause the application to hang for several seconds before returning an error.The HAL provides
HAL_SD_ErrorCallback()for this purpose, but it was not implemented, so DMA errors were silently ignored.Solution
This PR adds proper error callback handling:
HAL_SD_ErrorCallback()inbsp_sd_diskio.c- receives HAL errors and forwards to BSP layerBSP_SD_ErrorCallback()insd_diskio.c- sets an error flagError flag checking in
SD_read()/SD_write()wait loops - exits immediately on errorBenefit
DMA errors now return immediately with
RES_ERRORinstead of waiting for timeout.This makes error detection faster, helps developers diagnose SD card issues more quickly.
Also it follows the same pattern as
HAL_SD_TxCpltCallbackandHAL_SD_RxCpltCallback.Testing
Tested on Daisy Patch with FatFS file operations.