cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in HAL_SD Capacity calculation

robert-hartung
Associate II
Posted on September 09, 2015 at 14:12

In the HAL Code the Capacity is calculated differently for Low Speed and High Speed Cards.

Low Speed cards use this code:

pCardInfo->CardCapacity  = (pCardInfo->SD_csd.DeviceSize + 1) ;

    pCardInfo->CardCapacity *= (1 << (pCardInfo->SD_csd.DeviceSizeMul + 2));

    pCardInfo->CardBlockSize = 1 << (pCardInfo->SD_csd.RdBlockLen);

    pCardInfo->CardCapacity *= pCardInfo->CardBlockSize;

While High Speed Cards use this:

pCardInfo->CardCapacity  = ((pCardInfo->SD_csd.DeviceSize + 1)) * 512 * 1024;

It should be either:

pCardInfo->CardCapacity  = ((uint64_t) (pCardInfo->SD_csd.DeviceSize + 1)) * 512 * 1024;

or

pCardInfo->CardCapacity  = (pCardInfo->SD_csd.DeviceSize + 1));

pCardInfo->CardCapacity *= 1024;

pCardInfo->CardCapacity *= pCardInfo->CardBlockSize;

To avoid the overflow in uint32_t, because DeviceSize is a uint32_t itself.

- Robert

#sd #hal #bug #!bug
7 REPLIES 7
Nesrine M_O
Lead II
Posted on September 11, 2015 at 15:58

Hi Robert,

Could you precise in which HAL library you have found the issue. So, we can verify it.

-Syrine-

robert-hartung
Associate II
Posted on October 12, 2015 at 14:54

Hi Syrine,

I am referring to the HAL SD library (stm32f2xx_hal_sd.c in my case) in function

HAL_SD_ErrorTypedef

HAL_SD_Get_CardInfo(

SD_HandleTypeDef

*hsd,

HAL_SD_CardInfoTypedef

*pCardInfo)

- Robert

Nesrine M_O
Lead II
Posted on October 13, 2015 at 10:13

Hi Robert,

I will check this issue with our development team & come back to you.Sorry for the inconvenience may bring.

-Syrine-

Lori B.
Associate III
Posted on April 06, 2016 at 14:42

It would be great to here an update on this.

I'm working on a eMMC project (still no MMC support in HAL driver by the way) and this bug is still here in Get_CardInfo function.

Nesrine M_O
Lead II
Posted on April 06, 2016 at 15:36

Hi lori.b,

•Please check the last release of the STM32CubeF2 firmware package (1.3.0), the issue is already fixed.

•Regarding your question about MMC, I confirm that there is a plan to support it on HAL but the driver is not yet available.

-Syrine-
Lori B.
Associate III
Posted on April 06, 2016 at 15:59

Hi Syrine, thanks for the reply.

I checked and it was fixed indeed, my fault. I was looking and my costumized version of the function for eMMCs instead of the original one.

I still have a lot of issues trying to interface eMMC though.

I hope to see the driver implementation soon!

Lori B.
Associate III
Posted on May 24, 2016 at 10:33

Any update on this?

Is there a realease date for the MMC driver?