Time Drift Between 2 Identical Black Pill boards
STM32F401 (Blackpill) – 2.4s Drift in 30 Minutes Between Two Identical Boards Using TIM2 (HSI Clock)
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
- Both boards started in STANDALONE mode
- Both boards waited for button interrupt
- The board which gets interrupt became MASTER
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;- UART disabled and connection removed
Initial sync works correctly.
Problem
After synchronization:
Drift increases over time
After 30 minutes → ~2400 ms difference
- After 50 minutes → ~3200 ms difference
This corresponds to approximately:
~1300 ppm difference between the two boards.
Both boards are identical and running the same firmware.
Questions
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?
Additional Notes
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.



