Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/util/bsp_sd_diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
BSP_SD_ReadCpltCallback();
}

/**
* @brief SD Error callback
* @param hsd: SD handle
* @retval None
*/
void HAL_SD_ErrorCallback(SD_HandleTypeDef *hsd)
{
BSP_SD_ErrorCallback();
}

/* USER CODE BEGIN CallBacksSection_C */
/**
* @brief BSP SD Abort callback
Expand All @@ -266,6 +276,12 @@ __weak void BSP_SD_WriteCpltCallback(void) {}
* @retval None
*/
__weak void BSP_SD_ReadCpltCallback(void) {}

/**
* @brief BSP SD Error callback
* @retval None
*/
__weak void BSP_SD_ErrorCallback(void) {}
/* USER CODE END CallBacksSection_C */

/**
Expand Down
6 changes: 4 additions & 2 deletions src/util/bsp_sd_diskio.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ uint8_t BSP_SD_IsDetected(void);

Abort the callback */
void BSP_SD_AbortCallback(void);
/** Read complete callback */
void BSP_SD_WriteCpltCallback(void);
/** Write complete callback */
void BSP_SD_WriteCpltCallback(void);
/** Read complete callback */
void BSP_SD_ReadCpltCallback(void);
/** Error callback */
void BSP_SD_ErrorCallback(void);

#endif
/** @} */
24 changes: 18 additions & 6 deletions src/util/sd_diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static volatile DSTATUS Stat = STA_NOINIT;
//static volatile UINT WriteStatus = 0, ReadStatus = 0;
static volatile uint32_t WriteStatus = 0;
static volatile uint32_t ReadStatus = 0;
static volatile uint32_t SdErrorFlag = 0;
/* Private function prototypes -----------------------------------------------*/
static DSTATUS SD_CheckStatus(BYTE lun);
DSTATUS SD_initialize(BYTE);
Expand Down Expand Up @@ -139,6 +140,7 @@ DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
{
DRESULT res = RES_ERROR;
ReadStatus = 0;
SdErrorFlag = 0;
uint32_t timeout;
#if(ENABLE_SD_DMA_CACHE_MAINTENANCE == 1)
uint32_t alignedAddr;
Expand All @@ -151,9 +153,9 @@ DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
{
/* Wait that the reading process is completed or a timeout occurs */
timeout = HAL_GetTick();
while((ReadStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT)) {}
/* incase of a timeout return error */
if(ReadStatus == 0)
while((ReadStatus == 0) && (SdErrorFlag == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT)) {}
/* incase of a timeout or error return error */
if(ReadStatus == 0 || SdErrorFlag != 0)
{
res = RES_ERROR;
}
Expand Down Expand Up @@ -196,6 +198,7 @@ DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
{
DRESULT res = RES_ERROR;
WriteStatus = 0;
SdErrorFlag = 0;
uint32_t timeout;
#if(ENABLE_SD_DMA_CACHE_MAINTENANCE == 1)
uint32_t alignedAddr;
Expand All @@ -221,9 +224,9 @@ DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
{
/* Wait that writing process is completed or a timeout occurs */
timeout = HAL_GetTick();
while((WriteStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT)) {}
/* incase of a timeout return error */
if(WriteStatus == 0)
while((WriteStatus == 0) && (SdErrorFlag == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT)) {}
/* incase of a timeout or error return error */
if(WriteStatus == 0 || SdErrorFlag != 0)
{
res = RES_ERROR;
}
Expand Down Expand Up @@ -320,6 +323,15 @@ void BSP_SD_ReadCpltCallback(void)
//HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, 1);
}

/**
* @brief SD Error callback
* @retval None
*/
void BSP_SD_ErrorCallback(void)
{
SdErrorFlag = 1;
}

// Interrupts -- Not sure these belong here or elsewhere yet.

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Loading