fsl_sdhc_driver Stuck at SDHC_HAL_GetCurState()

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

fsl_sdhc_driver Stuck at SDHC_HAL_GetCurState()

1,522 Views
audi_mcavoy
Contributor IV

I used Processor Expert in KDS 3.0.0 with KSDK 1.2.0 to create a project for the FRDM-K64F board.  I added MQX Standard (I intend to use MFS later), one task, and an fsl_sdcard component.  PEx has no errors, and appears to generate its code with no problems.

 

The one task simply prints a string to the debug console, delays a little bit then repeats.

 

When I debug the program, it will sometimes print the string; but, most often it will hang in the fsl_sdhc_driver. . .

 

/* Wait until last time sdhc send operation complete */

while(!SDHC_HAL_GetCurState(g_sdhcBase[instance], kSdhcHalGetDataLine0Level)){}

 

I do have a known good SD card inserted.

 

Do I have something configured wrong?  Project attached.

- Audi

Original Attachment has been moved to: transflash_drive.zip

Labels (1)
6 Replies

1,095 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Audi,

Please insert your SD card into your board.

I have test your project on my side after i insert one SD card, it can work well , please see the  result :

pastedImage_0.png

Hope it helps


Have a great day,
Alice

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,095 Views
audi_mcavoy
Contributor IV

Were you able to repeat that success?  Because I have seen it work on rare occasion.

I've tried the same thing on my custom board with a K64 processor and a real SD card on it.

It gets stuck at the same place. . .

while(!SDHC_HAL_GetCurState(g_sdhcBase[instance], kSdhcHalGetDataLine0Level)){}

I'm not sure what else to try.

0 Kudos

1,095 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Audi McAvoy:

I think you are just missing to enable the Pull-ups and High-drive strength features for the SDHC pins. You can do this with a Init_PORT component.

Please try with the attached project.


Regards!,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,095 Views
audi_mcavoy
Contributor IV

Hi Jorge,  thanks for the reply.

We are getting closer to having a functional memory card.  Your fix did allow the fsl_sdhc_driver to finish initializing.  (I am going to insert a micro-rant here: Why doesn't the fsl_sdcard or the fsl_sdhc component configure the port to actually work?!  Arghh!)

As I was saying, we are getting closer.  When I add the following two lines before the while() loop in os_tasks.c . . .

  printf("Block Size: %d\r\n", (uint16_t)memoryCard1_state.blockSize);

  printf("Clock Speed: %d MHz, %d MHz max\r\n", (int)(memoryCard1_state.host->clock / 1000000), (int)(memoryCard1_state.host->maxClock / 1000000));

I get the following output. . .

  Block Size: 0

  Clock Speed: 0 MHz, 48 MHz max

I know the block size should be 512.  I expect the clock speed to be something greater than 0MHz.  So the driver has finished initializing; but, the card is unusable.  I am using a FAT formatted 2GB Transcend microSD card.  I'm confident the card is good because it works with some of the demo apps provided.

What should I try next?

- Audi

EDIT: I applied your fix to my custom board running a K64 with a real 1GB SD card on it, and it works.  The card appears to be fully functional.

0 Kudos

1,095 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Audi:

That result is because the SD Card initialization is not finished by the time the task is first launched. If you print the values again then you might receive the expected results.

To make sure that the SD card is initialized before your task is executed, you can change the initialization sequence.

Go to Window -> Show View -> Other...-> Processor Expert -> Initialization Sequence. Enable the initialization for the fsl_sdcard and the OS_Task components and make sure that the SD card is initialized first:

pastedImage_1.png

Then the correct information will be printed:

pastedImage_2.png

Regards!

Jorge Gonzalez

1,095 Views
audi_mcavoy
Contributor IV

Yep, that did it.

I really appreciate your help.  I marked both of your replies as helpful.  I wish I could mark them both as correct, because we really need to implement both to guarantee that the SD card works.

There is so much of this kind of information that can't be learned by opening an example project.  I've seen a few "how to" posts that show each step with explanations along the way -- I find those the most helpful.  Ideally, there would be a post like that for every component in the PEx components library.

Thanks again!  Now I can go be productful.

- Audi