From: Nathael Pajani Date: Tue, 28 Mar 2017 13:22:52 +0000 (+0200) Subject: SD/MMC card support going on. Still needs testing. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=54780f9cbdbb536f4426e6dfb5ba7bf01971a836;p=soft%2Flpc122x%2Fcore SD/MMC card support going on. Still needs testing. --- diff --git a/extdrv/sdmmc.c b/extdrv/sdmmc.c index 382f39a..6efc135 100644 --- a/extdrv/sdmmc.c +++ b/extdrv/sdmmc.c @@ -271,6 +271,11 @@ int sdmmc_init_end(struct sdmmc_card* mmc) if (mmc->block_size > MMC_MAX_SECTOR_SIZE) { mmc->block_size = MMC_MAX_SECTOR_SIZE; } + while (mmc->block_size > 1) { + mmc->block_shift++; + mmc->block_size = mmc->block_size >> 1; + } + mmc->block_size = (0x01 << mmc->block_shift); r1 = sdmmc_send_command(mmc, MMC_SET_BLOCKLEN, mmc->block_size, NULL, 0); if (r1 > MMC_R1_IN_IDLE_STATE) { mmc->card_type = MMC_CARDTYPE_UNKNOWN; @@ -301,6 +306,10 @@ int sdmmc_read_block(const struct sdmmc_card* mmc, uint32_t block_number, uint8_ /* Garbage for the SPI out data */ memset(buffer, 0xFF, mmc->block_size); + if (mmc->card_type != MMC_CARDTYPE_SDV2_HC) { + block_number = (block_number << mmc->block_shift); + } + /* Get SPI Bus */ spi_get_mutex(mmc->ssp_bus_num); sdmmc_cs_activate(mmc); diff --git a/include/extdrv/sdmmc.h b/include/extdrv/sdmmc.h index 72e33b9..31cf525 100644 --- a/include/extdrv/sdmmc.h +++ b/include/extdrv/sdmmc.h @@ -34,6 +34,7 @@ struct sdmmc_card { uint8_t ssp_bus_num; uint8_t card_type; uint16_t block_size; + uint8_t block_shift; struct pio chip_select; };