is it a bug in the UC3B's sd_mmc_spi_get_capacity() ?

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

in the function sd_mmc_spi_get_capacity() in the file sd_mmc_spi.c,

the following code:

  // compute last block addr
  sd_mmc_spi_last_block_address = ((U32)(c_size + 1) * (U32)((1 << (c_size_mult + 2)))) - 1;
  if (read_bl_len > 9)  // 9 means 2^9 = 512b
    sd_mmc_spi_last_block_address <<= (read_bl_len - 9);

  // compute card capacity in bytes
  capacity = (1 << read_bl_len) * (sd_mmc_spi_last_block_address + 1);

I think in this function sd_mmc_spi_last_block_address is considered as block size of 512B,so in case of "read_bl_len > 9", shouldn't the calculation be:

sd_mmc_spi_last_block_address++; // because of previous - 1
sd_mmc_spi_last_block_address <<= (read_bl_len - 9);
sd_mmc_spi_last_block_address--;

what do you think?