Add HAL_SD_ErrorCallback to handle DMA errors gracefully#685
Open
CyberDuck79 wants to merge 1 commit intoelectro-smith:masterfrom
Open
Add HAL_SD_ErrorCallback to handle DMA errors gracefully#685CyberDuck79 wants to merge 1 commit intoelectro-smith:masterfrom
CyberDuck79 wants to merge 1 commit intoelectro-smith:masterfrom
Conversation
Without this callback, SD card DMA errors cause the wait loops in SD_read() and SD_write() to spin until timeout (SD_TIMEOUT), which can take several seconds. This adds: - HAL_SD_ErrorCallback() in bsp_sd_diskio.c that calls BSP_SD_ErrorCallback() - BSP_SD_ErrorCallback() in sd_diskio.c that sets an error flag - Error flag checking in SD_read() and SD_write() wait loops Now when a DMA error occurs (e.g., buffer in wrong memory region), the functions return immediately with an error instead of hanging.
Collaborator
|
Thanks for the contribution! This looks solid to me. I'll give this a quick test sometime before the end of the week, but based on the changes I don't expect any issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.