Getting started with FAT Filesystem on SD/MMC cards over SPI

Robert S. Grimes rsg at alum.mit.edu
Thu Sep 25 01:16:09 UTC 2008


Hi Sebastian,

I'm having some success, but of course, not total!

I haven't powered on my oscilloscope to verify that way, but I do think 
I've got your spi-sd-card.c driver talking with my powerpc/virtex SPI 
driver, in that I'm getting some believable data, before it breaks. What 
I did was start with the MPC5566EVB init code you mentioned:

c/src/lib/libbsp/powerpc/mpc55xxevb/startup/sd-card-init.c


and customized it to talk via my SPI driver. I finally got things to 
build execute, at least to the following point, which is output from the 
spi-sd-card.c driver:

    sd_card_driver_init: *** Card Identification ***
    sd_card_driver_init: Manufacturer ID : 3
    sd_card_driver_init: OEM/Application ID : 21316
    sd_card_driver_init: Product name : S1G€
    sd_card_driver_init: Product revision : 0
    sd_card_driver_init: Product serial number : 2696421888
    sd_card_driver_init: Manufacturing date : 136
    sd_card_driver_init: 7-bit CRC checksum : 27
    sd_card_send_command: Error: Command error [07]: 0x7f
    sd_card_send_command: Error: Response: ff:ff 49:ff 00:ff 00:ff 00:ff
    00:ff 95:82 ff:[7f] ff:ff ff:ff f
    f:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:00 ff:00
    sd_card_driver_init: Error: RV = -27: Send: SD_CARD_CMD_SEND_CSD


Looking at the SanDisk manual seems to suggest the first two fields are 
correct (Man. and App IDs), and the Man Data corresponds to August 2008, 
which makes sense (I just bought the card last week). The Product name 
looks semi-sensible - it is a 1 GB SD Card.

I don't know what to make of the Errors though, and I have to go home 
now. If you have any ideas, I would be glad to hear them; regardless, 
I'll be back at it in 10 hours...

Thanks,
-Bob




Sebastian Huber wrote:
> Hi,
> I wrote a SD Card driver that uses the LibI2C interface.  It is already
> included in the RTEMS CVS under the LibChip:
>
> c/src/libchip/i2c/spi-sd-card.h
> c/src/libchip/i2c/spi-sd-card.c
>
> It works with the SPI drivers for the MPC5566EVB and MPC8313ERDB boards.
>   I had problems to initialize some SD Cards (1 out of 10), but this is
> maybe a problem of the SPI interface in these cards.  The initialization
> sequence is not perfect and may need improvement.  One problem is that
> not all documents are publicly available.
>
> The SD Card driver registers itself to LibBlock so you can use easily
> imfs and dosfs.
>
> Example code:
>
> c/src/lib/libbsp/powerpc/mpc55xxevb/startup/sd-card-init.c
>
> The crucial point for the SPI driver is that it must be possible to
> drive the clock with inactive chip select:
>
> [...]
> /* Stop */
> sc = sd_card_stop( e);
> CHECK_SC( sc, "Stop");
>
> /* Start with inactive chip select */
> sc = rtems_libi2c_send_start( e->minor);
> CHECK_SC( sc, "Send start");
>
> /* Set transfer mode */
> rv = rtems_libi2c_ioctl( e->minor, RTEMS_LIBI2C_IOCTL_SET_TFRMODE,
> &e->transfer_mode);
> CLEANUP_RVSC( rv, sc, sd_card_driver_init_cleanup, "Set transfer mode");
>
> /* Send idle tokens with inactive chip select */
> rv = sd_card_query( e, e->response, SD_CARD_COMMAND_SIZE);
> CLEANUP_RVSC( rv, sc, sd_card_driver_init_cleanup, "Inactive chip select
> delay");
>
> /* Activate chip select */
> sc = rtems_libi2c_send_addr( e->minor, 1);
> CLEANUP_SC( sc, sd_card_driver_init_cleanup, "Send address");
> [...]
>
> So you have to activate the chip select in rtems_libi2c_send_addr() and
> not before.
>
> It would be nice if you could use this code.
>
> Gene Smith wrote:
>   
>> What you are talking about here my h/w does and it is something I need
>> to do too. However, at this point I don't have a clue how. So a "HowTo"
>> would be most appreciated and I could contribute what I learn.
>>
>> All I have worked with is the IMFS in a simple way.
>>
>> -gene
>>
>> Robert S. Grimes wrote:
>>     
>>> Hello,
>>>
>>> My hardware provides support for SD/MMC flash cards over SPI, so now I
>>> need to implement suitable drivers for this.  Because it would need to
>>> be read by Windows machines, and because it is sufficient for my
>>> application, it seems the dosfs is the way to go.
>>>
>>> I've got a low level SPI driver for my BSP (powerpc/virtex under RTEMS
>>> 4.8), and I've written some chip drivers on top of that, so I'm
>>> comfortable with the SPI level.
>>>
>>> But where do I go from here?
>>>
>>>    1. How do I "include" the dosfs in my application?  Is it a matter of
>>>       #define CONFIGURE_ macros, and if so, which?  (As an aside, is
>>>       there one central place where all these macros are defined?  If
>>>       so, I haven't found it...)
>>>    2. How do I get dosfs to work via the SPI bus?  What must my driver
>>>       look like?
>>>
>>> Any pointers or roadmap well appreciated - TIA
>>> -Bob
>>>
>>> P.S. Sounds like a request for a "HowTo" on my part - I'd be happy to
>>> write one for the Wiki...
>>>       
>> _______________________________________________
>> rtems-users mailing list
>> rtems-users at rtems.com
>> http://rtems.rtems.org/mailman/listinfo/rtems-users
>>     
>
>
> --
> Sebastian Huber, Embedded Brains GmbH
>
> Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany
> Phone   : +49 89 18 90 80 79-6
> Fax     : +49 89 18 90 80 79-9
> E-Mail  : sebastian.huber at embedded-brains.de
> PGP     : Public key available on request
>
> Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.com
> http://rtems.rtems.org/mailman/listinfo/rtems-users
>
>   




More information about the users mailing list