NUCLEO-H743ZI2: Same binary on two identical boards → different USB SOF callback count (≈1000 vs ≈2000)
Hello everyone,
I am facing a confusing behavior with USB SOF events on two identical STM32 boards and I would appreciate any insight.
Hardware
-
2 × NUCLEO-H743ZI2
-
Same MCU revision (checked device ID, revision ID – identical)
-
Same USB connection to the same PC (USB OTG FS, device mode)
Software
-
Exactly the same firmware binary programmed on both boards
-
STM32 HAL + CubeMX generated project
-
USB CDC device (USB OTG FS)
-
No conditional compilation, no board-specific code
What I want to measure
I wanted to check:
-
Whether USB SOF events are really occurring every 1 ms
-
Whether SOF can be considered a reliable timing source
So I implemented a very simple counter in the SOF callback:
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
#else
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
#endif
{
sof_eventc++;
USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData);
}
Additionally:
-
TIM2 is configured as a 1 Hz timer
-
In the TIM2 overflow interrupt, I read and print sof_eventc
-
Output is monitored via a serial terminal
-
Counter is reset every second
Expected behavior
Since USB Full Speed SOF is 1 ms:
-
I expect ≈ 1000 SOF events per second
Actual behavior
This is where it becomes strange:
-
Board #1:
~996 SOF events per second
(occasionally 995 or 997 – looks perfectly reasonable) -
Board #2:
~1994 SOF events per second
(almost exactly 2×)
Both boards are running:
-
the same binary
-
same clock configuration
-
same USB host
-
same cable and port
Additional observation
On Board #2 only:
-
When I send data from the host (PC → device), i.e. any USB receive activity:
-
The SOF count drops to ~1930
-
The value becomes unstable / inconsistent
-
On Board #1, USB traffic does not affect the SOF count significantly.
My questions
-
How is it possible that two identical NUCLEO-H743ZI2 boards, running the exact same firmware, produce:
-
~1000 SOF callbacks on one board
-
~2000 SOF callbacks on the other?
-
-
Is HAL_PCD_SOFCallback() guaranteed to be called exactly once per USB frame, or can it be:
-
triggered multiple times per frame?
-
skipped or coalesced under USB traffic?
-
-
Can USB traffic (RX activity) legitimately reduce the number of SOF callbacks delivered to the application?
-
Is counting SOF callbacks a valid way to measure the USB 1 ms frame timing, or should another mechanism (e.g. DSTS.FNSOF) be used instead?
At this point I am unsure whether:
-
I am misunderstanding the SOF callback semantics, or
-
there is some subtle USB OTG / HAL / interrupt behavior that differs per board even with the same binary
Any ideas, explanations, or references would be greatly appreciated.
Thank you.
