@ -449,13 +449,13 @@ __weak void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd)
* is managed by polling mode .
* is managed by polling mode .
* @ param hsd : SD handle
* @ param hsd : SD handle
* @ param pReadBuffer : pointer to the buffer that will contain the received data
* @ param pReadBuffer : pointer to the buffer that will contain the received data
* @ param ReadAddr : Address from where data is to be read
* @ param BlockNumber : Block number from where data is to be read ( byte address = BlockNumber * BlockSize )
* @ param BlockSize : SD card Data block size
* @ param BlockSize : SD card Data block size
* This parameter should be 512
* This parameter should be 512
* @ param NumberOfBlocks : Number of SD blocks to read
* @ param NumberOfBlocks : Number of SD blocks to read
* @ retval SD Card error state
* @ retval SD Card error state
*/
*/
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks ( SD_HandleTypeDef * hsd , uint32_t * pReadBuffer , uint64_t ReadAdd r , uint32_t BlockSize , uint32_t NumberOfBlocks )
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_BlockNumber ( SD_HandleTypeDef * hsd , uint32_t * pReadBuffer , uint32_t BlockNumbe r , uint32_t BlockSize , uint32_t NumberOfBlocks )
{
{
SDIO_CmdInitTypeDef sdio_cmdinitstructure ;
SDIO_CmdInitTypeDef sdio_cmdinitstructure ;
SDIO_DataInitTypeDef sdio_datainitstructure ;
SDIO_DataInitTypeDef sdio_datainitstructure ;
@ -465,10 +465,16 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
/* Initialize data control register */
/* Initialize data control register */
hsd - > Instance - > DCTRL = 0 ;
hsd - > Instance - > DCTRL = 0 ;
uint32_t ReadAddr ;
if ( hsd - > CardType = = HIGH_CAPACITY_SD_CARD )
if ( hsd - > CardType = = HIGH_CAPACITY_SD_CARD )
{
{
BlockSize = 512 ;
BlockSize = 512 ;
ReadAddr / = 512 ;
ReadAddr = BlockNumber ;
}
else
{
// should not overflow for standard-capacity cards
ReadAddr = BlockNumber * BlockSize ;
}
}
/* Set Block Size for Card */
/* Set Block Size for Card */
@ -507,7 +513,7 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
sdio_cmdinitstructure . CmdIndex = SD_CMD_READ_SINGLE_BLOCK ;
sdio_cmdinitstructure . CmdIndex = SD_CMD_READ_SINGLE_BLOCK ;
}
}
sdio_cmdinitstructure . Argument = ( uint32_t ) ReadAddr ;
sdio_cmdinitstructure . Argument = ReadAddr ;
SDIO_SendCommand ( hsd - > Instance , & sdio_cmdinitstructure ) ;
SDIO_SendCommand ( hsd - > Instance , & sdio_cmdinitstructure ) ;
/* Read block(s) in polling mode */
/* Read block(s) in polling mode */
@ -633,13 +639,13 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
* transfer is managed by polling mode .
* transfer is managed by polling mode .
* @ param hsd : SD handle
* @ param hsd : SD handle
* @ param pWriteBuffer : pointer to the buffer that will contain the data to transmit
* @ param pWriteBuffer : pointer to the buffer that will contain the data to transmit
* @ param WriteAddr : Address from where data is to be written
* @ param BlockNumber : Block number to where data is to be written ( byte address = BlockNumber * BlockSize )
* @ param BlockSize : SD card Data block size
* @ param BlockSize : SD card Data block size
* This parameter should be 512.
* This parameter should be 512.
* @ param NumberOfBlocks : Number of SD blocks to write
* @ param NumberOfBlocks : Number of SD blocks to write
* @ retval SD Card error state
* @ retval SD Card error state
*/
*/
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks ( SD_HandleTypeDef * hsd , uint32_t * pWriteBuffer , uint64_t WriteAdd r , uint32_t BlockSize , uint32_t NumberOfBlocks )
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_BlockNumber ( SD_HandleTypeDef * hsd , uint32_t * pWriteBuffer , uint32_t BlockNumbe r , uint32_t BlockSize , uint32_t NumberOfBlocks )
{
{
SDIO_CmdInitTypeDef sdio_cmdinitstructure ;
SDIO_CmdInitTypeDef sdio_cmdinitstructure ;
SDIO_DataInitTypeDef sdio_datainitstructure ;
SDIO_DataInitTypeDef sdio_datainitstructure ;
@ -651,10 +657,16 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
/* Initialize data control register */
/* Initialize data control register */
hsd - > Instance - > DCTRL = 0 ;
hsd - > Instance - > DCTRL = 0 ;
uint32_t WriteAddr ;
if ( hsd - > CardType = = HIGH_CAPACITY_SD_CARD )
if ( hsd - > CardType = = HIGH_CAPACITY_SD_CARD )
{
{
BlockSize = 512 ;
BlockSize = 512 ;
WriteAddr / = 512 ;
WriteAddr = BlockNumber ;
}
else
{
// should not overflow for standard-capacity cards
WriteAddr = BlockNumber * BlockSize ;
}
}
/* Set Block Size for Card */
/* Set Block Size for Card */
@ -684,7 +696,7 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
sdio_cmdinitstructure . CmdIndex = SD_CMD_WRITE_SINGLE_BLOCK ;
sdio_cmdinitstructure . CmdIndex = SD_CMD_WRITE_SINGLE_BLOCK ;
}
}
sdio_cmdinitstructure . Argument = ( uint32_t ) WriteAddr ;
sdio_cmdinitstructure . Argument = WriteAddr ;
SDIO_SendCommand ( hsd - > Instance , & sdio_cmdinitstructure ) ;
SDIO_SendCommand ( hsd - > Instance , & sdio_cmdinitstructure ) ;
/* Check for error conditions */
/* Check for error conditions */
@ -851,13 +863,13 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
* to check the completion of the read process
* to check the completion of the read process
* @ param hsd : SD handle
* @ param hsd : SD handle
* @ param pReadBuffer : Pointer to the buffer that will contain the received data
* @ param pReadBuffer : Pointer to the buffer that will contain the received data
* @ param ReadAddr : Address from where data is to be read
* @ param BlockNumber : Block number from where data is to be read ( byte address = BlockNumber * BlockSize )
* @ param BlockSize : SD card Data block size
* @ param BlockSize : SD card Data block size
* This paramater should be 512.
* This paramater should be 512.
* @ param NumberOfBlocks : Number of blocks to read .
* @ param NumberOfBlocks : Number of blocks to read .
* @ retval SD Card error state
* @ retval SD Card error state
*/
*/
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA ( SD_HandleTypeDef * hsd , uint32_t * pReadBuffer , uint64_t ReadAdd r , uint32_t BlockSize , uint32_t NumberOfBlocks )
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_BlockNumber_ DMA ( SD_HandleTypeDef * hsd , uint32_t * pReadBuffer , uint32_t BlockNumbe r , uint32_t BlockSize , uint32_t NumberOfBlocks )
{
{
SDIO_CmdInitTypeDef sdio_cmdinitstructure ;
SDIO_CmdInitTypeDef sdio_cmdinitstructure ;
SDIO_DataInitTypeDef sdio_datainitstructure ;
SDIO_DataInitTypeDef sdio_datainitstructure ;
@ -898,10 +910,16 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
/* Enable the DMA Stream */
/* Enable the DMA Stream */
HAL_DMA_Start_IT ( hsd - > hdmarx , ( uint32_t ) & hsd - > Instance - > FIFO , ( uint32_t ) pReadBuffer , ( uint32_t ) ( BlockSize * NumberOfBlocks ) ) ;
HAL_DMA_Start_IT ( hsd - > hdmarx , ( uint32_t ) & hsd - > Instance - > FIFO , ( uint32_t ) pReadBuffer , ( uint32_t ) ( BlockSize * NumberOfBlocks ) ) ;
uint32_t ReadAddr ;
if ( hsd - > CardType = = HIGH_CAPACITY_SD_CARD )
if ( hsd - > CardType = = HIGH_CAPACITY_SD_CARD )
{
{
BlockSize = 512 ;
BlockSize = 512 ;
ReadAddr / = 512 ;
ReadAddr = BlockNumber ;
}
else
{
// should not overflow for standard-capacity cards
ReadAddr = BlockNumber * BlockSize ;
}
}
/* Set Block Size for Card */
/* Set Block Size for Card */
@ -941,7 +959,7 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
sdio_cmdinitstructure . CmdIndex = SD_CMD_READ_SINGLE_BLOCK ;
sdio_cmdinitstructure . CmdIndex = SD_CMD_READ_SINGLE_BLOCK ;
}
}
sdio_cmdinitstructure . Argument = ( uint32_t ) ReadAddr ;
sdio_cmdinitstructure . Argument = ReadAddr ;
SDIO_SendCommand ( hsd - > Instance , & sdio_cmdinitstructure ) ;
SDIO_SendCommand ( hsd - > Instance , & sdio_cmdinitstructure ) ;
/* Check for error conditions */
/* Check for error conditions */
@ -968,13 +986,13 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
* to check the completion of the write process ( by SD current status polling ) .
* to check the completion of the write process ( by SD current status polling ) .
* @ param hsd : SD handle
* @ param hsd : SD handle
* @ param pWriteBuffer : pointer to the buffer that will contain the data to transmit
* @ param pWriteBuffer : pointer to the buffer that will contain the data to transmit
* @ param WriteAddr : Address from where data is to be read
* @ param BlockNumber : Block number to where data is to be w ritt en ( byte address = BlockNumber * BlockSize )
* @ param BlockSize : the SD card Data block size
* @ param BlockSize : the SD card Data block size
* This parameter should be 512.
* This parameter should be 512.
* @ param NumberOfBlocks : Number of blocks to write
* @ param NumberOfBlocks : Number of blocks to write
* @ retval SD Card error state
* @ retval SD Card error state
*/
*/
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA ( SD_HandleTypeDef * hsd , uint32_t * pWriteBuffer , uint64_t WriteAdd r , uint32_t BlockSize , uint32_t NumberOfBlocks )
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_BlockNumber_ DMA ( SD_HandleTypeDef * hsd , uint32_t * pWriteBuffer , uint32_t BlockNumbe r , uint32_t BlockSize , uint32_t NumberOfBlocks )
{
{
SDIO_CmdInitTypeDef sdio_cmdinitstructure ;
SDIO_CmdInitTypeDef sdio_cmdinitstructure ;
SDIO_DataInitTypeDef sdio_datainitstructure ;
SDIO_DataInitTypeDef sdio_datainitstructure ;
@ -1015,10 +1033,16 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
/* Enable SDIO DMA transfer */
/* Enable SDIO DMA transfer */
__HAL_SD_SDIO_DMA_ENABLE ( ) ;
__HAL_SD_SDIO_DMA_ENABLE ( ) ;
uint32_t WriteAddr ;
if ( hsd - > CardType = = HIGH_CAPACITY_SD_CARD )
if ( hsd - > CardType = = HIGH_CAPACITY_SD_CARD )
{
{
BlockSize = 512 ;
BlockSize = 512 ;
WriteAddr / = 512 ;
WriteAddr = BlockNumber ;
}
else
{
// should not overflow for standard-capacity cards
WriteAddr = BlockNumber * BlockSize ;
}
}
/* Set Block Size for Card */
/* Set Block Size for Card */
@ -1049,7 +1073,7 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
sdio_cmdinitstructure . CmdIndex = SD_CMD_WRITE_MULT_BLOCK ;
sdio_cmdinitstructure . CmdIndex = SD_CMD_WRITE_MULT_BLOCK ;
}
}
sdio_cmdinitstructure . Argument = ( uint32_t ) WriteAddr ;
sdio_cmdinitstructure . Argument = WriteAddr ;
SDIO_SendCommand ( hsd - > Instance , & sdio_cmdinitstructure ) ;
SDIO_SendCommand ( hsd - > Instance , & sdio_cmdinitstructure ) ;
/* Check for error conditions */
/* Check for error conditions */