cancel
Showing results for 
Search instead for 
Did you mean: 

How can I calculate the clock frequency and Baud rate from code

LMI2
Lead

I have an heavily modified LCD Application/example for STM32F746 Discovery and Usart code from CubeMX. It looks like their clock frequencies do not match, that is the Baud rate is off. I would like know in which files is the clock frequency set up. And of course Baud rate too, I'll have to match that to the clock later.

3 REPLIES 3

The system should be able to decompose the RCC and PLL settings, and use the HSE_VALUE defined in stm32f7xx_hal_conf.h to set bad rates.

Clock stuff RCC file, baud rate U(S)ART files

  printf("Core=%d, %d MHz\n", SystemCoreClock, SystemCoreClock / 1000000);
  
  printf("HCLK=%d\n", HAL_RCC_GetHCLKFreq());
  printf("APB1=%d\n", HAL_RCC_GetPCLK1Freq());
  printf("APB2=%d\n", HAL_RCC_GetPCLK2Freq());

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

Do you mean that the CPU calculates the baud rate itself, no matter how strange the clock frequency is?

So this is enough (in Usart.c file.)?

huart6.Instance = USART6;
  huart6.Init.BaudRate = 9600;
  huart6.Init.WordLength = UART_WORDLENGTH_8B;
  huart6.Init.StopBits = UART_STOPBITS_1;
  huart6.Init.Parity = UART_PARITY_NONE;
  huart6.Init.Mode = UART_MODE_TX_RX;
  huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart6.Init.OverSampling = UART_OVERSAMPLING_16;
  huart6.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart6.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_UART_Init(&huart6) != HAL_OK)

LMI2
Lead

By the way, I have loop back working. I have to try connecting boards together next.