sources/common/libs/STM32Cube_F4/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_mmc.c
HAL_StatusTypeDef HAL_MMC_WriteBlocks_IT(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)
{
  SDIO_DataInitTypeDef config;
  uint32_t errorstate;
  uint32_t add = BlockAdd;

  if(NULL == pData)
  {
    hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM;
    return HAL_ERROR;
  }

  if(hmmc->State == HAL_MMC_STATE_READY)
  {
    hmmc->ErrorCode = HAL_MMC_ERROR_NONE;

    if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
    {
      hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
      return HAL_ERROR;
    }

    hmmc->State = HAL_MMC_STATE_BUSY;

    /* Initialize data control register */
    hmmc->Instance->DCTRL = 0U;

    hmmc->pTxBuffPtr = pData;
    hmmc->TxXferSize = MMC_BLOCKSIZE * NumberOfBlocks;

    /* Enable transfer interrupts */
#if defined(SDIO_STA_STBITERR)
    __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR | SDIO_IT_DATAEND | SDIO_FLAG_TXFIFOHE | SDIO_IT_STBITERR));
#else /* SDIO_STA_STBITERR not defined */
    __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR | SDIO_IT_DATAEND | SDIO_FLAG_TXFIFOHE));
#endif /* SDIO_STA_STBITERR */

    if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
    {
      add *= 512U;
    }

    /* Write Blocks in Polling mode */
    if(NumberOfBlocks > 1U)
    {
      hmmc->Context = (MMC_CONTEXT_WRITE_MULTIPLE_BLOCK| MMC_CONTEXT_IT);

      /* Write Multi Block command */
      errorstate = SDMMC_CmdWriteMultiBlock(hmmc->Instance, add);
    }
    else
    {
      hmmc->Context = (MMC_CONTEXT_WRITE_SINGLE_BLOCK | MMC_CONTEXT_IT);

      /* Write Single Block command */
      errorstate = SDMMC_CmdWriteSingleBlock(hmmc->Instance, add);
    }
    if(errorstate != HAL_MMC_ERROR_NONE)
    {
      /* Clear all the static flags */
      __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS);
      hmmc->ErrorCode |= errorstate;
      hmmc->State = HAL_MMC_STATE_READY;
      return HAL_ERROR;
    }

    /* Configure the MMC DPSM (Data Path State Machine) */ 
    config.DataTimeOut   = SDMMC_DATATIMEOUT;
    config.DataLength    = MMC_BLOCKSIZE * NumberOfBlocks;
    config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B;
    config.TransferDir   = SDIO_TRANSFER_DIR_TO_CARD;
    config.TransferMode  = SDIO_TRANSFER_MODE_BLOCK;
    config.DPSM          = SDIO_DPSM_ENABLE;
    (void)SDIO_ConfigData(hmmc->Instance, &config);
    
    return HAL_OK;
  }
  else
  {
    return HAL_BUSY;
  }
}
/**
  * @brief  Writes block(s) to a specified address in a card. The Data transfer
  *         is managed in interrupt mode.
  * @note   This API should be followed by a check on the card state through
  *         HAL_MMC_GetCardState().
  * @note   You could also check the IT transfer process through the MMC Tx
  *         interrupt event.
  * @param  hmmc: Pointer to MMC handle
  * @param  pData: Pointer to the buffer that will contain the data to transmit
  * @param  BlockAdd: Block Address where data will be written
  * @param  NumberOfBlocks: Number of blocks to write
  * @retval HAL status
  */
@brief  Writes block(s) to a specified address in a card. The Data transfer
is managed in interrupt mode.
@note   This API should be followed by a check on the card state through
HAL_MMC_GetCardState().
@note   You could also check the IT transfer process through the MMC Tx
interrupt event.
@brief Writes block ( s ) to a specified address in a card . The Data transfer is managed in interrupt mode . @note This API should be followed by a check on the card state through HAL_MMC_GetCardState () . @note You could also check the IT transfer process through the MMC Tx interrupt event .
HAL_StatusTypeDef HAL_MMC_WriteBlocks_IT(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)
{
  SDIO_DataInitTypeDef config;
  uint32_t errorstate;
  uint32_t add = BlockAdd;
  if(NULL == pData)
  {
    hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM;
    return HAL_ERROR;
  }
  if(hmmc->State == HAL_MMC_STATE_READY)
  {
    hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
    if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
    {
      hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
      return HAL_ERROR;
    }
    hmmc->State = HAL_MMC_STATE_BUSY;
    hmmc->Instance->DCTRL = 0U;
    hmmc->pTxBuffPtr = pData;
    hmmc->TxXferSize = MMC_BLOCKSIZE * NumberOfBlocks;
#if defined(SDIO_STA_STBITERR)
    __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR | SDIO_IT_DATAEND | SDIO_FLAG_TXFIFOHE | SDIO_IT_STBITERR));
#else 
    __HAL_MMC_ENABLE_IT(hmmc, (SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR | SDIO_IT_DATAEND | SDIO_FLAG_TXFIFOHE));
#endif 
    if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
    {
      add *= 512U;
    }
    if(NumberOfBlocks > 1U)
    {
      hmmc->Context = (MMC_CONTEXT_WRITE_MULTIPLE_BLOCK| MMC_CONTEXT_IT);
      errorstate = SDMMC_CmdWriteMultiBlock(hmmc->Instance, add);
    }
    else
    {
      hmmc->Context = (MMC_CONTEXT_WRITE_SINGLE_BLOCK | MMC_CONTEXT_IT);
      errorstate = SDMMC_CmdWriteSingleBlock(hmmc->Instance, add);
    }
    if(errorstate != HAL_MMC_ERROR_NONE)
    {
      __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS);
      hmmc->ErrorCode |= errorstate;
      hmmc->State = HAL_MMC_STATE_READY;
      return HAL_ERROR;
    }
    config.DataTimeOut   = SDMMC_DATATIMEOUT;
    config.DataLength    = MMC_BLOCKSIZE * NumberOfBlocks;
    config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B;
    config.TransferDir   = SDIO_TRANSFER_DIR_TO_CARD;
    config.TransferMode  = SDIO_TRANSFER_MODE_BLOCK;
    config.DPSM          = SDIO_DPSM_ENABLE;
    (void)SDIO_ConfigData(hmmc->Instance, &config);
    return HAL_OK;
  }
  else
  {
    return HAL_BUSY;
  }
}
HAL_StatusTypeDef HAL_MMC_WriteBlocks_IT ( MMC_HandleTypeDef * hmmc , uint8_t * pData , uint32_t BlockAdd , uint32_t NumberOfBlocks ) { SDIO_DataInitTypeDef config ; uint32_t errorstate ; uint32_t add = BlockAdd ; if ( NULL == pData ) { hmmc -> ErrorCode |= HAL_MMC_ERROR_PARAM ; return HAL_ERROR ; } if ( hmmc -> State == HAL_MMC_STATE_READY ) { hmmc -> ErrorCode = HAL_MMC_ERROR_NONE ; if ( ( BlockAdd + NumberOfBlocks ) > ( hmmc -> MmcCard . LogBlockNbr ) ) { hmmc -> ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE ; return HAL_ERROR ; } hmmc -> State = HAL_MMC_STATE_BUSY ; hmmc -> Instance -> DCTRL = 0U ; hmmc -> pTxBuffPtr = pData ; hmmc -> TxXferSize = MMC_BLOCKSIZE * NumberOfBlocks ; #if defined ( SDIO_STA_STBITERR ) __HAL_MMC_ENABLE_IT ( hmmc , ( SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR | SDIO_IT_DATAEND | SDIO_FLAG_TXFIFOHE | SDIO_IT_STBITERR ) ) ; #else __HAL_MMC_ENABLE_IT ( hmmc , ( SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_TXUNDERR | SDIO_IT_DATAEND | SDIO_FLAG_TXFIFOHE ) ) ; #endif if ( ( hmmc -> MmcCard . CardType ) != MMC_HIGH_CAPACITY_CARD ) { add *= 512U ; } if ( NumberOfBlocks > 1U ) { hmmc -> Context = ( MMC_CONTEXT_WRITE_MULTIPLE_BLOCK | MMC_CONTEXT_IT ) ; errorstate = SDMMC_CmdWriteMultiBlock ( hmmc -> Instance , add ) ; } else { hmmc -> Context = ( MMC_CONTEXT_WRITE_SINGLE_BLOCK | MMC_CONTEXT_IT ) ; errorstate = SDMMC_CmdWriteSingleBlock ( hmmc -> Instance , add ) ; } if ( errorstate != HAL_MMC_ERROR_NONE ) { __HAL_MMC_CLEAR_FLAG ( hmmc , SDIO_STATIC_FLAGS ) ; hmmc -> ErrorCode |= errorstate ; hmmc -> State = HAL_MMC_STATE_READY ; return HAL_ERROR ; } config . DataTimeOut = SDMMC_DATATIMEOUT ; config . DataLength = MMC_BLOCKSIZE * NumberOfBlocks ; config . DataBlockSize = SDIO_DATABLOCK_SIZE_512B ; config . TransferDir = SDIO_TRANSFER_DIR_TO_CARD ; config . TransferMode = SDIO_TRANSFER_MODE_BLOCK ; config . DPSM = SDIO_DPSM_ENABLE ; ( void ) SDIO_ConfigData ( hmmc -> Instance , & config ) ; return HAL_OK ; } else { return HAL_BUSY ; } }
@brief  Writes block(s) to a specified address in a card.
@brief Writes block ( s ) to a specified address in a card .
/* Initialize data control register */ /* Enable transfer interrupts */ /* SDIO_STA_STBITERR not defined */ /* SDIO_STA_STBITERR */ /* Write Blocks in Polling mode */ /* Write Multi Block command */ /* Write Single Block command */ /* Clear all the static flags */ /* Configure the MMC DPSM (Data Path State Machine) */