DaveAitch
Posts: 14
Joined: Thu Mar 24, 2016 6:06 pm

mmc_spi problems

Tue Jan 24, 2017 9:57 pm

Hi,
I'm trying to add a second SD card reader to my Raspberry Pi (model B) based "internet radio". The reader hardware connects the SPI lines directly to the SD card slot - all it provides is pullup resistors and a 5v->3.3v regulator so as not to overload the Pi's 3.3v rail. I've connected the reader to SPI CS0.
I've used the following devicetree overlay to switch off spidev0.0 and route it to mmc_spi instead.

Code: Select all

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2708";
    fragment@0 {
        target = <&spidev0>;
        __overlay__ {
            status = "disabled";
        };
    };
    fragment@1 {
        target = <&spi0>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            sd0: sd@0 {
                reg = <0>;
                status = "okay";
                compatible = "spi,mmc_spi";
                voltage-ranges = <3200 3500>;
                spi-max-frequency = <20000000>;
            };
        };
    };
};
A big thank-you to @PhilE for fixing my own attempt at that. 8-)

I've also applied a patch similar to this one viewtopic.php?p=865757#p865757 to my mmc_spi kernel module.

With this combination of hacks, the SD reader works for some of my cards but not others. They are all 8GB micro SDHC cards. Some are from SanDisk, others are cheap brands from Aldi, DM etc. It appears to be the SanDisk cards that don't work, except one (and that might be a fake).

I've scattered a few pr_info() calls into mmc_spi to try to find out what's going on.

When I insert a "good" card, I get the following sequence in /var/log/syslog:

Code: Select all

Jan 23 12:16:40 balor kernel: [ 2712.722298] mmc1: host does not support reading read-only switch, assuming write-enable
Jan 23 12:16:40 balor kernel: [ 2712.722342] mmc1: new SDHC card on SPI
Jan 23 12:16:40 balor kernel: [ 2712.740970] mmcblk1: mmc1:0000 00000 7.35 GiB
Jan 23 12:16:40 balor kernel: [ 2712.742012]   mmc_spi: CMD18, resp R1
Jan 23 12:16:40 balor kernel: [ 2712.747838]   mmc_spi: CMD12, resp R1
Jan 23 12:16:40 balor kernel: [ 2712.748050]  mmcblk1: p1
Jan 23 12:16:40 balor kernel: [ 2712.768404]   mmc_spi: CMD18, resp R1
Jan 23 12:16:40 balor kernel: [ 2712.772205]   mmc_spi: CMD12, resp R1
Jan 23 12:16:40 balor kernel: [ 2712.772618]   mmc_spi: CMD18, resp R1
Jan 23 12:16:40 balor kernel: [ 2712.780366]   mmc_spi: CMD12, resp R1
Jan 23 12:16:40 balor kernel: [ 2712.780807]   mmc_spi: CMD18, resp R1
Jan 23 12:16:40 balor kernel: [ 2712.787764]   mmc_spi: CMD12, resp R1
Jan 23 12:16:40 balor kernel: [ 2712.788203]   mmc_spi: CMD18, resp R1
Jan 23 12:16:40 balor kernel: [ 2712.791786]   mmc_spi: CMD12, resp R1
Jan 23 12:16:40 balor kernel: [ 2712.792175]   mmc_spi: CMD18, resp R1
Jan 23 12:16:40 balor kernel: [ 2712.800697]   mmc_spi: CMD12, resp R1
Jan 23 12:16:40 balor kernel: [ 2712.800796] cmd->resp[0] = 0x40
Jan 23 12:16:40 balor kernel: [ 2712.800849]   mmc_spi: CMD13, resp R2/R5
Jan 23 12:16:40 balor kernel: [ 2712.800944] mmcblk1: error -14 sending stop command, original cmd response 0x0, card status 0x0
The error message at the end doesn't seem to cause trouble; after this I can mount mmcblk1p1 and play audio files from it.
Note the sign-on information: mmcblk1: mmc1:0000 00000 7.35 GiB
When I insert a bad card I get the following sequence:

Code: Select all

Jan 23 12:16:22 balor kernel: [ 2694.721660] mmc1: host does not support reading read-only switch, assuming write-enable
Jan 23 12:16:22 balor kernel: [ 2694.721706] mmc1: new SDHC card on SPI
Jan 23 12:16:22 balor kernel: [ 2694.734366] mmcblk1: mmc1:0000 SU08G 7.40 GiB
Jan 23 12:16:22 balor kernel: [ 2694.735557]   mmc_spi: CMD18, resp R1
Jan 23 12:16:22 balor kernel: [ 2694.747878]   mmc_spi: CMD12, resp R1
Jan 23 12:16:22 balor kernel: [ 2694.748117]  mmcblk1: p1
Jan 23 12:16:22 balor kernel: [ 2694.766540]   mmc_spi: CMD18, resp R1
Jan 23 12:16:22 balor kernel: [ 2694.776057]   mmc_spi: CMD12, resp R1
Jan 23 12:16:22 balor kernel: [ 2694.776508]   mmc_spi: CMD18, resp R1
Jan 23 12:16:22 balor kernel: [ 2694.782110]   mmc_spi: CMD12, resp R1
Jan 23 12:16:22 balor kernel: [ 2694.782463]   mmc_spi: CMD18, resp R1
Jan 23 12:16:22 balor kernel: [ 2694.790733]   mmc_spi: CMD12, resp R1
Jan 23 12:16:22 balor kernel: [ 2694.791212]   mmc_spi: CMD18, resp R1
Jan 23 12:16:22 balor kernel: [ 2694.798407]   mmc_spi: CMD12, resp R1
Jan 23 12:16:22 balor kernel: [ 2694.798948]   mmc_spi: CMD18, resp R1
Jan 23 12:16:22 balor kernel: [ 2694.808116]   mmc_spi: CMD12, resp R1
Jan 23 12:16:22 balor kernel: [ 2694.808215] Houston, we have an ugly card with a bit-shifted response: 0xc2
Jan 23 12:16:22 balor kernel: [ 2694.808235] Shifted response - extra byte: 0x3f
Jan 23 12:16:22 balor kernel: [ 2694.808246] Shifted response - before shift: rotator = 0xc23f
Jan 23 12:16:22 balor kernel: [ 2694.808260] Shifted response - after shift: rotator = 0x08fc, bitshift = 2, resp = 0x08, leftover = 0xfc
Jan 23 12:16:22 balor kernel: [ 2694.808271] cmd->resp[0] = 0x08
Jan 23 12:16:22 balor kernel: [ 2694.808317]   mmc_spi: CMD13, resp R2/R5
Jan 23 12:16:22 balor kernel: [ 2694.808394] cmd->resp[0] = 0x04
Jan 23 12:16:22 balor kernel: [ 2694.808422] mmcblk1: error -38 sending status command, retrying
Jan 23 12:16:22 balor kernel: [ 2694.808441]   mmc_spi: CMD13, resp R2/R5
Jan 23 12:16:22 balor kernel: [ 2694.808512] cmd->resp[0] = 0x04
Jan 23 12:16:22 balor kernel: [ 2694.808537] mmcblk1: error -38 sending status command, retrying
Jan 23 12:16:22 balor kernel: [ 2694.808557]   mmc_spi: CMD13, resp R2/R5
Jan 23 12:16:22 balor kernel: [ 2694.808629] cmd->resp[0] = 0x04
Jan 23 12:16:22 balor kernel: [ 2694.808655] mmcblk1: error -38 sending status command, aborting
Jan 23 12:16:22 balor kernel: [ 2694.808677]   mmc_spi: CMD13, resp R2/R5
Jan 23 12:16:22 balor kernel: [ 2694.808750] cmd->resp[0] = 0x04
Jan 23 12:16:22 balor kernel: [ 2694.808927] mmc1: SPI card removed
Jan 23 12:16:22 balor systemd-udevd[558]: inotify_add_watch(6, /dev/mmcblk1p1, 10) failed: No such file or directory
Then the card detection sequence starts again, and repeats until I eject the card.
Note the sign-on information: mmcblk1: mmc1:0000 SU08G 7.40 GiB
The working card that's marked SanDisk identifies itself as 00000, which is why I think it's a fake.
The strange thing is that the shifted response only happens once, and seems to cause the errors that follow. If a card used a shifted response, you'd expect it to do it all the time, wouldn't you?

Does anyone have any idea about what might be going wrong.

BTW I'm using a fully-updated (as of 2017-01-22) Raspbian Lite distro. Kernel version is 4.4.43+

DaveAitch
Posts: 14
Joined: Thu Mar 24, 2016 6:06 pm

Re: mmc_spi problems

Sun Feb 26, 2017 4:17 pm

Bump.
Upgrading to 4.9.11+ didn't help.

Return to “Interfacing (DSI, CSI, I2C, etc.)”