AnsweredAssumed Answered

MFS init hang on K70 w/SDHC

Question asked by pbanta on May 16, 2014
Latest reply on Jan 19, 2016 by thiagow

I have a K70 board that is a shipping product with MQX 3.8.1.  I'm about to receive the next generation of that board.  While I'm waiting I'm trying to convert my code base to MQX 4.1.  I cloned the K70TWR BSP as a starting point.  I'm bringing peripherals online one at a time.  I have SPI working and now I'm working on the esdhc.

 

If I let the board run through initialization at full speed, the MFS initialization hangs in MFS_Mount_drive_internal().

 

mfs_init_hang_call_stack.png

It turns out that it is stuck in an infinite loop on these lines:

 

 

    /*

    ** Calculate the rest of the drive data.

    */

    k = drive_ptr->BPB.SECTORS_PER_CLUSTER;

    for ( drive_ptr->CLUSTER_POWER_SECTORS = 0; !(k & 1); drive_ptr->CLUSTER_POWER_SECTORS++ )

    {

        k>>=1;

    }


The BPB.SECTORS_PER_CLUSTER is zero, therefore k is zero before the for loop.  I suppose one might not expect for k to ever be zero and that is why there is no check.  If we are this far down the initialization then we know the SDHC card is present and we expect reads to work.


I have found that if set a breakpoint up one level in the call stack (MFS_Open_Device()) and step over the call to MFS_Read_device_sector() shown below, then I get valid data in drive_ptr and initialization is successful.


    /*

    ** read boot sector and get the BIOS Parameter Block

    */

    error_code = MFS_Read_device_sector(drive_ptr, BOOT_SECTOR, drive_ptr->DIR_SECTOR_PTR);

   

    if ( error_code == MFS_NO_ERROR )

    {

        drive_ptr->DIR_SECTOR_NUMBER = BOOT_SECTOR;

        error_code = MFS_Mount_drive_internal(drive_ptr);

    }

 

The configuration in init_edshc.c is this:

 

 

const ESDHC_INIT_STRUCT _bsp_esdhc0_init = {

    0,                          /* ESDHC device number */

    25000000,                   /* ESDHC baudrate      */

    BSP_SYSTEM_CLOCK            /* ESDHC clock source  */

};

 

where BSP_SYSTEM_CLOCK is 120000000UL.

 

It's all standard stuff.  In fact, it's the K70TWR default settings.  The variables in the equation are the changes in MQX 4.1.  My application code is lifted straight from the MFS example in MQX 3.8.1.  I reviewed the MQX 4.1 version of the example today and I didn't notice any differences.  However, I noticed that there are a lot of differences between the MQX 3.8.1 and MQX 4.1 versions of edshc.c.

 

One more data point...I tried changing the ESDHC baudrate to 50000000.  The result was that the MFS initialization did not hang, but I saw corruption in the file names on the device.

 

It seems there is a race condition somewhere.

 

Any ideas?

Outcomes