cancel
Showing results for 
Search instead for 
Did you mean: 

Hello, i have to solve the task: Configure the MCU to operate with a system clock frequency of 72MHz. Make sure that the clock signal is derived from the external oscillator (HSE). Find a way to show the system clock frequency (SYSCLK) at an output pin.

DKunz.1
Associate II

This is my code so far.

I solved the clock frequency of 72MHz with an excel sheet and imported the file which got created, so that is working. My HSE Speed is 8 Mhz.

Now i dont get how to mirror the System Clock onto the MCO output pin.

This is what i tried...

Can you guys help me?

I am really new to MCU Programming.

We are working with a STM32F407VG

Thanks in advance!

________________________________________________________________________________

#include "stm32f4xx.h"

#include "stm32f4xx_gpio.h"

#include "stm32f4xx_rcc.h"

#define HSE_VALUE (uint32_t)8000000

GPIO_InitTypeDef GPIO;

int main(void)

{

 int i = 0;

 SystemInit();

 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

 GPIO.GPIO_Mode = GPIO_Mode_AF;

 GPIO.GPIO_OType = GPIO_OType_PP;

 GPIO.GPIO_Speed = GPIO_Speed_50MHz;

 GPIO.GPIO_PuPd = GPIO_PuPd_NOPULL;

 GPIO.GPIO_Pin = GPIO_Pin_9;

 GPIO_Init(GPIOC, &GPIO);

 //GPIO_SetBits(GPIOC, GPIO_Pin_9);

 while (1)

 {

   i++;

 }

}

5 REPLIES 5
TDK
Guru

You should be able to select this configuration within CubeMX and have it generate the code. MCO output can be selected within System Core -> RCC.

If you feel a post has answered your question, please click "Accept as Solution".
DKunz.1
Associate II

Thanks for you answer.

I didnt know this software exists.

Sadly we are not allowed to work with it...

But still i managed to get the code out of it

thanks

/**
  * @brief  Output System Clock on MCO2
  * @param  None
  * @retval None
  */
void MCO2_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure = {0};
 
  /* Config MCO2 PC9 to Alternate function */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_MCO);
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
 
  /* MCO CLK pin configuration */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  RCC_MCO2Config(RCC_MCO2Source_SYSCLK, RCC_MCO2Div_5); // Select divider from available options
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Yeah it sounds like a homework problem. Up to you what you want to use and how much you want to understand things. If you’re really interested, it’s probably worth looking at the reference manual to understand how it works.
If you feel a post has answered your question, please click "Accept as Solution".
DKunz.1
Associate II

Okay thanks to you all it works 🙂