Use AzureRTOS ThreadX
This commit is contained in:
@ -300,9 +300,9 @@ static uint32_t SD_FindSCR(SD_HandleTypeDef *hsd, uint32_t *pSCR);
|
||||
static void SD_PowerOFF(SD_HandleTypeDef *hsd);
|
||||
static void SD_Write_IT(SD_HandleTypeDef *hsd);
|
||||
static void SD_Read_IT(SD_HandleTypeDef *hsd);
|
||||
static uint32_t SD_HighSpeed(SD_HandleTypeDef *hsd);
|
||||
static uint32_t SD_SwitchSpeed(SD_HandleTypeDef *hsd, uint32_t SwitchSpeedMode);
|
||||
#if (USE_SD_TRANSCEIVER != 0U)
|
||||
static uint32_t SD_UltraHighSpeed(SD_HandleTypeDef *hsd);
|
||||
static uint32_t SD_UltraHighSpeed(SD_HandleTypeDef *hsd, uint32_t UltraHighSpeedMode);
|
||||
static uint32_t SD_DDR_Mode(SD_HandleTypeDef *hsd);
|
||||
#endif /* USE_SD_TRANSCEIVER */
|
||||
/**
|
||||
@ -470,7 +470,7 @@ HAL_StatusTypeDef HAL_SD_InitCard(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
uint32_t errorstate;
|
||||
SD_InitTypeDef Init;
|
||||
uint32_t sdmmc_clk = 0U;
|
||||
uint32_t sdmmc_clk;
|
||||
|
||||
/* Default SDMMC peripheral configuration for SD card initialization */
|
||||
Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
|
||||
@ -509,8 +509,15 @@ HAL_StatusTypeDef HAL_SD_InitCard(SD_HandleTypeDef *hsd)
|
||||
|
||||
/* wait 74 Cycles: required power up waiting time before starting
|
||||
the SD initialization sequence */
|
||||
sdmmc_clk = sdmmc_clk / (2U * Init.ClockDiv);
|
||||
HAL_Delay(1U + (74U * 1000U / (sdmmc_clk)));
|
||||
if (Init.ClockDiv != 0U)
|
||||
{
|
||||
sdmmc_clk = sdmmc_clk / (2U * Init.ClockDiv);
|
||||
}
|
||||
|
||||
if (sdmmc_clk != 0U)
|
||||
{
|
||||
HAL_Delay(1U + (74U * 1000U / (sdmmc_clk)));
|
||||
}
|
||||
|
||||
/* Identify card operating voltage */
|
||||
errorstate = SD_PowerON(hsd);
|
||||
@ -847,8 +854,8 @@ HAL_StatusTypeDef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint8_t *pData, uint3
|
||||
* @param Timeout: Specify timeout value
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks,
|
||||
uint32_t Timeout)
|
||||
HAL_StatusTypeDef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, const uint8_t *pData, uint32_t BlockAdd,
|
||||
uint32_t NumberOfBlocks, uint32_t Timeout)
|
||||
{
|
||||
SDMMC_DataInitTypeDef config;
|
||||
uint32_t errorstate;
|
||||
@ -857,7 +864,7 @@ HAL_StatusTypeDef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint8_t *pData, uint
|
||||
uint32_t data;
|
||||
uint32_t dataremaining;
|
||||
uint32_t add = BlockAdd;
|
||||
uint8_t *tempbuff = pData;
|
||||
const uint8_t *tempbuff = pData;
|
||||
|
||||
if (NULL == pData)
|
||||
{
|
||||
@ -1129,7 +1136,7 @@ HAL_StatusTypeDef HAL_SD_ReadBlocks_IT(SD_HandleTypeDef *hsd, uint8_t *pData, ui
|
||||
* @param NumberOfBlocks: Number of blocks to write
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SD_WriteBlocks_IT(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd,
|
||||
HAL_StatusTypeDef HAL_SD_WriteBlocks_IT(SD_HandleTypeDef *hsd, const uint8_t *pData, uint32_t BlockAdd,
|
||||
uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDMMC_DataInitTypeDef config;
|
||||
@ -1325,7 +1332,7 @@ HAL_StatusTypeDef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint8_t *pData, u
|
||||
* @param NumberOfBlocks: Number of blocks to write
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd,
|
||||
HAL_StatusTypeDef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, const uint8_t *pData, uint32_t BlockAdd,
|
||||
uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDMMC_DataInitTypeDef config;
|
||||
@ -1854,6 +1861,9 @@ __weak void HAL_SD_DriveTransceiver_1_8V_Callback(FlagStatus status)
|
||||
/**
|
||||
* @brief Register a User SD Callback
|
||||
* To be used instead of the weak (surcharged) predefined callback
|
||||
* @note The HAL_SD_RegisterCallback() may be called before HAL_SD_Init() in
|
||||
* HAL_SD_STATE_RESET to register callbacks for HAL_SD_MSP_INIT_CB_ID
|
||||
* and HAL_SD_MSP_DEINIT_CB_ID.
|
||||
* @param hsd : SD handle
|
||||
* @param CallbackID : ID of the callback to be registered
|
||||
* This parameter can be one of the following values:
|
||||
@ -1882,9 +1892,6 @@ HAL_StatusTypeDef HAL_SD_RegisterCallback(SD_HandleTypeDef *hsd, HAL_SD_Callback
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hsd);
|
||||
|
||||
if (hsd->State == HAL_SD_STATE_READY)
|
||||
{
|
||||
switch (CallbackID)
|
||||
@ -1953,14 +1960,15 @@ HAL_StatusTypeDef HAL_SD_RegisterCallback(SD_HandleTypeDef *hsd, HAL_SD_Callback
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hsd);
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unregister a User SD Callback
|
||||
* SD Callback is redirected to the weak (surcharged) predefined callback
|
||||
* @note The HAL_SD_UnRegisterCallback() may be called before HAL_SD_Init() in
|
||||
* HAL_SD_STATE_RESET to register callbacks for HAL_SD_MSP_INIT_CB_ID
|
||||
* and HAL_SD_MSP_DEINIT_CB_ID.
|
||||
* @param hsd : SD handle
|
||||
* @param CallbackID : ID of the callback to be unregistered
|
||||
* This parameter can be one of the following values:
|
||||
@ -1980,9 +1988,6 @@ HAL_StatusTypeDef HAL_SD_UnRegisterCallback(SD_HandleTypeDef *hsd, HAL_SD_Callba
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hsd);
|
||||
|
||||
if (hsd->State == HAL_SD_STATE_READY)
|
||||
{
|
||||
switch (CallbackID)
|
||||
@ -2051,8 +2056,6 @@ HAL_StatusTypeDef HAL_SD_UnRegisterCallback(SD_HandleTypeDef *hsd, HAL_SD_Callba
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Release Lock */
|
||||
__HAL_UNLOCK(hsd);
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -2400,7 +2403,7 @@ HAL_StatusTypeDef HAL_SD_ConfigWideBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
{
|
||||
SDMMC_InitTypeDef Init;
|
||||
uint32_t errorstate;
|
||||
uint32_t sdmmc_clk = 0U;
|
||||
uint32_t sdmmc_clk;
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
@ -2435,7 +2438,7 @@ HAL_StatusTypeDef HAL_SD_ConfigWideBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
}
|
||||
else
|
||||
{
|
||||
/* MMC Card does not support this feature */
|
||||
/* SD Card does not support this feature */
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
@ -2583,9 +2586,9 @@ HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
{
|
||||
hsd->Instance->CLKCR |= SDMMC_CLKCR_BUSSPEED;
|
||||
/* Enable Ultra High Speed */
|
||||
if (SD_UltraHighSpeed(hsd) != HAL_SD_ERROR_NONE)
|
||||
if (SD_UltraHighSpeed(hsd, SDMMC_SDR104_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
if (SD_HighSpeed(hsd) != HAL_SD_ERROR_NONE)
|
||||
if (SD_SwitchSpeed(hsd, SDMMC_SDR25_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
@ -2595,7 +2598,7 @@ HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
else if (hsd->SdCard.CardSpeed == CARD_HIGH_SPEED)
|
||||
{
|
||||
/* Enable High Speed */
|
||||
if (SD_HighSpeed(hsd) != HAL_SD_ERROR_NONE)
|
||||
if (SD_SwitchSpeed(hsd, SDMMC_SDR25_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
@ -2607,13 +2610,33 @@ HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDMMC_SPEED_MODE_ULTRA:
|
||||
case SDMMC_SPEED_MODE_ULTRA_SDR104:
|
||||
{
|
||||
if ((hsd->SdCard.CardSpeed == CARD_ULTRA_HIGH_SPEED) ||
|
||||
(hsd->SdCard.CardType == CARD_SDHC_SDXC))
|
||||
{
|
||||
/* Enable UltraHigh Speed */
|
||||
if (SD_UltraHighSpeed(hsd) != HAL_SD_ERROR_NONE)
|
||||
if (SD_UltraHighSpeed(hsd, SDMMC_SDR104_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
hsd->Instance->CLKCR |= SDMMC_CLKCR_BUSSPEED;
|
||||
}
|
||||
else
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDMMC_SPEED_MODE_ULTRA_SDR50:
|
||||
{
|
||||
if ((hsd->SdCard.CardSpeed == CARD_ULTRA_HIGH_SPEED) ||
|
||||
(hsd->SdCard.CardType == CARD_SDHC_SDXC))
|
||||
{
|
||||
/* Enable UltraHigh Speed */
|
||||
if (SD_UltraHighSpeed(hsd, SDMMC_SDR50_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
@ -2654,7 +2677,7 @@ HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
(hsd->SdCard.CardType == CARD_SDHC_SDXC))
|
||||
{
|
||||
/* Enable High Speed */
|
||||
if (SD_HighSpeed(hsd) != HAL_SD_ERROR_NONE)
|
||||
if (SD_SwitchSpeed(hsd, SDMMC_SDR25_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
@ -2668,7 +2691,16 @@ HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
break;
|
||||
}
|
||||
case SDMMC_SPEED_MODE_DEFAULT:
|
||||
{
|
||||
/* Switch to default Speed */
|
||||
if (SD_SwitchSpeed(hsd, SDMMC_SDR12_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_PARAM;
|
||||
status = HAL_ERROR;
|
||||
@ -2686,7 +2718,7 @@ HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
(hsd->SdCard.CardType == CARD_SDHC_SDXC))
|
||||
{
|
||||
/* Enable High Speed */
|
||||
if (SD_HighSpeed(hsd) != HAL_SD_ERROR_NONE)
|
||||
if (SD_SwitchSpeed(hsd, SDMMC_SDR25_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
@ -2705,7 +2737,7 @@ HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
(hsd->SdCard.CardType == CARD_SDHC_SDXC))
|
||||
{
|
||||
/* Enable High Speed */
|
||||
if (SD_HighSpeed(hsd) != HAL_SD_ERROR_NONE)
|
||||
if (SD_SwitchSpeed(hsd, SDMMC_SDR25_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
@ -2719,7 +2751,16 @@ HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
break;
|
||||
}
|
||||
case SDMMC_SPEED_MODE_DEFAULT:
|
||||
{
|
||||
/* Switch to default Speed */
|
||||
if (SD_SwitchSpeed(hsd, SDMMC_SDR12_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case SDMMC_SPEED_MODE_ULTRA: /*not valid without transceiver*/
|
||||
default:
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_PARAM;
|
||||
@ -2737,7 +2778,7 @@ HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
(hsd->SdCard.CardType == CARD_SDHC_SDXC))
|
||||
{
|
||||
/* Enable High Speed */
|
||||
if (SD_HighSpeed(hsd) != HAL_SD_ERROR_NONE)
|
||||
if (SD_SwitchSpeed(hsd, SDMMC_SDR25_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
@ -2756,7 +2797,7 @@ HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
(hsd->SdCard.CardType == CARD_SDHC_SDXC))
|
||||
{
|
||||
/* Enable High Speed */
|
||||
if (SD_HighSpeed(hsd) != HAL_SD_ERROR_NONE)
|
||||
if (SD_SwitchSpeed(hsd, SDMMC_SDR25_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
@ -2770,7 +2811,16 @@ HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation(SD_HandleTypeDef *hsd, uint32_t
|
||||
break;
|
||||
}
|
||||
case SDMMC_SPEED_MODE_DEFAULT:
|
||||
{
|
||||
/* Switch to default Speed */
|
||||
if (SD_SwitchSpeed(hsd, SDMMC_SDR12_SWITCH_PATTERN) != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case SDMMC_SPEED_MODE_ULTRA: /*not valid without transceiver*/
|
||||
default:
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_PARAM;
|
||||
@ -2836,35 +2886,94 @@ HAL_SD_CardStateTypeDef HAL_SD_GetCardState(SD_HandleTypeDef *hsd)
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SD_Abort(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
HAL_SD_CardStateTypeDef CardState;
|
||||
uint32_t error_code;
|
||||
uint32_t tickstart;
|
||||
|
||||
/* DIsable All interrupts */
|
||||
__HAL_SD_DISABLE_IT(hsd, SDMMC_IT_DATAEND | SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | \
|
||||
SDMMC_IT_TXUNDERR | SDMMC_IT_RXOVERR);
|
||||
|
||||
/* Clear All flags */
|
||||
__HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_DATA_FLAGS);
|
||||
|
||||
/* If IDMA Context, disable Internal DMA */
|
||||
hsd->Instance->IDMACTRL = SDMMC_DISABLE_IDMA;
|
||||
|
||||
hsd->State = HAL_SD_STATE_READY;
|
||||
|
||||
/* Initialize the SD operation */
|
||||
hsd->Context = SD_CONTEXT_NONE;
|
||||
|
||||
CardState = HAL_SD_GetCardState(hsd);
|
||||
if ((CardState == HAL_SD_CARD_RECEIVING) || (CardState == HAL_SD_CARD_SENDING))
|
||||
if (hsd->State == HAL_SD_STATE_BUSY)
|
||||
{
|
||||
/* DIsable All interrupts */
|
||||
__HAL_SD_DISABLE_IT(hsd, SDMMC_IT_DATAEND | SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | \
|
||||
SDMMC_IT_TXUNDERR | SDMMC_IT_RXOVERR);
|
||||
__SDMMC_CMDTRANS_DISABLE(hsd->Instance);
|
||||
|
||||
/*we will send the CMD12 in all cases in order to stop the data transfers*/
|
||||
/*In case the data transfer just finished , the external memory will not respond and will return HAL_SD_ERROR_CMD_RSP_TIMEOUT*/
|
||||
/*In case the data transfer aborted , the external memory will respond and will return HAL_SD_ERROR_NONE*/
|
||||
/*Other scenario will return HAL_ERROR*/
|
||||
|
||||
hsd->ErrorCode = SDMMC_CmdStopTransfer(hsd->Instance);
|
||||
}
|
||||
if (hsd->ErrorCode != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
error_code = hsd->ErrorCode;
|
||||
if ((error_code != HAL_SD_ERROR_NONE) && (error_code != HAL_SD_ERROR_CMD_RSP_TIMEOUT))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
tickstart = HAL_GetTick();
|
||||
if ((hsd->Instance->DCTRL & SDMMC_DCTRL_DTDIR) == SDMMC_TRANSFER_DIR_TO_CARD)
|
||||
{
|
||||
if (hsd->ErrorCode == HAL_SD_ERROR_NONE)
|
||||
{
|
||||
while(!__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_DABORT | SDMMC_FLAG_BUSYD0END))
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) >= SDMMC_DATATIMEOUT)
|
||||
{
|
||||
hsd->ErrorCode = HAL_SD_ERROR_TIMEOUT;
|
||||
hsd->State = HAL_SD_STATE_READY;
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hsd->ErrorCode == HAL_SD_ERROR_CMD_RSP_TIMEOUT)
|
||||
{
|
||||
while(!__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_DATAEND))
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) >= SDMMC_DATATIMEOUT)
|
||||
{
|
||||
hsd->ErrorCode = HAL_SD_ERROR_TIMEOUT;
|
||||
hsd->State = HAL_SD_STATE_READY;
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((hsd->Instance->DCTRL & SDMMC_DCTRL_DTDIR) == SDMMC_TRANSFER_DIR_TO_SDMMC)
|
||||
{
|
||||
while(!__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_DABORT | SDMMC_FLAG_DATAEND))
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) >= SDMMC_DATATIMEOUT)
|
||||
{
|
||||
hsd->ErrorCode = HAL_SD_ERROR_TIMEOUT;
|
||||
hsd->State = HAL_SD_STATE_READY;
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Nothing to do*/
|
||||
}
|
||||
|
||||
/*The reason of all these while conditions previously is that we need to wait the SDMMC and clear
|
||||
the appropriate flags that will be set depending of the abort/non abort of the memory */
|
||||
/*Not waiting the SDMMC flags will cause the next SDMMC_DISABLE_IDMA to not get cleared
|
||||
and will result in next SDMMC read/write operation to fail */
|
||||
|
||||
/*SDMMC ready for clear data flags*/
|
||||
__HAL_SD_CLEAR_FLAG(hsd, SDMMC_FLAG_BUSYD0END);
|
||||
__HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_DATA_FLAGS);
|
||||
/* If IDMA Context, disable Internal DMA */
|
||||
hsd->Instance->IDMACTRL = SDMMC_DISABLE_IDMA;
|
||||
|
||||
hsd->State = HAL_SD_STATE_READY;
|
||||
|
||||
/* Initialize the SD operation */
|
||||
hsd->Context = SD_CONTEXT_NONE;
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Abort the current transfer and disable the SD (IT mode).
|
||||
* @param hsd: pointer to a SD_HandleTypeDef structure that contains
|
||||
@ -3571,7 +3680,7 @@ static void SD_Write_IT(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
uint32_t count;
|
||||
uint32_t data;
|
||||
uint8_t *tmp;
|
||||
const uint8_t *tmp;
|
||||
|
||||
tmp = hsd->pTxBuffPtr;
|
||||
|
||||
@ -3600,11 +3709,12 @@ static void SD_Write_IT(SD_HandleTypeDef *hsd)
|
||||
* @brief Switches the SD card to High Speed mode.
|
||||
* This API must be used after "Transfer State"
|
||||
* @note This operation should be followed by the configuration
|
||||
* of PLL to have SDMMCCK clock between 50 and 120 MHz
|
||||
* of PLL to have SDMMCCK clock between 25 and 50 MHz
|
||||
* @param hsd: SD handle
|
||||
* @param SwitchSpeedMode: SD speed mode( SDMMC_SDR12_SWITCH_PATTERN, SDMMC_SDR25_SWITCH_PATTERN)
|
||||
* @retval SD Card error state
|
||||
*/
|
||||
uint32_t SD_HighSpeed(SD_HandleTypeDef *hsd)
|
||||
uint32_t SD_SwitchSpeed(SD_HandleTypeDef *hsd, uint32_t SwitchSpeedMode)
|
||||
{
|
||||
uint32_t errorstate = HAL_SD_ERROR_NONE;
|
||||
SDMMC_DataInitTypeDef sdmmc_datainitstructure;
|
||||
@ -3619,7 +3729,7 @@ uint32_t SD_HighSpeed(SD_HandleTypeDef *hsd)
|
||||
return HAL_SD_ERROR_REQUEST_NOT_APPLICABLE;
|
||||
}
|
||||
|
||||
if (hsd->SdCard.CardSpeed == CARD_HIGH_SPEED)
|
||||
if (hsd->SdCard.CardSpeed >= CARD_HIGH_SPEED)
|
||||
{
|
||||
/* Initialize the Data control register */
|
||||
hsd->Instance->DCTRL = 0;
|
||||
@ -3641,7 +3751,7 @@ uint32_t SD_HighSpeed(SD_HandleTypeDef *hsd)
|
||||
(void)SDMMC_ConfigData(hsd->Instance, &sdmmc_datainitstructure);
|
||||
|
||||
|
||||
errorstate = SDMMC_CmdSwitch(hsd->Instance, SDMMC_SDR25_SWITCH_PATTERN);
|
||||
errorstate = SDMMC_CmdSwitch(hsd->Instance, SwitchSpeedMode);
|
||||
if (errorstate != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
return errorstate;
|
||||
@ -3715,9 +3825,10 @@ uint32_t SD_HighSpeed(SD_HandleTypeDef *hsd)
|
||||
* @note This operation should be followed by the configuration
|
||||
* of PLL to have SDMMCCK clock between 50 and 120 MHz
|
||||
* @param hsd: SD handle
|
||||
* @param UltraHighSpeedMode: SD speed mode( SDMMC_SDR50_SWITCH_PATTERN, SDMMC_SDR104_SWITCH_PATTERN)
|
||||
* @retval SD Card error state
|
||||
*/
|
||||
static uint32_t SD_UltraHighSpeed(SD_HandleTypeDef *hsd)
|
||||
static uint32_t SD_UltraHighSpeed(SD_HandleTypeDef *hsd, uint32_t UltraHighSpeedMode)
|
||||
{
|
||||
uint32_t errorstate = HAL_SD_ERROR_NONE;
|
||||
SDMMC_DataInitTypeDef sdmmc_datainitstructure;
|
||||
@ -3756,7 +3867,7 @@ static uint32_t SD_UltraHighSpeed(SD_HandleTypeDef *hsd)
|
||||
return (HAL_SD_ERROR_GENERAL_UNKNOWN_ERR);
|
||||
}
|
||||
|
||||
errorstate = SDMMC_CmdSwitch(hsd->Instance, SDMMC_SDR104_SWITCH_PATTERN);
|
||||
errorstate = SDMMC_CmdSwitch(hsd->Instance, UltraHighSpeedMode);
|
||||
if (errorstate != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
return errorstate;
|
||||
|
||||
Reference in New Issue
Block a user