MFS init hang on K70 w/SDHC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MFS init hang on K70 w/SDHC

1,138 Views
pbanta
Contributor IV

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?

Labels (1)
0 Kudos
5 Replies

561 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Pbanta:

I ran the demo (C:\Freescale\Freescale_MQX_4_1\mfs\examples\sdcard) in my side, and not found this issue. The following is the terminal output

SD card demo

Shell (build: May 16 2014)

Copyright (c) 2013 Freescale Semiconductor;

shell>

could you please run this demo in your board?


Have a great day,
Daniel

-----------------------------------------------------------------------------------------------------------------------

0 Kudos

561 Views
pbanta
Contributor IV

Hi Daniel,

Thank you for the reply.

I have run the demo on my board but I don't have a UART for the console so I can't see the prompt.  I don't know whether or not it's working correctly.  In the demo I've set breakpoints on _io_mfs_install() and _io_dev_uninstall() so I can see that the code is running and detecting card insertion/removal, but I cannot verify that I can read/write the SD card..  I'm trying to get the iodebug: console working through my PE Micro but so far it's not working.

I also ran the demo on my K70 TWR but there is no surprise that works fine there.  I expected it to work on the tower and it did.

I forgot to mention in my original post that the MCU is a K70FX512.  I don't think it should matter, but it's not exactly the same chip used on the K70TWR.

0 Kudos

561 Views
pbanta
Contributor IV

Hi Daniel,

I got the iodebug: console to work.  When I run the demo I can see the prompt but the filesystem is not being mounted.

SD card demo

Shell (build: May 27 2014)

Copyright (c) 2013 Freescale Semiconductor;

shell>

shell> dir

Error, file system not mounted

shell>

Paul

0 Kudos

561 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Paul:

I think your issue is related to your SD card.  MQX only supports MFS (FAT) file system.   I tested it with Kingston micro SDHC card, 4Gb, class 4.

shell> Installing MFS over partition...

SD card installed to a:

shell> dir

DANIEL.TXT          5 05-29-2014 15:11:28      A DANIEL.TXT

shell>

shell> SD card uninstalled.

0 Kudos

561 Views
thiagow
Contributor III

I've the same problem using SanDisk cards on MQX 4.1.1 and kinetis k64 . How can'I solve this? Can I decrease the sdcard frequency?

Using sdcard.c example  with a Kingston SD I see:

shell>

shell> Installing MFS over partition...

SD card installed to a:

shell>

And all work fine, I can read and write. But,

Using a sdcard.c example with a SAnDisk card:

shell>

shell>

shell> Installing MFS over SD card driver...

Error opening filesystem: UNKNOWN ERROR !!!

shell>

0 Kudos