2013-12-19 06:46 AM
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);
}
2013-12-19 07:03 AM
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 whatRCC_MCO1Config
() does.
If not - look up how to use the alternate pint outs.
2013-12-19 07:15 AM
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...
2013-12-19 07:37 AM
It worked as soon as I called SystemInit() beforehand.
2013-12-19 08:06 AM
Hi
Glad you got it working. Sorry, I did not notice that you had already configured the alternate function.2013-12-19 08:15 AM
Isn't the MCO pin on the SYSCFG peripheral/clock
2014-01-06 02:53 AM
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?2014-01-06 03:13 AM
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);