cancel
Showing results for 
Search instead for 
Did you mean: 

How to Check HSE is Connected To STM32

JThom.15
Associate III

Hi,

I am using STM32F205 Board for our development. We were using HSI (16MHZ) as the clock and found out that HSI has issues with high temperatures. I am calibrating HSITRIM value to fix the clock drift issue and we already have 50 boards manufactured. 

Now we decided to use crystal oscillator (25MHz) as HSE.

How do I determine if we connected external crystal oscillator to stm32 to configure the clock correctly?

8 REPLIES 8
STTwo-32
ST Employee

Hello @JThom.15 

You can use MCO1 or MCO2 to output the HSE Clock and visualise it to insure that it is working fine. For more details, take a look at the RM0033. You can also refer to this article.

Best Regards.

STTwo-32 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Check HSERDY bit.

Perhaps bench tick counts vs RTC second

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

Currently we are using MCO1 and MCO2 pins for i2c comms, so we cant really monitor MCO1 and MCO2

So Once I configure the the clock with HSE, wait for HSERDY bit to set (How long do we need to wait?), if not set then reconfigure clock with HSI?

 

Once you enable the HSE, The HSERDY flag in the RCC clock control register (RCC_CR) indicates if the high-speed
external oscillator is stable or not. At startup, the clock is not released until this bit is set by hardware. So you can do exactly as you descripted. You can refer to the HSE config on this example.

Best Regards.

STTwo-32

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

JThom.15
Associate III

Hi @STTwo-32 ,

Thanks for the reply,

The issue that I'm currently facing when I try to configure HSE, the board which doesn't have an external Crystal crashes .

The system Crashes here when I configure RCC_OscConfig 

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
void SystemClock_ConfigHSE(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;  
	
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 13;
  RCC_OscInitStruct.PLL.PLLN = 195;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 4;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
  {
    Error_Handler();
  }

   /** Enables the Clock Security System
  */
  HAL_RCC_EnableCSS();
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  
}
LCE
Principal

That's no big surprise, if you only enable HSE which is not there.

I have not yet used CSS, but I think it must have HSI enabled, and with the first HAL_RCC_OscConfig() you are turning it off.

So keep the HSI enabled:

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON; 

And not sure about this: maybe put the enable CSS before that call. 

As I've said previously:

> How do we identify if there is an external clock connected to the board to configure the clock correctly?

What do you mean by "external clock", a complete external oscillator (which generates clock by itself, even without STM32), or a crystal?

In either case, you can use the fact that HSE/N (HSE_RTC) is fed into TIM11_CH1 (see TIM11_OR description). So start with running from HSI+PLL; and after configuring HSE to run, set TIM11_OR to HSE_RTC and TIM11_CH1 to capture. If captures occur regularly at the expected rate, then you have a clock on HSE.

In any case, I don't think this is something you can pull out using Cube/HAL/CubeMX. Cube/HAL was not designed for this sort of things. So, you have to write your own RCC setup and check routines.

JW