return sdmmc_send_command(mmc, index, arg, NULL, 0);
}
+#define MMC_TO_SPI_BYTES 10 /* We need at least 74 bit : 10 x 8 bits is OK */
void sdmmc_set_card_to_spi_mode(const struct sdmmc_card* mmc)
{
- int i = 0;
+ uint8_t mmcdata[MMC_TO_SPI_BYTES];
+
/* Get SPI Bus */
spi_get_mutex(mmc->ssp_bus_num);
- /* Set SPI pins to GPIO mode */
- set_pins(mmc->pin_cfg_mode_gpio);
- /* Configure GPIOs */
+ /* Configure Chip Sslect GPIO */
config_gpio(&(mmc->chip_select), LPC_IO_MODE_PULL_UP, GPIO_DIR_OUT, 1);
- config_gpio(&(mmc->sclk), LPC_IO_MODE_PULL_UP, GPIO_DIR_OUT, 1);
- config_gpio(&(mmc->mosi), LPC_IO_MODE_PULL_UP, GPIO_DIR_OUT, 1);
/* Toggle SCLK to get 74 clock cycles while holding MOSI and CS high */
+ /* CS high */
gpio_set(mmc->chip_select);
- gpio_set(mmc->mosi);
- for (i = 0; i < (80 * 2); i++) {
- gpio_toggle(mmc->sclk);
- }
-
- /* Set SPI pins to GPIO mode */
- set_pins(mmc->pin_cfg_mode_spi);
+ /* Send 10 bytes of 0xFF, which makes MOSI High */
+ memset(mmcdata, 0xFF, MMC_TO_SPI_BYTES);
+ spi_transfer_multiple_frames(mmc->ssp_bus_num, mmcdata, NULL, MMC_TO_SPI_BYTES, 8);
/* Release SPI Bus */
spi_release_mutex(mmc->ssp_bus_num);