AnsweredAssumed Answered

K60 SDHC hanging problem

Question asked by Mark Butcher on Aug 14, 2011
Latest reply on Mar 19, 2012 by Mark Butcher

Hi All

Has anyone had a problem that the SDHC gets blocked?
When doing  tests I sometimes get the following while loop waiting forever:


This is performed in the read of a sector (not using DMA) of 512 bytes (actually 128 long words at the SDHC interface). The BREN flag indicates that there are bytes to be read and the problem always occurs when 127 long word reads have been made and there is never a flag to say that the final one is ready.

When this happens there are no data error bits set in the SDHC_IRQSTAT register.

The value of SDHC_PRSSTAT is 0xff88020a

This is the routine:

// Read a sector from SD card into the specified data buffer//extern int fnGetSector(unsigned char *ptrBuf){    unsigned long *ptrData = (unsigned long *)ptrBuf;                    // the Kinetis driver ensures that the buffer is long word aligned    int i = (512/sizeof(unsigned long));    while (i--) {        if (SDHC_IRQSTAT & (SDHC_IRQSTAT_DEBE | SDHC_IRQSTAT_DCE | SDHC_IRQSTAT_DTOE)) { // check for read errors            SDHC_IRQSTAT = (SDHC_IRQSTAT_DEBE | SDHC_IRQSTAT_DCE | SDHC_IRQSTAT_DTOE | SDHC_IRQSTAT_BRR);            return UTFAT_DISK_READ_ERROR;                                // return error        }        while (!(SDHC_PRSSTAT & SDHC_PRSSTAT_BREN)) {             <---------- gets stuck here        }        *ptrData++ = SDHC_DATPORT;    }    while (!(SDHC_IRQSTAT & SDHC_IRQSTAT_TC)) {                          // wait for transfer to complete    }    SDHC_IRQSTAT = (SDHC_IRQSTAT_TC | SDHC_IRQSTAT_BRR | SDHC_IRQSTAT_AC12E); // reset flags    return UTFAT_SUCCESS;                                                // read successfully terminated}


This seems quite a standard/typical realisation. The following subtle effects have also been noticed:
1) When built with GCC it hangs very often when the SDHC_IRQSTAT check before it is removed. With the check in position it seems to be stable.
2) When built with CW10.1 it gets stuck quite often, even with the SDHC_IRQSTAT check before the line.

Therefore the stability is compiler/timing dependent (all registers are declared as volatile).

Has anyone else encountered such a behaviour?



P.S. During the test the SD card is used by various sources (to display images to the TFT display (file system reads), for USB-MSD (PC reads) and for serving pages at web server (web server file reads). It is easier to reproduce when all are working together but still happens when only one read source is actually active (although less frequently). Accesses are however protected so only one source actually physically reads at a time.