[En-Nut-Discussion] Bug in Ethernut found - was: SD-card problems

Bernd Walter enut at cicely.de
Mon Mar 2 21:08:08 CET 2009


On Mon, Mar 02, 2009 at 08:26:39PM +0100, Bernd Walter wrote:
> Sorry - I was a bit too fast :(
> 
> On Mon, Mar 02, 2009 at 08:05:45PM +0100, Bernd Walter wrote:
> > 
> > Probably it is already fixed, since I'm still using 4.6.3.
> > The code failed to put the card into SPI mode.
> > The comment above was correct, but disagreeing with the code.
> > Maybe just luck got the card in SPI mode everywhere else.
> > 
> > [188]devel# [187]devel# diff -u mmcard.orig mmcard.c 
> > --- mmcard.orig 2009-03-02 20:02:43.551952257 +0100
> > +++ mmcard.c    2009-03-02 20:02:50.659675771 +0100
> > @@ -366,7 +366,7 @@
> >       * 80 bits of ones with deactivated chip select will put the card 
> >       * in SPI mode.
> >       */
> > -    (*ifc->mmcifc_cs) (0);
> > +    (*ifc->mmcifc_cs) (1);
> >      for (i = 0; i < 10; i++) {
> >          (*ifc->mmcifc_io) (0xFF);
> >      }
> > Exit 1
> 
> The code was correct, since mmcifc_cs is inverting.
> Nevertheless it is working with this change in the X256 board, but
> still not with the X512 one.
> Sigh... - I really hate this kind of problems.

I've found another reset sequence on the net, which seems to work.
The official standard isn't helping very much :( about this problem.
The other sequence startet with 400kHz, while this is starting with
sysclk/3 (~16MHz in my case), but it was said that the 400kHz is only
for compatibility with old cards - the SD specs say at least 25MHz
is required by cards.
Supporting SD cards correctly seems to be a very fishy thing :(
I already wrote a simple AT91RM9200 MCI driver for MMC cards in
FreeBSD and was happy that another one took over and did the SD
work - MMC specs were easier to read and I spend my time with the
glory MCI bugs instead.

--- /usr/local/arm-elf/ethernut-4.6.3-X512/dev/mmcard.orig      2009-03-02 21:00:00.018798498 +0100
+++ /usr/local/arm-elf/ethernut-4.6.3-X512/dev/mmcard.c 2009-03-02 20:45:23.875451761 +0100
@@ -366,8 +366,12 @@
      * 80 bits of ones with deactivated chip select will put the card 
      * in SPI mode.
      */
+    (*ifc->mmcifc_cs) (1);
+    for (i = 0; i < 100; i++) {
+        (*ifc->mmcifc_io) (0xFF);
+    }
     (*ifc->mmcifc_cs) (0);
-    for (i = 0; i < 10; i++) {
+    for (i = 0; i < 2; i++) {
         (*ifc->mmcifc_io) (0xFF);
     }
 
-- 
B.Walter <bernd at bwct.de> http://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.


More information about the En-Nut-Discussion mailing list