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

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Sep 12 06:51:10 UTC 2008


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.



More information about the users mailing list