Skip to main content
PKuma.51
Associate
May 10, 2020
Question

UART not responding under OSC BYPASS Mode.

  • May 10, 2020
  • 4 replies
  • 975 views

Hello Guys,

I am trying to setup UART under oscillator bypass mode in STM32f446RE Nucleo Board. I have created a new project in CubeIDE with UART under Asynchronous mode. I have commented out the SystemClock_Config and written my code for oscillator bypass mode even though everything can be done via code generation tool ( Part of learning ). But UART is not responding. Please find the below-attached project.

char data[] = "PK is Working\r\n";
 
int main(void)
{
 HAL_Init();
 //SystemClock_Config();
 
 RCC_OscInitTypeDef Osc = {0};
 RCC_ClkInitTypeDef Clk = {0};
 
 Osc.OscillatorType = RCC_OSCILLATORTYPE_HSE;
 Osc.HSEState = RCC_HSE_BYPASS;
 HAL_RCC_OscConfig(&Osc);
 
 Clk.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
 Clk.AHBCLKDivider = RCC_SYSCLK_DIV2;
 Clk.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;
 Clk.APB1CLKDivider = RCC_HCLK_DIV2;
 Clk.APB2CLKDivider = RCC_HCLK_DIV2;
 
 HAL_RCC_ClockConfig(&Clk, FLASH_ACR_LATENCY_0WS);
 
 __HAL_RCC_HSI_DISABLE();
 
 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
 
 
 
 MX_GPIO_Init();
 MX_USART2_UART_Init();
 
 while (1)
 {
 HAL_UART_Transmit(&huart2, (uint8_t*) data, sizeof(data), HAL_MAX_DELAY);
 }
}

This topic has been closed for replies.

4 replies

TDK
May 10, 2020

Debug your code. Do all the calls to HAL_* return HAL_OK? Have you observed the TX line with a scope to verify it's not responding?

Your clock is pretty slow. Is your UART baud rate within tolerance?

"If you feel a post has answered your question, please click ""Accept as Solution""."
PKuma.51
PKuma.51Author
Associate
May 16, 2020

After some debugging, I found that when the function HAL_RCC_ClockConfig(&Clk, FLASH_ACR_LATENCY_0WS) exit, the value of SystemCoreClock changes from 16000000 to 12500000. I am expecting an HCLK of 4Mhz. The UART sometimes respond with random garbage values. I dont understand why this happens? Any solution guys?

waclawek.jan
Super User
May 16, 2020

You need to set properly the constant which determines the HSE frequency - you've copied some project based on a board which has 25MHz crystal at HSE.

I don't know which constant it is, I don't use Cube, but Clive mentioned it here many times in the past in similar cases.

JW

TDK
May 16, 2020

As waclawek.jan says, change HSE_VALUE to 8000000.

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