Driver for SDIO peripheral
The SDIO driver provides functions to configure and control SDIO functionalities for communication with SD cards and I/O Devices. Features include:
- Command and data transfer initialization
- Card status and information retrieval
- Write protection control
- Error handling and interrupt status
Configuration Considerations
To initialize and use the SDIO driver:
SDIO Pinmux Configuration
Configures the pin multiplexing for the SDIO interface to ensure proper routing of signals.
SD Card
SDIO Init Operation
Initializes the SDIO module and prepares it for communication.
LOG_INFO(LOG_MOD_SDIO,"SDIO Init Failure!\n");
} else {
LOG_INFO(LOG_MOD_SDIO,"SDIO Init Success!\n");
}
SDIO Host Configuration and Initialization.
Sets up the host-side configuration, including DMA type and initializes the SDIO interface.
.dmaType = CONFIG_SDIO_HOST_DMA_TYPE,
};
LOG_INFO(LOG_MOD_SDIO,"SDIO Config Failure!\n");
} else {
LOG_INFO(LOG_MOD_SDIO,"SDIO Config Success!\n");
}
SDIO SD Card Configuration and Initialization.
Initializes the SD card connected to the specified SDIO instance
#ifdef CONFIG_SDIO_CARD__LOW_VOLTAGE_SIGNALING
.lowVoltageSignaling = true,
#endif
.busWidth = CONFIG_SDIO_CARD_BUS_WIDTH,
.cardType = &cardType,
.rca = &rca,
.cardCapacity = &cardCapacity,
.clockSpeed = CONFIG_SDIO_CLOCK,
.busSpeed = CONFIG_SDIO_SDR50_SPEED,
};
LOG_INFO(LOG_MOD_SDIO,"SDIO Init Card Failure!\n");
} else {
LOG_INFO(LOG_MOD_SDIO,"SDIO Init Card Success!\n");
}
LOG_INFO(LOG_MOD_SDIO,"SDIO Init Complete! \n");
SDIO SD Card Write Operation.
Writes a data block to the SD card using the SDIO interface.
int32_t i;
rxBuff[i] = 0x00;
txBuff[i] = (uint8_t)(rand());
}
data.data = (uint32_t*)txBuff;
SDIO SD Card Read Operation.
Reads a data block from the SD card using the SDIO interface.
data.data = (uint32_t*)rxBuff;
if(data.enableDma == false) {
}
I/O Device
SDIO Init Operation
Initializes the SDIO module and prepares it for communication.
LOG_INFO(LOG_MOD_SDIO,"SDIO Init Failure!\n");
} else {
LOG_INFO(LOG_MOD_SDIO,"SDIO Init Success!\n");
}
SDIO Host Configuration and Initialization.
Sets up the host-side configuration, including DMA type and initializes the SDIO interface.
.dmaType = CONFIG_SDIO_HOST_DMA_TYPE,
};
ret = sdio_host_init_test(
SDIO1, &sdHostConfig);
LOG_INFO(LOG_MOD_SDIO,"SDIO Config Failure!\n");
} else {
LOG_INFO(LOG_MOD_SDIO,"SDIO Config Success!\n");
}
SDIO I/O Device Configuration and Initialization.
Initializes the I/O Device connected to the specified SDIO instance
#ifdef CONFIG_SDIO_CARD__LOW_VOLTAGE_SIGNALING
.lowVoltageSignaling = true,
#endif
.busWidth = CONFIG_SDIO_CARD_BUS_WIDTH,
.cardType = &cardType,
.rca = &rca,
.cardCapacity = &cardCapacity,
.clockSpeed = CONFIG_SDIO_CLOCK,
.busSpeed = CONFIG_SDIO_SDR50_SPEED,
};
ret = sdio_device_init_test(
SDIO1);
LOG_INFO(LOG_MOD_SDIO,"SDIO IO Device Init Failure!\n");
} else {
LOG_INFO(LOG_MOD_SDIO,"SDIO IO Device Init Success!\n");
}
LOG_INFO(LOG_MOD_SDIO,"SDIO Init Complete! \n");
SDIO Direct I/O Transfer Operation (CMD52)
Performs single-byte read/write to a specific register address in the I/O device.
sdio_lock_test(sdio_mutex);
sdio_status_en ret = sdio_sd_cmd52_test(
SDIO1, rw_flag, function_number, raw_flag, reg_addr, data);
if (xSemaphoreTake(sdio_completion_sem, 5000) != pdPASS) {
LOG_ERROR(LOG_MOD_SDIO,"Timeout waiting for CMD52 completion!\n");
}
} else {
LOG_ERROR(LOG_MOD_SDIO, "1st CMD52 failed!\n");
}
sdio_unlock_test(sdio_mutex);
SDIO Extended I/O Transfer Operation (CMD53)
Performs multi-byte (or block) read or write transfer between the host and the I/O device.
sdio_lock_test(sdio_mutex);
sdio_sd_cmd53_test(
SDIO1, read, funcNum, block_mode, opCode, reg_addr, byteCnt, globalBuffer);
LOG_ERROR(LOG_MOD_SDIO, "2nd CMD53 failed!\n");
}
sdio_unlock_test(sdio_mutex);
Cache Handling for SDIO Operations
cache_clean_addr
- Before an SD Card write operation, cache_clean_addr is called to ensure that any data modified in the CPU's cache for the transmit buffer is written back to main memory. This is crucial because the SDIO controller, when using DMA, reads directly from main memory, bypassing the CPU's cache.
cache_invalidate_addr
- After an SD Card read operation, cache_invalidate_addr is called to invalidate the CPU's data cache entries for the receive buffer. This ensures that the CPU will read the newly updated data from main memory, as the SDIO controller (via DMA) writes directly to main memory, bypassing the CPU's cache.
Note:
Incase SDIO DMA is enabled, do not place the read/write data buffers in the DTCM region as SDIO DMA does not have access to it.