AnsweredAssumed Answered

Low level SD card access

Question asked by Mark Potts on Jul 22, 2011
Latest reply on Aug 3, 2011 by Mark Potts

 

I am trying to implement low level access (read and write single sectors) from/to an SD card. I have studied the SPI and SD Card sections in the I/O Drivers Guide and the sdcard sample and come up with the following code (including scard.c and sdcard_spi.c plus headers):

 

MCF5XXX_QSPI_INIT_STRUCT _qspi0_init = {
   0,                            /* SPI channel                     */
   MCF5XXX_QSPI_QDR_QSPI_CS0,    /* Chip Select 0                   */
   SPI_DEVICE_MASTER_MODE,       /* Transfer mode                   */
   BSP_QSPI_BAUDRATE,            /* SPI Baud rate register value    */
   BSP_SYSTEM_CLOCK/2,           /* Clock Speed                     */
   SPI_CLK_POL_PHA_MODE0,        /* SPI clock phase                 */
   BSP_QSPI_RX_BUFFER_SIZE,      /* Rx Buffer Size (interrupt only) */
   BSP_QSPI_TX_BUFFER_SIZE       /* Tx Buffer Size (interrupt only) */
};

SDCARD_INIT_STRUCT _sdcard0_init = {
    _io_sdcard_spi_init,
    _io_sdcard_spi_read_block,
    _io_sdcard_spi_write_block,
    MCF5XXX_QSPI_QDR_QSPI_CS0
};
   
  _mcf5xxx_qspi_polled_install("spi0:", &_qspi0_init);
  spifd = fopen("spi0:", SPI_FLAG_HALF_DUPLEX);
  rc = _io_sdcard_install("sdcard:", &_sdcard0_init, spifd);
  rc = _io_sdcard_spi_init(spifd));
  rc = _io_sdcard_open(spifd, "", "");
  rc = _io_sdcard_write_blocks(spifd, buffer, n);
  rc = _io_sdcard_read_blocks(spifd, buffer, n);

On execution the code hangs in _io_sdcard_spi_init(). Any suggestions as to possible causes appreciated.

 

Mark

Outcomes