@@ -459,13 +459,13 @@ __weak void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd)
459
459
* is managed by polling mode.
460
460
* @param hsd: SD handle
461
461
* @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)
463
463
* @param BlockSize: SD card Data block size
464
464
* @note BlockSize must be 512 bytes.
465
465
* @param NumberOfBlocks: Number of SD blocks to read
466
466
* @retval SD Card error state
467
467
*/
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 )
469
469
{
470
470
SDMMC_CmdInitTypeDef sdmmc_cmdinitstructure ;
471
471
SDMMC_DataInitTypeDef sdmmc_datainitstructure ;
@@ -475,10 +475,16 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
475
475
/* Initialize data control register */
476
476
hsd -> Instance -> DCTRL = 0 ;
477
477
478
+ uint32_t ReadAddr ;
478
479
if (hsd -> CardType == HIGH_CAPACITY_SD_CARD )
479
480
{
480
481
BlockSize = 512 ;
481
- ReadAddr /= 512 ;
482
+ ReadAddr = BlockNumber ;
483
+ }
484
+ else
485
+ {
486
+ // should not overflow for standard-capacity cards
487
+ ReadAddr = BlockNumber * BlockSize ;
482
488
}
483
489
484
490
/* Set Block Size for Card */
@@ -517,7 +523,7 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
517
523
sdmmc_cmdinitstructure .CmdIndex = SD_CMD_READ_SINGLE_BLOCK ;
518
524
}
519
525
520
- sdmmc_cmdinitstructure .Argument = ( uint32_t ) ReadAddr ;
526
+ sdmmc_cmdinitstructure .Argument = ReadAddr ;
521
527
SDMMC_SendCommand (hsd -> Instance , & sdmmc_cmdinitstructure );
522
528
523
529
/* Read block(s) in polling mode */
@@ -635,13 +641,13 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
635
641
* transfer is managed by polling mode.
636
642
* @param hsd: SD handle
637
643
* @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)
639
645
* @param BlockSize: SD card Data block size
640
646
* @note BlockSize must be 512 bytes.
641
647
* @param NumberOfBlocks: Number of SD blocks to write
642
648
* @retval SD Card error state
643
649
*/
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 )
645
651
{
646
652
SDMMC_CmdInitTypeDef sdmmc_cmdinitstructure ;
647
653
SDMMC_DataInitTypeDef sdmmc_datainitstructure ;
@@ -653,10 +659,16 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
653
659
/* Initialize data control register */
654
660
hsd -> Instance -> DCTRL = 0 ;
655
661
662
+ uint32_t WriteAddr ;
656
663
if (hsd -> CardType == HIGH_CAPACITY_SD_CARD )
657
664
{
658
665
BlockSize = 512 ;
659
- WriteAddr /= 512 ;
666
+ WriteAddr = BlockNumber ;
667
+ }
668
+ else
669
+ {
670
+ // should not overflow for standard-capacity cards
671
+ WriteAddr = BlockNumber * BlockSize ;
660
672
}
661
673
662
674
/* Set Block Size for Card */
@@ -686,7 +698,7 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
686
698
sdmmc_cmdinitstructure .CmdIndex = SD_CMD_WRITE_SINGLE_BLOCK ;
687
699
}
688
700
689
- sdmmc_cmdinitstructure .Argument = ( uint32_t ) WriteAddr ;
701
+ sdmmc_cmdinitstructure .Argument = WriteAddr ;
690
702
SDMMC_SendCommand (hsd -> Instance , & sdmmc_cmdinitstructure );
691
703
692
704
/* Check for error conditions */
@@ -845,13 +857,13 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
845
857
* to check the completion of the read process
846
858
* @param hsd: SD handle
847
859
* @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)
849
861
* @param BlockSize: SD card Data block size
850
862
* @note BlockSize must be 512 bytes.
851
863
* @param NumberOfBlocks: Number of blocks to read.
852
864
* @retval SD Card error state
853
865
*/
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 )
855
867
{
856
868
SDMMC_CmdInitTypeDef sdmmc_cmdinitstructure ;
857
869
SDMMC_DataInitTypeDef sdmmc_datainitstructure ;
@@ -895,10 +907,16 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
895
907
/* Enable the DMA Channel */
896
908
HAL_DMA_Start_IT (hsd -> hdmarx , (uint32_t )& hsd -> Instance -> FIFO , (uint32_t )pReadBuffer , (uint32_t )(BlockSize * NumberOfBlocks )/4 );
897
909
910
+ uint32_t ReadAddr ;
898
911
if (hsd -> CardType == HIGH_CAPACITY_SD_CARD )
899
912
{
900
913
BlockSize = 512 ;
901
- ReadAddr /= 512 ;
914
+ ReadAddr = BlockNumber ;
915
+ }
916
+ else
917
+ {
918
+ // should not overflow for standard-capacity cards
919
+ ReadAddr = BlockNumber * BlockSize ;
902
920
}
903
921
904
922
/* Set Block Size for Card */
@@ -938,7 +956,7 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
938
956
sdmmc_cmdinitstructure .CmdIndex = SD_CMD_READ_SINGLE_BLOCK ;
939
957
}
940
958
941
- sdmmc_cmdinitstructure .Argument = ( uint32_t ) ReadAddr ;
959
+ sdmmc_cmdinitstructure .Argument = ReadAddr ;
942
960
SDMMC_SendCommand (hsd -> Instance , & sdmmc_cmdinitstructure );
943
961
944
962
/* Check for error conditions */
@@ -965,13 +983,13 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
965
983
* to check the completion of the write process (by SD current status polling).
966
984
* @param hsd: SD handle
967
985
* @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)
969
987
* @param BlockSize: the SD card Data block size
970
988
* @note BlockSize must be 512 bytes.
971
989
* @param NumberOfBlocks: Number of blocks to write
972
990
* @retval SD Card error state
973
991
*/
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 )
975
993
{
976
994
SDMMC_CmdInitTypeDef sdmmc_cmdinitstructure ;
977
995
SDMMC_DataInitTypeDef sdmmc_datainitstructure ;
@@ -1015,10 +1033,16 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
1015
1033
/* Enable SDMMC DMA transfer */
1016
1034
__HAL_SD_SDMMC_DMA_ENABLE (hsd );
1017
1035
1036
+ uint32_t WriteAddr ;
1018
1037
if (hsd -> CardType == HIGH_CAPACITY_SD_CARD )
1019
1038
{
1020
1039
BlockSize = 512 ;
1021
- WriteAddr /= 512 ;
1040
+ WriteAddr = BlockNumber ;
1041
+ }
1042
+ else
1043
+ {
1044
+ // should not overflow for standard-capacity cards
1045
+ WriteAddr = BlockNumber * BlockSize ;
1022
1046
}
1023
1047
1024
1048
/* Set Block Size for Card */
0 commit comments