KSDK assertion failed clocking the SDHC at 20MHz

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

KSDK assertion failed clocking the SDHC at 20MHz

1,342 Views
simonhaines
Contributor III

Not sure if this is a bug, but in my MK64F project I clock the SDHC from a 20MHz oscillator (kCLOCK_OSC0ErClk). The SD_CardInit and SD_SelectBusTiming functions call SDHC_SetSdClock functions with parameters like SD_CLOCK_25MHZ, SD_CLOCK_50MHZ and SD_CLOCK_100MHZ.

In the SDHC_SetSdClock function there is the assertion:

assert((busClock_Hz != 0U) && (busClock_Hz <= srcClock_Hz));

This will assert because my source clock is 20MHz and the bus clock is greater. I have added the following line to SDHC_SetSdClock as a workaround.

busClock_Hz = MIN(srcClock_Hz, busClock_Hz);

Is this an issue?

Also, this document indicates the maximum SDHC timing for K64 parts should be 40MHz, and not 50MHz as in the SDK... Does that advice still apply?

Tags (3)
5 Replies

1,102 Views
jeff_rosen
Contributor II

I have had the same issues - my workaround was slightly different, I just lie and tell the SDK that my srcClock_Hz matches the request bus clock, i.e. use a srcClock_Hz = 25MHz even though it is actually 20MHz.  It seems to work fine and since my actual srcClock is slower, I think that meets the spec.  I have been wondering if I'm doing something wrong, given Simon's comments it seems like this is another possible workaround, although his "fix" seems more correct.

0 Kudos

1,102 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Simon:

Please refer to the function parameters,   busClock_Hz is SD bus clock frequency, not system bus clock.

/*!
 * @brief Sets the SD bus clock frequency.
 *
 * @param base SDHC peripheral base address.
 * @param srcClock_Hz SDHC source clock frequency united in Hz.
 * @param busClock_Hz SD bus clock frequency united in Hz.
 *
 * @return The nearest frequency of busClock_Hz configured to SD bus.
 */
uint32_t SDHC_SetSdClock(SDHC_Type *base, uint32_t srcClock_Hz, uint32_t busClock_Hz);

Regards

Daniel

0 Kudos

1,102 Views
simonhaines
Contributor III

Hi Daniel,

It is perfectly OK to set SIM_SOPT2:SDHCSRC to a 20MHz source clock. In this case the SD bus clock cannot be more than 20MHz of course, but this is OK according to the SD Physical Specification Version 1.1.

However if you set SIM_SOPT2:SDHCSRC to a 20MHz source clock and then call the KSDK 2.4.2 function SD_CardInit(sd_card_t *card), then that function will call SDHC_SetSdClock(card->host.base, card->host.sourceClock_Hz, SD_CLOCK_25MHZ).

As you can see, if the value of srcClock_Hz is 20MHz and the value of busClock_Hz is 25MHz, then this line will not work:

assert((busClock_Hz != 0U) && (busClock_Hz <= srcClock_Hz));

This is a bug. When the SDK tries to set the bus clock greater than the source clock, it should instead set the bus clock to be equal to the source clock (i.e. 20MHz). This is in KSDK 2.4.2, file fsl_sdhc.c, function SDHC_SetSdClock, line 891.

Hope this helps,

Simon.

1,102 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Simon:

Could you please let me know your KSDK version?

Regards

Daniel

0 Kudos

1,102 Views
simonhaines
Contributor III

Hi Daniel,

Version is KSDK 2.4.2.

Hope this helps,

Simon.

0 Kudos