Astra MCU SDK Peripheral Driver Library
Loading...
Searching...
No Matches

Topics

 Macro Definitions
 Macro Definitions for SDIO Driver.
 Enumerated Types
 Enumerated Types for SDIO Driver.
 Data Structures
 Data Structures for SDIO Driver.
 Functions
 Functions for SDIO Driver.

Detailed Description

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.

pinmux_set_pin_function(SD0_CMD, SD0_CMD__SD0_CMD);
pinmux_set_pin_function(SD0_CLK, SD0_CLK__SD0_CLK);

SD Card

SDIO Init Operation

Initializes the SDIO module and prepares it for communication.

if (ret != SDIO_OK) {
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.

const sdio_config_t sdHostConfig = {
.dmaType = CONFIG_SDIO_HOST_DMA_TYPE,
};
ret = sdio_config(SDIO0, &sdHostConfig);
if (ret != SDIO_OK) {
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

sdio_sd_card_config_t sdCardConfig = {
#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,
};
/* Initialize the card */
ret = sdio_sd_card_init(SDIO0, &sdCardConfig );
if (ret != SDIO_OK) {
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.

/*Populate data*/
int32_t i;
for (i = 0; i < SDIO_BLOCK_SIZE ; i++) {
rxBuff[i] = 0x00;
txBuff[i] = (uint8_t)(rand());
}
/*force TX buffer into memory*/
cache_clean_addr((uint32_t*)&txBuff[0], SDIO_BLOCK_SIZE);
data.data = (uint32_t*)txBuff; /* The pointer to data to write. */
ret = sdio_sd_card_write(SDIO0,&data); /* Write data to the card. */

SDIO SD Card Read Operation.

Reads a data block from the SD card using the SDIO interface.

data.data = (uint32_t*)rxBuff; /* The pointer to data to read. */
ret = sdio_sd_card_read(SDIO0, &data); /* Read data from the card. */
/*force read buffer from memory*/
if(data.enableDma == false) {
cache_clean_addr((uint32_t*)&rxBuff[0], SDIO_BLOCK_SIZE);
}
cache_invalidate_addr(CACHE_TYPE_DATA, (void *)rxBuff, SDIO_BLOCK_SIZE);

I/O Device

SDIO Init Operation

Initializes the SDIO module and prepares it for communication.

if (ret != SDIO_OK) {
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.

sdio_config_t sdHostConfig = {
.dmaType = CONFIG_SDIO_HOST_DMA_TYPE,
};
ret = sdio_host_init_test(SDIO1, &sdHostConfig);
if (ret != SDIO_OK) {
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

sdio_sd_card_config_t sdCardConfig = {
#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,
};
/* Initialize the IO Device */
ret = sdio_device_init_test(SDIO1);
if (ret != SDIO_OK) {
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 (SDIO_OK == ret) {
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);
if (SDIO_OK != ret) {
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.