leecoakley

SD interface driver sets incorrect SD clock

Discussion created by leecoakley on Sep 27, 2018
Latest reply on Sep 29, 2018 by leecoakley

I was looking at the SD bus signals on a scope and I noticed the clock speeds were all WAY off the mark.

  • Set 400 KHz, get ~118 KHz.  Cards don't work. (Must be why the high level driver enumerates at 20MHz)
  • Set 20 MHz, get 16.67 MHz. Usually works but it's slower than it should be.
  • Set 50 MHz, get 33.33 MHz. Usually not tolerated.

 

This looks suspiciously like a divisor being stepped up one notch further than it's supposed to be.  When I went through the SDIF driver I found the culprit was exactly that.  Look at the function Chip_SDIF_SetClock(). This is how it computes the divisor:

div = ((clk_rate / speed) + 2) >> 1;

This is wrong.  It should be + 1.  Once corrected I get the expected clocks and everything works perfectly.  All cards enumerate, high speed mode works, etc.

 

This makes your SD controller look much worse than it actually is!  When properly configured I can run any SD card I own in high-speed mode and get the full 25 MB/sec the controller is capable of - from ancient SD to SDHC to a brand new SDXC card. The SD controller is really a great piece of work. But I can't say the same for the drivers.

Outcomes