cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Visitor
Visitor
2,282 Views
Registered: ‎07-06-2011

Reading data from Compact Flash

Hello all,

 

I'm using an ML405 demo board and the EDK 10.1 SP3.

 

I am using the SystemACE drivers to do a raw read of data from an unformated Compact Flash drive.  I put the data there using the 'dd' utility in linux.  Linux is able to read the data from the Compact Flash card.  I am able to read the data some of the time using the PowerPC on the ML405, but for some reason, it is often failing half way through reading the 13 sectors worth of data.  I'm using a 1GB CF card and the data I'm reading is 16MB away from the end of the card.

 

Here is my code:

 

 

inline XStatus SectorRead(Xuint32 sector)
{
    XStatus status;
    Xuint32 errorMask;
    int retries = 10;


    /* Wait for SysAce to be ready and then read */
    xil_printf("Reading next sector from Compact Flash...");
    while ( !XSysAce_IsCFReady(&SysAce) );
    status = XSysAce_SectorRead(&SysAce, sector, 1, CFBuf);

    /* Check the read */
    if (status != XST_SUCCESS)
    {

        /*
        * An error occurred. Get the error mask to figure out what the
        * cause of the error is.
        */

        if (status == XST_DEVICE_BUSY)
        {
            xil_printf("Compact Flash device busy!\r\n");
        }
        else if (status == XST_SYSACE_NO_LOCK)
        {
            xil_printf("No lock on SysACE!\r\n");
        }
        else
        {
            errorMask = XSysAce_GetErrors(&SysAce);

            if (errorMask & XSA_ER_CARD_READ)
            {
                xil_printf("Compact Flash read error!\r\n");
            }
            else
            {
                xil_printf("Other Compact Flash error! Err No: 0x%8x\r\n", errorMask);
            }
        }

        status = XST_FAILURE;
    }
    else
    {
        xil_printf("Sector read in!\r\n");

        /* Print out data */
        for (i = 0; i < 512/16; i++)
        {
            xil_printf("%3d:", i*16);
            for  (j = 0; j < 16; j++)
            {
                if (j % 8 == 0)  xil_printf("  ");
                xil_printf(" %2x", CFBuf[i*16+j]);
            }
            xil_printf("\r\n");
        }
        
    }

    return status;
}

 

Sometimes it will read through all 13 sectors.   It doesn't fail on a consistant sector.  

 

It prints out the "Other Compact Flash error! Err No: 0x80". This is defined in xsysace_l.h as:

#define XSA_ER_CFG_READ      0x00000080	 /**< Cfg read of CF failed */

This error doesn't make sense to me since I'm not trying to read the Compact Flash configuration.

 

Has anyone run into this error before?

 

0 Kudos
Reply
1 Reply
Visitor
Visitor
2,273 Views
Registered: ‎07-06-2011

I've been doing more work on this.  For the benifit of anyone who searches for this thread I'll write down my findings.

 

Just in case, I decided to put an FAT32 partition with SystemACE configuration files on it.  However, that did not seem to have any effect.

 

Next, I went from reading 1 sector at a time to 4 sectors at a time.  For some reason, this seems to help, and it crashed a lot less often after doing this, but it still crashed, and I need the reliability.

 

After that, I went code diving into the SysAce 1.11 driver.  XSysAce_SectorRead() has two lines that are commented out:

 

/* Reset configuration controller (be sure to keep the lock) */
/* This breaks mvl, beware! */
/*XSysAce_mOrControlReg(InstancePtr->BaseAddress, XSA_CR_CFGRESET_MASK); */

NumRead = XSysAce_ReadDataBuffer(InstancePtr->BaseAddress,
			       BufferPtr, BytesToRecv);
/* Clear reset of configuration controller */
/* This breaks mvl, beware! */
/*XSysAce_mAndControlReg(InstancePtr->BaseAddress, ~(XSA_CR_CFGRESET_MASK)); */

 

I think mvl refers to Monta Vista Linux.  Anyways, removing the comments from these lines seems to have worked.  So for some reason, for a reliable read, I need to reset the configuration controler.

 

Anyone know what this is about?

0 Kudos
Reply