cancel
Showing results for 
Search instead for 
Did you mean: 

How to write to SD card over 4G address by HAL?

TLung.1
Associate II

Hi All,

I am using STM32H7 to write the SD card. The SD card is 16GB. But when I call HAL_SD_WriteBlocks, I found it only accept under 4GB(uint32_t) address.

Here is header declaration.

HAL_StatusTypeDef HAL_SD_ReadBlocks   (SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout);

Does anyone have ideal for that?

1 ACCEPTED SOLUTION

Accepted Solutions

It is a block address spanning 2TB, not a byte offset. The SDHC cards use logical block addressing.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3

It is a block address spanning 2TB, not a byte offset. The SDHC cards use logical block addressing.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TLung.1
Associate II

Hi clive,

Does mean I need to leverage by block?

for example:

//assume 1 block = 512 byte
HAL_SD_WriteBlocks(&hsd2, aTxBuffer, 0, 1,2000); 
// = write aTxBuffer into number block 0 (address 0x00000000) by 1 block
HAL_SD_WriteBlocks(&hsd2, aTxBuffer, 1, 1,2000); 
// = write aTxBuffer into number block 1 (address 0x00000200) by 1 block
HAL_SD_WriteBlocks(&hsd2, aTxBuffer, 2, 2,2000); 
// = write aTxBuffer into  number block 2 (address 0x00000400) by 2 block, fill data to address 0x0000400~0x000007FF(2 blocks)

Am I correct for that explanation?

Yes​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..