cancel
Showing results for 
Search instead for 
Did you mean: 

MCO1 output doesn't output anything

cherobim
Associate
Posted on February 21, 2013 at 23:36

Hello all,

Can someone help me please?

I must be doing something wrong because I can't do something so trivial...

I'm trying to output HSI over MCO1, it must be something straightforward, but...

void cpu_init_mco( void )

{

GPIO_InitTypeDef GPIO_InitStructure;

/* Output HSE clock on MCO1 pin(PA8) ****************************************/ 

/* Enable the GPIOA peripheral */ 

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

/* Configure MCO1 pin(PA8) in alternate function */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

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);

/* HSE clock selected to output on MCO1 pin(PA8)*/

RCC_MCO1Config(RCC_MCO1Source_HSI, RCC_MCO1Div_5);

GPIO_PinAFConfig( GPIOA, GPIO_PinSource8, GPIO_AF_MCO );

}

Yes, there is no secret, just setup the pin to alternate and enable MCO1, I call this method after everything is been initialized, but I also tried after clock was set (after SystemInit is called), I tried 50MHz, 100MHz, I tried MCO2, in case something is not right with MCO1, well, I tried everything but the right thing lol. I tried use different clocks, like PLL, I have another board with HSE, I tried it with RCC_MCO1Source_HSE and nothing, I tried debug going through step-by-step (using OpenOCD + STLink) - nothing, ok maybe in debug mode clock wont be there, so I put a while(1) to make execution stop in there, in case there is somewhere it's messing up with the pin - nothing. Tried without ST-Link, then as a desperate action tried other things like setting GPIO mode to output lol.

Apart this code snippet, is there anything else I need to do to have MCOx with clock? 

If anyone can help, that would be very appreciated!

Many Thanks,

Marcio.

EDIT: forgot to mention, I'm using STM32F407VGT6 (Mikroe) and STM32F405RGT6 (Cerb40). Thanks!

#stm32-mco-clock-output
6 REPLIES 6
Posted on February 22, 2013 at 03:21

Honestly that looks reasonable. Are we sure PA8 is not connected to something else here?

Maybe you can toggle an LED to confirm the board has your code on it. Keil and IAR have an issue with people selecting the simulator instead of the hardware, but not sure this is the case here.

Maybe toggle GPIO A8 manually?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 22, 2013 at 03:24

Cerb40 looks like a breakout board, so direct connection there.

http://wiki.tinyclr.com/index.php?title=FEZ_Cerb40_Developer

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
nakulrao
Associate II
Posted on February 22, 2013 at 05:37

Hi

I have used the following code in one of my projects and can guarantee that it works. The only difference is that I am putting the HSE on PA8. However that would be a piece of cake to change. :)


void MCO1_Init(void)

{

GPIO_InitTypeDef GPIO_InitStructure;


RCC_ClockSecuritySystemCmd(ENABLE);


/* 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_3);

}

Posted on February 22, 2013 at 09:30

Just tried the code in original post (on a STM3240G-EVAL) and it surely outputs a jittery cca 3.2MHz on PA8. Outputting HSE works as expected, too.

> Maybe toggle GPIO A8 manually?

+1

JW

cherobim
Associate
Posted on February 22, 2013 at 22:06

Thank you so much guys for all the answers...

I'm so sorry to raise such discussion, but I think (quite sure) that it's my USB oscilloscope...that's the only thing. I did try to find something to measure, so checked the JTAG and I saw pulses, I get pulses also from my UART, but they are all low speed. I tried to toggle the PA8 itself by software, it goes fine, but it's under 1MHz (I have to say, it looks horrible what was supposed to be square wave lol), using HSI (16MHz) and even dividing by 5 will be 3.2 MHz, higher than 1MHz where I suspect it's the limit of my scope...

That's what happen when buy a $100 USB scope!

I will close my eyes and carry on supposing the clock is there and see what will happen.

pmoore
Associate II
Posted on February 26, 2013 at 01:57

You could try counting the MCO1 pulses using a counter input jumped over to PA8. 

I've had good success counting TTL pulses beyond 6MHZ with an F105, which has lower core, timer, and I/O speed limits.