Increasing G120 SD card clock speed and enabling powersave

By default the SD card clock is running at 10MHz. Most modern cards will work well at many times this rate.

Additionally by default the clock is running 100% of the time regardless of whether any data transfer is taking place.

We can boost this clock rate and also enable the built in Powersave feature of the NXP chip by simply overwriting the Register value as shown below.

 sdPS = new SD();
                    Register SD_CLK = new Register(0x0400C0004);
                    //MCLK rate is the Peripheral clock rate which is 60MHz by default.
                    //SD_CLK.CLKDIV frequency = MCLK/(2 * (ClkDiv+1))
                    //SD_CLK.Value = 0x902; //set clock rate to 60/ (2*( 2+ 1) = 120/6   = 10MHz  DEFAULT VALUE
                    //SD_CLK.Value = 0x901; //set clock rate to 60/ (2*( 1+ 1) = 120/4   = 15MHz
                    SD_CLK.Value = 0x900; //set clock rate to 60/ (2*( 1+ 1) = 120/2   = 30MHz
                    SD_CLK.SetBits(0x200);//SET SD CARD POWERSAVE BIT (BIT 9). TURNS OFF CLOCK WHEN IDLE
                    Debug.Print("SD CLOCK = " + SD_CLK.Value.ToString());

I have tested this with a Kingston 64GB SDXC Class10 UHS1 card as well as a SDHC 32GB class 4 card. So far I have had not seen any issues whatsoever. I see no reason this will not work with all modern SD cards.

I have measured the clock rate with an oscilloscope and confirmed both the rate and the PowerSave functionality.

I have not yet made any read/write speed tests (although it does seem much snappier) or quantified any power savings.

For more details please refer to page 456 of the LPC178x/7x user manual UM10470.


Just for reference here is a link to some previous speed test work done by Peter B.

and on codeshare

@ hagster -

From 4.3

With xxx is input clock param, in KHz
But we will add bit 9 (no clock when no active on the bus).
1 Like