@@ -459,13 +459,13 @@ __weak void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd)
459459 * is managed by polling mode.
460460 * @param hsd: SD handle
461461 * @param pReadBuffer: pointer to the buffer that will contain the received data
462- * @param ReadAddr: Address from where data is to be read
462+ * @param BlockNumber: Block number from where data is to be read (byte address = BlockNumber * BlockSize)
463463 * @param BlockSize: SD card Data block size
464464 * @note BlockSize must be 512 bytes.
465465 * @param NumberOfBlocks: Number of SD blocks to read
466466 * @retval SD Card error state
467467 */
468- HAL_SD_ErrorTypedef HAL_SD_ReadBlocks (SD_HandleTypeDef * hsd , uint32_t * pReadBuffer , uint64_t ReadAddr , uint32_t BlockSize , uint32_t NumberOfBlocks )
468+ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_BlockNumber (SD_HandleTypeDef * hsd , uint32_t * pReadBuffer , uint32_t BlockNumber , uint32_t BlockSize , uint32_t NumberOfBlocks )
469469{
470470 SDMMC_CmdInitTypeDef sdmmc_cmdinitstructure ;
471471 SDMMC_DataInitTypeDef sdmmc_datainitstructure ;
@@ -475,10 +475,16 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
475475 /* Initialize data control register */
476476 hsd -> Instance -> DCTRL = 0 ;
477477
478+ uint32_t ReadAddr ;
478479 if (hsd -> CardType == HIGH_CAPACITY_SD_CARD )
479480 {
480481 BlockSize = 512 ;
481- ReadAddr /= 512 ;
482+ ReadAddr = BlockNumber ;
483+ }
484+ else
485+ {
486+ // should not overflow for standard-capacity cards
487+ ReadAddr = BlockNumber * BlockSize ;
482488 }
483489
484490 /* Set Block Size for Card */
@@ -517,7 +523,7 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
517523 sdmmc_cmdinitstructure .CmdIndex = SD_CMD_READ_SINGLE_BLOCK ;
518524 }
519525
520- sdmmc_cmdinitstructure .Argument = ( uint32_t ) ReadAddr ;
526+ sdmmc_cmdinitstructure .Argument = ReadAddr ;
521527 SDMMC_SendCommand (hsd -> Instance , & sdmmc_cmdinitstructure );
522528
523529 /* Read block(s) in polling mode */
@@ -635,13 +641,13 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
635641 * transfer is managed by polling mode.
636642 * @param hsd: SD handle
637643 * @param pWriteBuffer: pointer to the buffer that will contain the data to transmit
638- * @param WriteAddr: Address from where data is to be written
644+ * @param BlockNumber: Block number to where data is to be written (byte address = BlockNumber * BlockSize)
639645 * @param BlockSize: SD card Data block size
640646 * @note BlockSize must be 512 bytes.
641647 * @param NumberOfBlocks: Number of SD blocks to write
642648 * @retval SD Card error state
643649 */
644- HAL_SD_ErrorTypedef HAL_SD_WriteBlocks (SD_HandleTypeDef * hsd , uint32_t * pWriteBuffer , uint64_t WriteAddr , uint32_t BlockSize , uint32_t NumberOfBlocks )
650+ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_BlockNumber (SD_HandleTypeDef * hsd , uint32_t * pWriteBuffer , uint32_t BlockNumber , uint32_t BlockSize , uint32_t NumberOfBlocks )
645651{
646652 SDMMC_CmdInitTypeDef sdmmc_cmdinitstructure ;
647653 SDMMC_DataInitTypeDef sdmmc_datainitstructure ;
@@ -653,10 +659,16 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
653659 /* Initialize data control register */
654660 hsd -> Instance -> DCTRL = 0 ;
655661
662+ uint32_t WriteAddr ;
656663 if (hsd -> CardType == HIGH_CAPACITY_SD_CARD )
657664 {
658665 BlockSize = 512 ;
659- WriteAddr /= 512 ;
666+ WriteAddr = BlockNumber ;
667+ }
668+ else
669+ {
670+ // should not overflow for standard-capacity cards
671+ WriteAddr = BlockNumber * BlockSize ;
660672 }
661673
662674 /* Set Block Size for Card */
@@ -686,7 +698,7 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
686698 sdmmc_cmdinitstructure .CmdIndex = SD_CMD_WRITE_SINGLE_BLOCK ;
687699 }
688700
689- sdmmc_cmdinitstructure .Argument = ( uint32_t ) WriteAddr ;
701+ sdmmc_cmdinitstructure .Argument = WriteAddr ;
690702 SDMMC_SendCommand (hsd -> Instance , & sdmmc_cmdinitstructure );
691703
692704 /* Check for error conditions */
@@ -845,13 +857,13 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
845857 * to check the completion of the read process
846858 * @param hsd: SD handle
847859 * @param pReadBuffer: Pointer to the buffer that will contain the received data
848- * @param ReadAddr: Address from where data is to be read
860+ * @param BlockNumber: Block number from where data is to be read (byte address = BlockNumber * BlockSize)
849861 * @param BlockSize: SD card Data block size
850862 * @note BlockSize must be 512 bytes.
851863 * @param NumberOfBlocks: Number of blocks to read.
852864 * @retval SD Card error state
853865 */
854- HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA (SD_HandleTypeDef * hsd , uint32_t * pReadBuffer , uint64_t ReadAddr , uint32_t BlockSize , uint32_t NumberOfBlocks )
866+ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_BlockNumber_DMA (SD_HandleTypeDef * hsd , uint32_t * pReadBuffer , uint32_t BlockNumber , uint32_t BlockSize , uint32_t NumberOfBlocks )
855867{
856868 SDMMC_CmdInitTypeDef sdmmc_cmdinitstructure ;
857869 SDMMC_DataInitTypeDef sdmmc_datainitstructure ;
@@ -895,10 +907,16 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
895907 /* Enable the DMA Channel */
896908 HAL_DMA_Start_IT (hsd -> hdmarx , (uint32_t )& hsd -> Instance -> FIFO , (uint32_t )pReadBuffer , (uint32_t )(BlockSize * NumberOfBlocks )/4 );
897909
910+ uint32_t ReadAddr ;
898911 if (hsd -> CardType == HIGH_CAPACITY_SD_CARD )
899912 {
900913 BlockSize = 512 ;
901- ReadAddr /= 512 ;
914+ ReadAddr = BlockNumber ;
915+ }
916+ else
917+ {
918+ // should not overflow for standard-capacity cards
919+ ReadAddr = BlockNumber * BlockSize ;
902920 }
903921
904922 /* Set Block Size for Card */
@@ -938,7 +956,7 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
938956 sdmmc_cmdinitstructure .CmdIndex = SD_CMD_READ_SINGLE_BLOCK ;
939957 }
940958
941- sdmmc_cmdinitstructure .Argument = ( uint32_t ) ReadAddr ;
959+ sdmmc_cmdinitstructure .Argument = ReadAddr ;
942960 SDMMC_SendCommand (hsd -> Instance , & sdmmc_cmdinitstructure );
943961
944962 /* Check for error conditions */
@@ -965,13 +983,13 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
965983 * to check the completion of the write process (by SD current status polling).
966984 * @param hsd: SD handle
967985 * @param pWriteBuffer: pointer to the buffer that will contain the data to transmit
968- * @param WriteAddr: Address from where data is to be read
986+ * @param @param BlockNumber: Block number to where data is to be written (byte address = BlockNumber * BlockSize)
969987 * @param BlockSize: the SD card Data block size
970988 * @note BlockSize must be 512 bytes.
971989 * @param NumberOfBlocks: Number of blocks to write
972990 * @retval SD Card error state
973991 */
974- HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA (SD_HandleTypeDef * hsd , uint32_t * pWriteBuffer , uint64_t WriteAddr , uint32_t BlockSize , uint32_t NumberOfBlocks )
992+ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_BlockNumber_DMA (SD_HandleTypeDef * hsd , uint32_t * pWriteBuffer , uint32_t BlockNumber , uint32_t BlockSize , uint32_t NumberOfBlocks )
975993{
976994 SDMMC_CmdInitTypeDef sdmmc_cmdinitstructure ;
977995 SDMMC_DataInitTypeDef sdmmc_datainitstructure ;
@@ -1015,10 +1033,16 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
10151033 /* Enable SDMMC DMA transfer */
10161034 __HAL_SD_SDMMC_DMA_ENABLE (hsd );
10171035
1036+ uint32_t WriteAddr ;
10181037 if (hsd -> CardType == HIGH_CAPACITY_SD_CARD )
10191038 {
10201039 BlockSize = 512 ;
1021- WriteAddr /= 512 ;
1040+ WriteAddr = BlockNumber ;
1041+ }
1042+ else
1043+ {
1044+ // should not overflow for standard-capacity cards
1045+ WriteAddr = BlockNumber * BlockSize ;
10221046 }
10231047
10241048 /* Set Block Size for Card */
0 commit comments