@@ -461,13 +461,13 @@ __weak void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd)
461461 * is managed by polling mode.
462462 * @param hsd: SD handle
463463 * @param pReadBuffer: pointer to the buffer that will contain the received data
464- * @param ReadAddr: Address from where data is to be read
464+ * @param BlockNumber: Block number from where data is to be read (byte address = BlockNumber * BlockSize)
465465 * @param BlockSize: SD card Data block size
466466 * @note BlockSize must be 512 bytes.
467467 * @param NumberOfBlocks: Number of SD blocks to read
468468 * @retval SD Card error state
469469 */
470- HAL_SD_ErrorTypedef HAL_SD_ReadBlocks (SD_HandleTypeDef * hsd , uint32_t * pReadBuffer , uint64_t ReadAddr , uint32_t BlockSize , uint32_t NumberOfBlocks )
470+ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_BlockNumber (SD_HandleTypeDef * hsd , uint32_t * pReadBuffer , uint32_t BlockNumber , uint32_t BlockSize , uint32_t NumberOfBlocks )
471471{
472472 SDIO_CmdInitTypeDef sdio_cmdinitstructure ;
473473 SDIO_DataInitTypeDef sdio_datainitstructure ;
@@ -477,10 +477,16 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
477477 /* Initialize data control register */
478478 hsd -> Instance -> DCTRL = 0U ;
479479
480+ uint32_t ReadAddr ;
480481 if (hsd -> CardType == HIGH_CAPACITY_SD_CARD )
481482 {
482- BlockSize = 512U ;
483- ReadAddr /= 512U ;
483+ BlockSize = 512 ;
484+ ReadAddr = BlockNumber ;
485+ }
486+ else
487+ {
488+ // should not overflow for standard-capacity cards
489+ ReadAddr = BlockNumber * BlockSize ;
484490 }
485491
486492 /* Set Block Size for Card */
@@ -519,7 +525,7 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
519525 sdio_cmdinitstructure .CmdIndex = SD_CMD_READ_SINGLE_BLOCK ;
520526 }
521527
522- sdio_cmdinitstructure .Argument = ( uint32_t ) ReadAddr ;
528+ sdio_cmdinitstructure .Argument = ReadAddr ;
523529 SDIO_SendCommand (hsd -> Instance , & sdio_cmdinitstructure );
524530
525531 /* Read block(s) in polling mode */
@@ -655,13 +661,13 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
655661 * transfer is managed by polling mode.
656662 * @param hsd: SD handle
657663 * @param pWriteBuffer: pointer to the buffer that will contain the data to transmit
658- * @param WriteAddr: Address from where data is to be written
664+ * @param BlockNumber: Block number to where data is to be written (byte address = BlockNumber * BlockSize)
659665 * @param BlockSize: SD card Data block size
660666 * @note BlockSize must be 512 bytes.
661667 * @param NumberOfBlocks: Number of SD blocks to write
662668 * @retval SD Card error state
663669 */
664- HAL_SD_ErrorTypedef HAL_SD_WriteBlocks (SD_HandleTypeDef * hsd , uint32_t * pWriteBuffer , uint64_t WriteAddr , uint32_t BlockSize , uint32_t NumberOfBlocks )
670+ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_BlockNumber (SD_HandleTypeDef * hsd , uint32_t * pWriteBuffer , uint32_t BlockNumber , uint32_t BlockSize , uint32_t NumberOfBlocks )
665671{
666672 SDIO_CmdInitTypeDef sdio_cmdinitstructure ;
667673 SDIO_DataInitTypeDef sdio_datainitstructure ;
@@ -673,10 +679,16 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
673679 /* Initialize data control register */
674680 hsd -> Instance -> DCTRL = 0U ;
675681
682+ uint32_t WriteAddr ;
676683 if (hsd -> CardType == HIGH_CAPACITY_SD_CARD )
677684 {
678- BlockSize = 512U ;
679- WriteAddr /= 512U ;
685+ BlockSize = 512 ;
686+ WriteAddr = BlockNumber ;
687+ }
688+ else
689+ {
690+ // should not overflow for standard-capacity cards
691+ WriteAddr = BlockNumber * BlockSize ;
680692 }
681693
682694 /* Set Block Size for Card */
@@ -706,7 +718,7 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
706718 sdio_cmdinitstructure .CmdIndex = SD_CMD_WRITE_SINGLE_BLOCK ;
707719 }
708720
709- sdio_cmdinitstructure .Argument = ( uint32_t ) WriteAddr ;
721+ sdio_cmdinitstructure .Argument = WriteAddr ;
710722 SDIO_SendCommand (hsd -> Instance , & sdio_cmdinitstructure );
711723
712724 /* Check for error conditions */
@@ -883,13 +895,13 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
883895 * to check the completion of the read process
884896 * @param hsd: SD handle
885897 * @param pReadBuffer: Pointer to the buffer that will contain the received data
886- * @param ReadAddr: Address from where data is to be read
898+ * @param BlockNumber: Block number from where data is to be read (byte address = BlockNumber * BlockSize)
887899 * @param BlockSize: SD card Data block size
888900 * @note BlockSize must be 512 bytes.
889901 * @param NumberOfBlocks: Number of blocks to read.
890902 * @retval SD Card error state
891903 */
892- HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA (SD_HandleTypeDef * hsd , uint32_t * pReadBuffer , uint64_t ReadAddr , uint32_t BlockSize , uint32_t NumberOfBlocks )
904+ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_BlockNumber_DMA (SD_HandleTypeDef * hsd , uint32_t * pReadBuffer , uint32_t BlockNumber , uint32_t BlockSize , uint32_t NumberOfBlocks )
893905{
894906 SDIO_CmdInitTypeDef sdio_cmdinitstructure ;
895907 SDIO_DataInitTypeDef sdio_datainitstructure ;
@@ -937,10 +949,16 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
937949 /* Enable the DMA Stream */
938950 HAL_DMA_Start_IT (hsd -> hdmarx , (uint32_t )& hsd -> Instance -> FIFO , (uint32_t )pReadBuffer , (uint32_t )(BlockSize * NumberOfBlocks )/4 );
939951
952+ uint32_t ReadAddr ;
940953 if (hsd -> CardType == HIGH_CAPACITY_SD_CARD )
941954 {
942- BlockSize = 512U ;
943- ReadAddr /= 512U ;
955+ BlockSize = 512 ;
956+ ReadAddr = BlockNumber ;
957+ }
958+ else
959+ {
960+ // should not overflow for standard-capacity cards
961+ ReadAddr = BlockNumber * BlockSize ;
944962 }
945963
946964 /* Set Block Size for Card */
@@ -980,7 +998,7 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
980998 sdio_cmdinitstructure .CmdIndex = SD_CMD_READ_SINGLE_BLOCK ;
981999 }
9821000
983- sdio_cmdinitstructure .Argument = ( uint32_t ) ReadAddr ;
1001+ sdio_cmdinitstructure .Argument = ReadAddr ;
9841002 SDIO_SendCommand (hsd -> Instance , & sdio_cmdinitstructure );
9851003
9861004 /* Check for error conditions */
@@ -1007,13 +1025,13 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
10071025 * to check the completion of the write process (by SD current status polling).
10081026 * @param hsd: SD handle
10091027 * @param pWriteBuffer: pointer to the buffer that will contain the data to transmit
1010- * @param WriteAddr: Address from where data is to be read
1028+ * @param BlockNumber: Block number to where data is to be written (byte address = BlockNumber * BlockSize)
10111029 * @param BlockSize: the SD card Data block size
10121030 * @note BlockSize must be 512 bytes.
10131031 * @param NumberOfBlocks: Number of blocks to write
10141032 * @retval SD Card error state
10151033 */
1016- HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA (SD_HandleTypeDef * hsd , uint32_t * pWriteBuffer , uint64_t WriteAddr , uint32_t BlockSize , uint32_t NumberOfBlocks )
1034+ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_BlockNumber_DMA (SD_HandleTypeDef * hsd , uint32_t * pWriteBuffer , uint32_t BlockNumber , uint32_t BlockSize , uint32_t NumberOfBlocks )
10171035{
10181036 SDIO_CmdInitTypeDef sdio_cmdinitstructure ;
10191037 SDIO_DataInitTypeDef sdio_datainitstructure ;
@@ -1061,10 +1079,16 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
10611079 /* Enable SDIO DMA transfer */
10621080 __HAL_SD_SDIO_DMA_ENABLE ();
10631081
1082+ uint32_t WriteAddr ;
10641083 if (hsd -> CardType == HIGH_CAPACITY_SD_CARD )
10651084 {
1066- BlockSize = 512U ;
1067- WriteAddr /= 512U ;
1085+ BlockSize = 512 ;
1086+ WriteAddr = BlockNumber ;
1087+ }
1088+ else
1089+ {
1090+ // should not overflow for standard-capacity cards
1091+ WriteAddr = BlockNumber * BlockSize ;
10681092 }
10691093
10701094 /* Set Block Size for Card */
@@ -1095,7 +1119,7 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
10951119 sdio_cmdinitstructure .CmdIndex = SD_CMD_WRITE_MULT_BLOCK ;
10961120 }
10971121
1098- sdio_cmdinitstructure .Argument = ( uint32_t ) WriteAddr ;
1122+ sdio_cmdinitstructure .Argument = WriteAddr ;
10991123 SDIO_SendCommand (hsd -> Instance , & sdio_cmdinitstructure );
11001124
11011125 /* Check for error conditions */
0 commit comments