2024-09-30 02:54 AM
Hello,
I have designed my PCB with STM32F103CBT6 and a 16MHz crystal oscillator. When I generate code with CubeMX with the clock configuration like the one of the attached images, 'SystemCoreClock', a global variable shows it's 36MHz while it should be 72MHz.
Also, the led blink interval should wait 1000ms while it does only 500ms. It seems the clock is not running properly.
As you can see in the last image, I set breakpoints at Error_Handler(), but I couldn't catch any error there so I assume the config was okay.
Here is what I did:
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
HAL_Delay(1000);
I use PlatformIO to build/upload/debug on ubuntu 24.04.
I would appreciate if someone could guide me how to debug this. I'm a noob at electronics but I have a logic analyzer, 4ch 100MHz oscilloscope, and lab power supply.
MCU: STM32F103CBT6
Crystal Oscillator: X322516MLB4SI
Load capacitor: 10pF
Solved! Go to Solution.
2024-09-30 06:39 AM
@SofLit wrote:
@hkyu wrote:The datasheet says it's just a crystal.
Here it says 16MHz
Yes, it's 16MHz. Does it mean the clock config is wrong?
Do you think the clock config is okay. the external crystal is working properly, and the schematic is okay, but something else is causing the problem? I just uploaded the same code to the other board with the same setup, the result is the same, so maybe this is not specific to this board.
2024-09-30 08:03 AM
SystemCoreClock is 36MHz while it should be 72MHz after SystemClock_Config().
2024-09-30 08:13 AM - edited 2024-09-30 08:14 AM
In the file stm32f1xx_hal_conf.h,
Check your HSE value.
Replace the definition of HSE value:
#define HSE_VALUE 8000000U
by
#define HSE_VALUE 16000000U
2024-09-30 09:52 AM
Thank you so much!
It was because I forgot to add the following line in platformio.ini:
board_build.stm32cube.custom_config_header = yes
https://docs.platformio.org/en/latest/frameworks/stm32cube.html#custom-configuration-header
That is why PlatformIO overrides any custom config headers and set `HSE_VALUE` as the default 8MHz. Sorrry my bad!