2026-02-12 7:48 AM - last edited on 2026-02-12 8:22 AM by Andrew Neil
I am working on time synchronization between two identical Blackpill STM32F401CCU6 boards.
Both boards:
Use internal HSI oscillator
Same firmware
Same clock configuration
TIM2 configured as 1 MHz free-running counter (1 µs resolution)
32-bit counter (auto-reload = 0xFFFFFFFF)
Clock configuration:
HSI ON
PLL enabled (HSI → PLL → SYSCLK)
SYSCLK = 32 MHz
TIM2 prescaler = 31 → 1 MHz timer tick
Initialization
Synchronization Method
One board acts as MASTER
Other board acts as SLAVE
Communication via UART (115200 baud)
Master sends a 5-byte sync packet:
0xAA + 4-byte counter value
Slave receives and sets:
htim2.Instance->CNT = received_counter; Initial sync works correctly.
After synchronization:
Drift increases over time
After 30 minutes → ~2400 ms difference
This corresponds to approximately:
~1300 ppm difference between the two boards.
Both boards are identical and running the same firmware.
Is this drift expected when using HSI?
What is the typical HSI accuracy (ppm) for STM32F401?
Would switching to:
External crystal (HSE)
LSE
significantly reduce drift?
Is there a recommended method for long-term time synchronization between two STM32s without external clock sharing?
No hardware clock sharing between boards
No external crystal currently used
Only UART connection between boards, and removed after sync
I would appreciate any guidance on improving long-term timing stability.
Thank you.
Solved! Go to Solution.
2026-02-17 1:59 AM
Unfortunately, not applicable. The screens will be placed stationary place and cameras mounted on a vehicle.
2026-02-17 2:00 AM
Do you have any suggestions for XO or TCXO?
2026-02-17 3:49 AM
Any crystal oscillator with MCU power supply range.
2026-02-17 4:08 AM - edited 2026-02-18 1:14 AM
Even with a low drift clock source I would calibrate the clocks. As the error of both clocks can be opposite so the differential error can be higher. Connect the boards to let them sync (let one board output a square wave and the other capture it). You can do this once and then save the calibration to non volatile memory. Since both modules likely have the same ambient temperature I think their differential drift will be minimal.
2026-02-18 8:14 AM
Another option could be to use a GPS module with a sync pulse output - this will pulse once per second with an accuracy of 1uS (I think, but it's been a while since I've done this!).