SD/MMC card support going on. Still needs testing.
authorNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 28 Mar 2017 13:22:52 +0000 (15:22 +0200)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 8 Nov 2022 16:03:05 +0000 (17:03 +0100)
extdrv/sdmmc.c
include/extdrv/sdmmc.h

index 382f39a..6efc135 100644 (file)
@@ -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);
index 72e33b9..31cf525 100644 (file)
@@ -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;
 };