cancel
Showing results for 
Search instead for 
Did you mean: 

Put HSE on MCO1

jdcowpland
Associate II
Posted on December 19, 2013 at 15:46

I have this code that is trying to put my HSE clock onto MCO1 (A8) on my STM32F407 Discovery, but it doesn't work. Anyone know what's wrong?

#include ''stm32f4xx_gpio.h''
#include ''stm32f4xx_rcc.h''
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIOs clocks */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_MCO);
/* Configure MCO (PA8) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_MCO1Config(RCC_MCO1Source_HSE, RCC_MCO1Div_1);
}

7 REPLIES 7
chen
Associate II
Posted on December 19, 2013 at 16:03

Hi

I do not know why you are configuring the Port/Pin To look at the Clock output on PA8 - you have to configure the port/pin to alternate function and select MCO1 as the output for that port bit. I have not looked at the code but I assume that is what

RCC_MCO1Config

() does. If not - look up how to use the alternate pint outs.
jdcowpland
Associate II
Posted on December 19, 2013 at 16:15

All the rcc_mco1Config does is choose what clock to output on the pin and what prescaler to use. To enable the pin you still have to setup the port/pin using the gpio config as I did. I've found other posts of people looking to do the same thing, and their code is the same as mine and it worked. So I don't know what's different about mine...

jdcowpland
Associate II
Posted on December 19, 2013 at 16:37

It worked as soon as I called SystemInit() beforehand.

chen
Associate II
Posted on December 19, 2013 at 17:06

Hi

Glad you got it working.

Sorry, I did not notice that you had already configured the alternate function.

Posted on December 19, 2013 at 17:15

Isn't the MCO pin on the SYSCFG peripheral/clock

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jdcowpland
Associate II
Posted on January 06, 2014 at 11:53

Clive: I thought the whole point of the 

RCC_MCO1Config(RCC_MCO2Source_HSE,RCC_MCO1Div_1);

line was that it allowed you to select the clock source?

Posted on January 06, 2014 at 12:13

Clive: I thought the whole point of the 

RCC_MCO1Config(RCC_MCO2Source_HSE,RCC_MCO1Div_1); line was that it allowed you to select the clock source?

That wasn't however, my point.

  /* Enable SYSCFG clock */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

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