Hi David,
Stepping through the code, I found the following and I would like to confirm it with you to see if you the same.
The code leads me to the following function, which I believe is where the clock actually gets configured.
/*FUNCTION****************************************************************
*
* Function Name: SDHC_HAL_ConfigSdClock
* Description: configure clock of host controller, it will set the most
* close clock frequency to the given clock
*
*END*********************************************************************/
void SDHC_HAL_ConfigSdClock(SDHC_Type * base, sdhc_hal_sdclk_config_t* clkConfItms)
{
uint32_t divisor, freq, sysCtlReg;
assert(base);
assert(clkConfItms);
divisor = SDHC_HAL_INITIAL_DVS;
freq = SDHC_HAL_INITIAL_CLKFS;
/* Enables the IPG clock and no automatic clock gating off.
Enables the system clock and no automatic clock gating off.
Enables the peripheral clock and no automatic clock gating off.
Enables the SD clock. It should be disabled before changing the SD clock */
SDHC_CLR_SYSCTL(base, (SDHC_SYSCTL_IPGEN_MASK | SDHC_SYSCTL_HCKEN_MASK | \
SDHC_SYSCTL_PEREN_MASK | SDHC_SYSCTL_SDCLKEN_MASK));
/* If user want to disable the clock , directly return. */
if(!(clkConfItms->enable))
{
return;
}
if (clkConfItms->destClk > 0)
{
while((clkConfItms->maxHostClk / freq / SDHC_HAL_MAX_DVS > clkConfItms->destClk) &&
(freq < SDHC_HAL_MAX_CLKFS))
{
SDHC_HAL_NEXT_CLKFS(freq);
}
while((clkConfItms->maxHostClk / freq / divisor > clkConfItms->destClk) &&
(divisor < SDHC_HAL_MAX_DVS))
{
SDHC_HAL_NEXT_DVS(divisor);
}
clkConfItms->destClk = clkConfItms->maxHostClk / freq / divisor; <--------------- Here I see the change happening **********
clkConfItms->destClk = 400KHz coming in, after this line clkConfItms->destClk = 0, then the code continues (I didn't bother copying the rest
it should be the same for you) and finally it gets to this line:
while(!SDHC_BRD_PRSSTAT_SDSTB(base)) {}
/* nables the SD clock. It should be disabled before changing the SD clock frequency. */
SDHC_SET_SYSCTL(base, SDHC_SYSCTL_SDCLKEN_MASK);
If I am holding my probe on the clock (PIN5) I can see that after it passes the while statement, it enables the clock and once again
the 24MHz appears!
In my previous post, I had a concern with this line:
freq = SDHC_HAL_INITIAL_CLKFS; where SDHC_HAL_INITIAL_CLKFS = 2U as seen on fsl_sdhc_hal.h
from the manual, choosing 2U = Base clock divided by 4.
SDCLK Frequency Select
Used to select the frequency of the SDCLK pin. The frequency is not programmed directly. Rather this
register holds the prescaler (this register) and divisor (next register) of the base clock frequency register.
Setting 00h bypasses the frequency prescaler of the SD Clock. Multiple bits must not be set, or the
behavior of this prescaler is undefined. The two default divider values can be calculated by the frequency
of SDHC clock and the following divisor bits.
Table continues on the next page...
Memory map and register definition
K64 Sub-Family Reference Manual, Rev. 2, January 2014
1640 Freescale Semiconductor, Inc.
SDHC_SYSCTL field descriptions (continued)
Field Description
The frequency of SDCLK is set by the following formula: Clock frequency = (Base clock) / (prescaler x
divisor)
For example, if the base clock frequency is 96 MHz, and the target frequency is 25 MHz, then choosing
the prescaler value of 01h and divisor value of 1h will yield 24 MHz, which is the nearest frequency less
than or equal to the target. Similarly, to approach a clock value of 400 kHz, the prescaler value of 08h and
divisor value of eh yields the exact clock value of 400 kHz. The reset value of this field is 80h, so if the
input base clock ( SDHC clock ) is about 96 MHz, the default SD clock after reset is 375 kHz.
According to the SD Physical Specification Version 1.1 and the SDIO Card Specification Version 1.2, the
maximum SD clock frequency is 50 MHz and shall never exceed this limit.
Only the following settings are allowed:
01h Base clock divided by 2.
02h Base clock divided by 4.
04h Base clock divided by 8.
08h Base clock divided by 16.
10h Base clock divided by 32.
20h Base clock divided by 64.
40h Base clock divided by 128.
80h Base clock divided by 256.
I am not sure, if I am heading in the right direction, but I don't understand, if I am changing the same lines as you are,
that I would get a different result? Of course, this is just a suspicion of what could be happening, maybe it can at least
give you a clue as to why I am not seeing the same thing.
Please let me know your thoughts on this.
Neil Porven