Cannot clock a MK64 SDHC controller

cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot clock a MK64 SDHC controller

Jump to solution
402 Views
simonhaines
Contributor III

I am struggling to bring up the SDHC on my MK64FN1M0xxx12 board. I have tried to clock the SDHC with both the IRC48M and a 20MHz OSCERCLK.

  1. When using the IRC48M and setting the SDHC SYSCTL register, the PRSSTAT register reports value 0xff880080 which is: bit 7 (SDOFF), bit 19 (this read-only field is reserved and always has the value of 0?), and bits 23-31 (CMD and all DAT signals). The expected SDSTB bit is never signalled.
  2. When using a 20MHz OSCERCLK, the SDHC is able to execute SD_GoIdle, but when executing a SD_SendInterfaceCondition or SD_SendApplicationCmd, the IRQSTAT register reports 0x10001 which is: bit 16 (CTOE) and bit 1 (CC). So the command is timing out.

I have attached a project that reproduces condition 1 on a FRDMK64F evaluation board. The project was built with MCUXpresso and SDK 2.4.0. It stops at drivers/fsl_sdhc.c:969 ("Wait until the SD clock is stable"). Note that a clock configuration and pin routing are included in the MK64FN1M0xxx12_Project.mex file.

I would like to know why the SDHC command is timing out even with a dedicated 20MHz clock from OSCERCLK (condition 2).

Simon.

Tags (2)
0 Kudos
1 Solution
168 Views
mjbcswitzerland
Specialist V


Hi Simon

Try a FRDM-K64F reference binary from here [http://www.utasker.com/kinetis/FRDM-K64F.html] to check your board and card can operate.

See also https://community.nxp.com/message/1001515?commentID=1001515#comment-1001515

I have attached two other binary files for the FRDM-K64F - one clocking the SDHC from OSCERCLK and the other from IRC48M. There are build with the uTasker project (more featured utFAT) and allows you to see the SD card's files on the OpenSDA VCOM interface at 115'200 Baud (then in the utFAT menu there is a DOS like interface).

Usually the core clock is used (faster) but the OSCERCLK (50MHz on the FRDM-K64F) can be selected instead, whereby the only trick is to be sure to enable the OSCERCLK output from the MCG - the uTasker code automates this in this mode with
OSC0_CR |= (OSC_CR_ERCLKEN);                                         // ensure that the OSCERCLK is enabled (it is assumed that there is a external clock applied or the oscillator is operating)
It can also be used from the IRC48M clock although this is a bit more delicate since the IRC48M has un-documentent errata in earlier chips (which are often found on even newer FRDM-K64F boards) - essentially the trick is to enable the USB module and clock recovery there otherwise it may not be operating. The clock speed during initialsiation should be chosen to be around 400kHz and then when operating in 4 bit SDHC mode to around 25MHz.

You can use the memory debugger interface in the I/O menu to view register settings (or use a debugger) if needed. You should then be able to correct the source that you use based on this. Or, if you would instead prefer to slash your development time with more complete code just use the uTasker project (either free open source or fully supported for professionals).


Regards

Mark

View solution in original post

0 Kudos
2 Replies
169 Views
mjbcswitzerland
Specialist V


Hi Simon

Try a FRDM-K64F reference binary from here [http://www.utasker.com/kinetis/FRDM-K64F.html] to check your board and card can operate.

See also https://community.nxp.com/message/1001515?commentID=1001515#comment-1001515

I have attached two other binary files for the FRDM-K64F - one clocking the SDHC from OSCERCLK and the other from IRC48M. There are build with the uTasker project (more featured utFAT) and allows you to see the SD card's files on the OpenSDA VCOM interface at 115'200 Baud (then in the utFAT menu there is a DOS like interface).

Usually the core clock is used (faster) but the OSCERCLK (50MHz on the FRDM-K64F) can be selected instead, whereby the only trick is to be sure to enable the OSCERCLK output from the MCG - the uTasker code automates this in this mode with
OSC0_CR |= (OSC_CR_ERCLKEN);                                         // ensure that the OSCERCLK is enabled (it is assumed that there is a external clock applied or the oscillator is operating)
It can also be used from the IRC48M clock although this is a bit more delicate since the IRC48M has un-documentent errata in earlier chips (which are often found on even newer FRDM-K64F boards) - essentially the trick is to enable the USB module and clock recovery there otherwise it may not be operating. The clock speed during initialsiation should be chosen to be around 400kHz and then when operating in 4 bit SDHC mode to around 25MHz.

You can use the memory debugger interface in the I/O menu to view register settings (or use a debugger) if needed. You should then be able to correct the source that you use based on this. Or, if you would instead prefer to slash your development time with more complete code just use the uTasker project (either free open source or fully supported for professionals).


Regards

Mark

View solution in original post

0 Kudos
168 Views
simonhaines
Contributor III

Thanks Mark for your reply. We are looking further into uTasker and if it will be a good fit for us.

The projects worked as expected... once we realised the manufacturer had placed the SD card holder with the wrong orientation. Since then we have been able to link the OSCERCLK with the SDHC peripheral. The Kinetis SDK does not like feeding the SDHC with a clock less than 25MHz, so there is a bit of work to be done there.

Thanks again and regards,

Simon.

0 Kudos