cancel
Showing results for 
Search instead for 
Did you mean: 

problem with clocking the SDIO for STM32F2xx

zeros_and_ones1991
Associate III
Posted on August 02, 2013 at 19:18

I have the PORT board , with STM32F207ZG , I have written my own SD library , since i did not feel good using the built in library , ...... the library i wrote is working correctly as it should be , and i wrote n read from the card correctly , but I just have a problem with clocking .... this is the configurations i have in the main ()

{

uint32_t temp; 

    temp=0;

    RCC->CFGR=0x00000000;

    RCC->CFGR|=(uint32_t)(0x09<<4);//AHB Prescalar of 4

    //RCC->CFGR|=(0x06<<13); //APB2 prescalar (if i uncomment this line , card wont initialize) 

    //

    //

    temp|=(0x08<<24); //  PLL Division factor for SDIO (PLLQ) = 8

    temp|=0x08;         // Main Division Factor for PLL input (PLLM) = 8  

    temp|=(0xC0<<6); // Main PLL multiplication factor (PLLN) = 192

    temp|=(3<<16); // Main Division Factor for PLL output (PLLP) = 8

    RCC->PLLCFGR=temp;

    RCC->CR|=(1<<24);

    while(!(RCC->CR & (1<<25))); // Waiting for PLL output to be ready

    //RCC->CFGR|=(1<<1); // PLL is the system clock (if i uncomment this line , the card wont initialize , idk y )

    //

    //

.

.

.

}

and on the SD_CARD_INIT()

{

  SDIO->CLKCR=0x00000000;    

  SDIO->CLKCR|=120; // Clock division factor but it has no meaning as long as bypass is enabled

 SDIO->CLKCR|=(1<<10); //By_pass enabled (if i comment this line , it wont work)

  SDIO->CLKCR|=(1<<8); // Clock enabled

  SDIO->POWER=0x00000003;

  //

  //  Initialization Sequence

  //

..

..

}

so the problem now is that i can not use the 96 MHz for the core processor or the card will fail initialization , even if i make sure that the clock on the APB2 domain is less than 60 MHz as the manual says , ..... but the other interesting fact is that according to these configurations , the card initialization is done via 48 MHZ clock , rather than 400KHZ or less ???!!!!!!!!!

This is urgent guys , cuz i really started to doubt this chip .
7 REPLIES 7
Posted on August 02, 2013 at 21:13

I'm not sure I want to wade through this mess. If you don't run from the PLL, then the process is going to be grinding at 8 or 16 MHz via the HSE or HSI, and the APBx a bunch slower than that.

I'm not sure running an APB at 1-2 MHz is compatible with running the SDIO at 48  MHz.

Start by fixing your clocking problems, and verify what clocks you've got by exporting them via the MCOx pins and viewing them on a scope.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
zeros_and_ones1991
Associate III
Posted on August 03, 2013 at 04:01

first thanks clive for ur reply ,..........well i do not really have a scope right now , ............but i can tell u that im sure i can run the Core on 96MHZ (through the Delay function) , so up to the PLL output , i can tell u that everything is going ok , ......... about the APB2 domain , and its Compatibility with SDIO , all the sheet tells is that the clock on the APB2 bus should not be more than 60 MHz and it should also follow that condition APB2 clock >= (3/8) SDIO_CLK .

It would be nice if u worked with this interface , so u can tell me how u clocked it.

thanks in advance.
Posted on August 03, 2013 at 04:24

Can you provide a cite for this ''PORT'' board, I'm not familiar with it.

Is there a reason you can't test the SDIO using the example code in the library? I'm not terribly keen on digging through register level code to fix an interface I know works with the examples.

Is there a reason to be clocking at 96 MHz instead of 120 MHz?

The SDIO peripheral requires the PLL (Q tap) to be functioning, if the PLL isn't running it won't work. It looks like you have the PLL running, just not using it.

You definitely don't want the bypass when enabling the card, the divider permits you to run it at about 400 KHz for initialization, and about 24 MHz when operating. While it's possible to run some cards at 48 MHz, or higher, I'd start with something slower, especially for full size cards. Does your board use MicroSD cards? What's the spec on the cards you're testing right now?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
zeros_and_ones1991
Associate III
Posted on August 03, 2013 at 04:43

thx again clive ....... well i do not have problem with using the 120 MHZ , ....... i tried sth else , i used the built-in     SystemInit(); function , so now u wont have to go down to the register level , the function is in the system_stm32f2xx.h/c file (surely u know that) , so now im sure im running the PLL correctly and to the maximum speed , (as it says in the file) , and also i provide the SDIO clock with the needed 48 MHz , so now all i should do is to change the division factor to get the 400KHZ or less needed for initialization , but unfortunately it still does not work , with or without by-passing , ....... so now what we know so far is that we have the clock core running at 120 MHZ and the APB2 bus running at 60 MHz and the SDIO clck running at 48 MHz , ..... to give u more idea , the error it returns is a timeout error at CMD8 which is the first command after resetting the card with CMD0 (which wont give errors cuz it does not wait for data from the card) ......... the card im using is MicroSD card (SANDISK) but i tried like 4 other card n it worked properly before i have this clock issue ..... and about the board .. i do not have SD card connector on it , i just made my own through the bigger adapter (No doubt in the hardware cuz i used this adapter for the same application when i wrote SPI driver for the card on ATMEGA device ) ....... the board has the external 25 MHz needed for HSE. n thats a link to the board....http://www.wvshare.com/product/Port207Z.htm

sorry man i know this is very confusing.

Posted on August 03, 2013 at 05:03

The clocks setting you had earlier were totally broken.

PLLP should be 2, gets 192 MHZ to 96 MHz

PLLQ should be 4, gets 192 MHz to 48 MHz (SDIO/USB) [was 8]

PLLM should be 25 if you have an external 25 MHz source [was 8]

AHB should be DIV1 [was div 4]

APB2 should be DIV2 [was div 8]

APB1 should be DIV4 [was undefined]

The example code for SDIO is here:

STM32F2xx_StdPeriph_Lib_V1.1.0\Project\STM32F2xx_StdPeriph_Examples\SDIO\uSDCard

I'll have to work through your other info.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
zeros_and_ones1991
Associate III
Posted on August 03, 2013 at 05:10

no it was not broken clive cuz i was working on the HSI not HSE . ...... any way like i told u , now im  sure that nothing else will be done to the RCC Registers ...... i guess. 

zeros_and_ones1991
Associate III
Posted on August 03, 2013 at 15:40

Hey clive , i solved the problem ...... well the problem was that in my Send_Command function , i wrote to the CMD register two times successively , and according to the manual , u should wait for like 3 SDIO CLK and 2 APB2 clk , thats why it worked on low frequencies of the Core ..... now i put a little delay between these two lines and the problem was solved . Thx alot for ur efforts bro .