Electronic – Why does usb have start of frame packets

stm32usbusb device

I'm developing some high-speed USB firmware for the STM32F746VG, and on page 1411 (under section 37.16.3, step 2), it tells me that I should enable start of frame interrupts.

I know that usb hosts send a start of frame packet once every 125uS in high-speed mode, but why should my device care about SOF packets, aside from timekeeping? What could I possibly do in an interrupt service routine that would trigger on every start of frame packet?

Best Answer

I believe the original 1 ms (1 kHz) start of frame interrupt was to give devices to cheap but accurate timing. The accuracy spec on that is rather tight.

If you don't need to do accurate timing, or you have your own crystal, then you don't need to know when USB frames start. The host initiates all transactions, even when you send, so your hardware and firmware will know that way when to do what.

I've created a bunch of USB devices, and have not used start of frame detection at all so far. If you are using a canned library, then possibly the library uses SOF for some internal timing or to know when to do housekeeping. If the library docs say you need SOF, then you need SOF.