cancel
Showing results for 
Search instead for 
Did you mean: 

how to allow the clock to be output onto the external MCO pin

yasamin
Associate II
Posted on May 06, 2015 at 13:03

I want to have a sample of system clock at MCO pin of STM32F107RC micro controller.

I use dspin firmware library for driving stepper motor.

The on board crystal is 8MHz and system clock set to be 72MHz.

I add this code to ''dspin.c'':

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

and I add the below line code in ''SetSysClockTo72()'' function at ''system_stm32f10x.c'' file.

RCC->CFGR &= (uint32_t)0xF6FFFFFF;   //HSE clock selected as MCO source

But I don't have no clock output on this pin.

please guide me

thanks

yasamin
10 REPLIES 10
Posted on May 06, 2015 at 13:17

RCC->CFGR = (RCC->CFGR & (uint32_t)0xF0FFFFFF) | (uint32_t)0x08000000;

JW

yasamin
Associate II
Posted on May 09, 2015 at 11:24

Hi

I add the below code

RCC->CFGR = (RCC->CFGR & (uint32_t)0xF0FFFFFF) | (uint32_t)0x08000000; 

in ''SetSysClockTo72(void)'' function at ''system_stm32f10x.c''.

But I have the same problem yet!!!

please guide me to solve my problem.

thanks

stm32forum
Associate II
Posted on May 09, 2015 at 12:47

MCO pin should be configured in alternate function mode.

yasamin
Associate II
Posted on May 10, 2015 at 07:14

Hi

I configured MCO pin in alternate function mode by adding this code to ''dspin.c'':

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

is it wrong?

and I add the below line code in ''SetSysClockTo72()'' function at ''system_stm32f10x.c'' file.

RCC->CFGR = (RCC->CFGR & (uint32_t)0xF0FFFFFF) | (uint32_t)0x08000000; 

But I don't have no clock output on this pin.

yasamin

Posted on May 10, 2015 at 13:49

Evidently you're doing something wrong, or it would work..

{
GPIO_InitTypeDef GPIO_InitStructure;
/* Output HSE clock on MCO pin ---------------------------------------------*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_MCOConfig(RCC_MCO_HSE);
// RCC_MCOConfig(RCC_MCO_SYSCLK);
// If these work you'll need to check if you have PLL2 configured and running
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
yasamin
Associate II
Posted on May 11, 2015 at 11:21

thanks

it is solved

Ahmed.Waqar
Associate II
Posted on May 12, 2015 at 13:25

I am using external interrupts. STM32F407 is not handling interrupt at speed of greater than 2MHz.

/* Includes ------------------------------------------------------------------*/

#include ''stm32f4xx.h''

#include ''stm32f4xx_syscfg.h''

#include ''stm32f4xx_rcc.h''

#include ''stm32f4xx_gpio.h''

#include ''stm32f4xx_exti.h''

#include ''misc.h''

EXTI_InitTypeDef   EXTI_InitStructure;

void EXTILine0_Config(void);

void LEDInit(void);

void main(void)

{

 LEDInit();

 EXTILine0_Config();

 EXTI_GenerateSWInterrupt(EXTI_Line0);

  while (1)

  {

  }

}

void LEDInit()

{

  GPIO_InitTypeDef  GPIO_InitStructure;

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

  /* Configure the GPIO_LED pin */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

}

void EXTILine0_Config(void)

{

  GPIO_InitTypeDef   GPIO_InitStructure;

  NVIC_InitTypeDef   NVIC_InitStructure;

  /* Enable GPIOA clock */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

  /* Enable SYSCFG clock */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

  /* Configure PA0 pin as input floating */

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Connect EXTI Line0 to PA0 pin */

  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);

  /* Configure EXTI Line0 */

  EXTI_InitStructure.EXTI_Line = EXTI_Line0;

  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;

  EXTI_InitStructure.EXTI_LineCmd = ENABLE;

  EXTI_Init(&EXTI_InitStructure);

  /* Enable and set EXTI Line0 Interrupt to the lowest priority */

  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

}

void EXTI0_IRQHandler(void)

{

              if (((EXTI->PR & EXTI_Line0) != (uint32_t)RESET) && ((EXTI->IMR & EXTI_Line0) != (uint32_t)RESET))

             {

            GPIOD->ODR ^= 0x8000;

            EXTI->PR = 0x0001;

        }

}

Please help me!

Amel NASRI
ST Employee
Posted on May 14, 2015 at 15:05

Hi Ahmed,

You have already submitted your question in another thread (

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/How%20fast%20we%20can%20go%20with%20EXTI

).

Please avoid switching from one topic to another in the same thread.

Thanks & Best Regards

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on May 14, 2015 at 16:55

I think he posted here first, as creating a ''New'' thread is far less apparent/obvious than replying to an older one.

Please just delete patently Off-Topic posts, or move them if the forum software permits that.

Thanks, -Clive

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..