Skip to content

SDSPI Performance Issue -- seeming bug in R1b response #45

@gdasher

Description

@gdasher

Hello,

I have been debugging an issue with the performance of the SDSPI driver with my PIC32 based project. I observe that the preformance of reading files from the SD card is abysmal (e.g. running at 25MHz SPI clock, getting far less than 10k bytes per second read throughput). I had chosen the sync implementation for what I thought was simplicities sake.

After hooking it up to a scope and observing the signals, I identified a consistent 100ms pause on the completion of of each MULTI_BLOCK_READ command sent to the card (to read a sector). What happens is that the MCU reads a sector, calls STOP_TRANSMISSION on the card, and then clocks 100ms of dummy bytes out of the SDcard. So each sector read takes 100ms+ to read 512 bytes, crippling the performance of the read.

Debugging, further, I think this code is just incorrect:

https://github.com/Microchip-MPLAB-Harmony/core/blob/master/driver/sdspi/sync/src/drv_sdspi.c.ftl (line 353)

do
            {
                /* MISRA C-2012 Rule 11.8 deviation taken. Deviation record ID -  H3_MISRAC_2012_R_11_8_DR_1 */
                if (DRV_SDSPI_SPIRead(dObj, (uint8_t*)dObj->cmdRespBuffer, 1) == false)
                {
                    <#if DRV_SDSPI_INTERFACE_TYPE == "SPI_DRV">
                    (void) DRV_SDSPI_SPIExclusiveAccess(dObj, false);
                    </#if>
                    return isSuccess;
                }
            } while ((dObj->cmdRespTmrExpired == false) && (dObj->cmdRespBuffer[0] != 0x00U));

The code is trying to wait for the SD card to become no longer busy, which as I understand the specification is indicated by returning a non-zero value [1]. Instead this code is continuing to loop until it gets a 0 value or times out (at 100ms). Changing != to == led to a massive speedup in my project and no longer shows the 100ms of junk each time a sector is read.

I suspect that this may have been noticed because the sync code may not be as widely used (?) and the software still works, its just horribly slow.

[1] (non-authoritative reference) https://chlazza.nfshost.com/sdcardinfo.html

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions