Skip to main content
vicki19880929
Associate III
April 8, 2014
Question

is it possible to see system clock from GPIO?

  • April 8, 2014
  • 3 replies
  • 850 views
Posted on April 08, 2014 at 13:28

Hi all, 

I'm working on stm32l MCU and wonder if it is possible to get the system clock waveform from GPIO output pin?  If yes, where could I find it from the datasheet?

Thanks a lot,

Shan
    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    April 8, 2014
    Posted on April 08, 2014 at 15:23

    The MCO pin (PA.8) should allow fractional internal clocks to be output. Some abstracted, but synchronous, clocks can be generated by timers.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    vicki19880929
    Associate III
    April 9, 2014
    Posted on April 09, 2014 at 05:13

    Thanks clive!  That's a good start.  

    I gave it a try and found the PA8 waveform frequency isn't the SYSCLK freq 32MHz but only around 2.17MHz.  The frequency did change if I changed the divider value.  Could anyone point out  if I did anything wrong here?  Many thanks!  :)

       

    int main(void)

    {

      GPIO_InitTypeDef GPIO_InitStructure;

      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

      GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_MCO);

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;

      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

      GPIO_Init(GPIOA, &GPIO_InitStructure);

      RCC_MCOConfig(RCC_MCOSource_SYSCLK, RCC_MCODiv_1);

        while(1) {

            delay();

        }

    }

     

    waclawek.jan
    Super User
    April 9, 2014
    Posted on April 09, 2014 at 09:53

    Looks good.

    Your SYSCLK probably is actually around 2MHz - I guess it never changed from the default nominally 2.097MHz MSI clock.

    JW