cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f4-Discovery SDIO problems

tavish
Associate II
Posted on July 12, 2012 at 13:52

Hi, I have been trying to get SDIO to work on an STM32f4-Discovery board using the std-periph library and the mass storage class example from the USB device library. I was able to get SDIO+FatFs+USB to work but it works very unreliably. I have found a couple of bugs in the library code like the

SD_LowLevel_DMA_TxConfig

(..) and

SD_LowLevel_DMA_RxConfig

(..) functions ignoring the Buffersize argument and setting it to 0. Also the usage of the SD card driver (

stm324xg_eval_sdio_sd.c

) is as

Status = SD_WriteMultiBlocks(buffer, address, 512, NUMBEROFBLOCKS);

Status = SD_WaitWriteOperation();

while(SD_GetStatus() != SD_TRANSFER_OK);

There seems to be no error checking here, for which I am doing something like:

again:

    Status=SD_WriteMultiBlocks ((uint8_t *)(&buf[0]), blk_addr, 512, blk_len);

    if(Status!=SD_OK)

    {

        SD_StopTransfer();

        return -1;

    }

    Status = SD_WaitWriteOperation();

    if(Status!=SD_OK)

    {

        SD_StopTransfer();

        goto again;

    }

    do

    {

        state=SD_GetStatus();

        if(state==SD_TRANSFER_ERROR)

        {

            SD_StopTransfer();

            goto again;

        }

    }while(state!=SD_TRANSFER_OK);

I am still getting a few errors at random times, like read and/or write error while copying a large file using USB. What might be the problem? I have also tried lowering the clock speed.

#stm32f4 #usb #sdio #microsd
6 REPLIES 6
Posted on July 12, 2012 at 15:12

The implementation of the demonstration code is rather crude, it's designed to illustrate function, not represent shippable code.

Hacking up an SD interface to a STM32F4 discovery is prone to problems as it's very difficult to control the wire lengths, skewing, or adequate guarding or grounding.

You need pull-up resistors on all the bidirectional pins (all but CLK), something in the order of 33K or 47K.

See other threads to see how I wired mine up.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tavish
Associate II
Posted on July 13, 2012 at 12:06

Hello, thanks for the reply. I tried again with the pull-up resistors in place. I often get SD_ILLEGAL_CMD returned by SD_ReadMultiBlocks(), for commands which seems to be valid. If I return 0 from the function, I am sending invalid data as valid, if I return non-zero then the USB interface restarts making the sdcard system unreliable. What should be the proper way to handle CRC, Illlegal_cmd and other such errors?

Posted on July 14, 2012 at 13:31

It gets complicated, certainly beyond the scope of my forum participation.

You'd basically want to keep track of the data actually delivered, and you'd need to convey SCSI SENSE data that describes the error appropriately, and the position of the error. You could, at a crude level, create sense data that said there was a soft CRC read error, and that none of the data delivered was usable. That way the IO subsystem could retry or decompose the request.

So for what is a wire error, you'd need to fake some kind of media error that will be retried. The media would normally report which sector this occurred in, but corruption in the transfer is rather indeterminate unless you break the transfer into smaller pieces. If you get a lot of wire errors you might want to degrade into single sector transfers.

It might also be worth trying a PCB implementation to see if it is more reliable. This Olimex board has a terminated MicroSD socket on board.

https://www.olimex.com/dev/stm32-h407.html

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
aambreen
Associate II
Posted on October 17, 2012 at 06:53

Hello,

tell me how to use fatfs to store an image on sd card if we are using sdio and already have initialized card successfully using low level sd init functions. i am using keil development environement...please tell me the proper steps i need to follow to import fatfs library in my project and then writing code to save image on sd card

I shall be highly obliged

Posted on October 17, 2012 at 07:12

I get bored of repeating myself, the forum search here *****, but this all gets spidered by Google, and is easy enough to find.

https://community.st.com/0D50X00009XkZKMSA3

 

Edit: Fixed DEAD LINK, original post from Oct 17, 2012

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
aambreen
Associate II
Posted on October 17, 2012 at 08:56

@Clive

the link you shared is quite cumbersome....I am a newbie so this link isn't helpful right now....I am looking for a stepwise approach

Kindly tell me the next step that i should follow after initializing sd card (using sdio functions)