2022-02-02 10:40 PM
hey there
I have a PCB which has a STM32F030C8T6 and a 11.0592MHz crystal on it.
the thing is that when I enable HSE and try to toggle a pin every 500ms it takes way longer than expected, here is the code
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_TogglePin(LED1_GPIO_Port,LED1_Pin);
HAL_Delay(500);
/* USER CODE END 3 */
}
pretty simple right? but way wrong results.
but as I set the clock to be HSI 8MHz(inner clock) everything works just fine and crisp!
I have also enabled CSS for clock security but in HSE case I dont see right results. why is that?
Solved! Go to Solution.
2022-02-04 09:19 PM
Many thanks to all who helped and gave me clues and hints.
I think that I found the solution: on my PCB, the soldered crystal was SMD. not sure why but recently these SMD crystals are not working as expected. so I swapped this one with a Dip and it worked just fine.
2022-02-02 10:48 PM
Did you tell your source code that you are using an HSE with 11.x MHz ?
HAL_Delay() is based on the SysTick, usually set to 1 ms.
There's a #define EXTERNAL_CLOCK_VALUE, I think in *_hal_conf.h .
2022-02-02 10:51 PM
I use CubeMX, I guess Cube should handle this... isnt it?
I've checked file stm32f0xx_hal_conf.h. here is the definition
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)11059200) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
seems right, but I can not see good results though...
2022-02-03 03:32 AM
Okay, that looks good.
Yes, Cube should handle that, but always check the sources, every now and then Cube omits an important setting.
I would try to "follow" all the Systick settings to find out where and how it is set. Maybe check some register settings via debugger or UART.
Then for testing, I would toggle a GPIO with the SysTick to find out what its actual period is.
2022-02-03 07:02 AM
output MCO to a pin to verify frequency is what you think it is.
Not sure how well HAL works with frequencies that are not multiple of 1 MHz.
Define "way longer", perhaps the relation could provide a clue.
2022-02-03 09:15 AM
Remember to define HSE_VALUE in the project preprocessor defines. Not [only] in ... hal_conf.h.
2022-02-04 09:13 PM
@TDK by "output MCO to a pin to verify frequency is what you think it is." you mean toggle a GPIO in SysTick?
"way longer" is actually not same and I didnt find any relation between, say different HAL_Delay(value) and the seen delay in between HAL_GPIO_TogglePin(LED1_GPIO_Port,LED1_Pin);
2022-02-04 09:14 PM
I really dont think that's the case, one #define is always sufficient and works.
2022-02-04 09:19 PM
Many thanks to all who helped and gave me clues and hints.
I think that I found the solution: on my PCB, the soldered crystal was SMD. not sure why but recently these SMD crystals are not working as expected. so I swapped this one with a Dip and it worked just fine.
2022-02-05 07:28 AM
I mean MCO, which is the direct output of the system clock source with an optional prescaler. See RCC settings in CubeMX, or reference manual.