Skip to content

Commit 1d37f5e

Browse files
skuepHiFiPhile
authored andcommitted
Added improvements with regards to SOF timing jitter
1 parent 76413a9 commit 1d37f5e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,13 @@ void dcd_int_handler(uint8_t rhport) {
627627
// dcd_ep_ctr_handler(), so less need to loop here. The other interrupts shouldn't
628628
// be triggered repeatedly.
629629

630+
/* Put SOF flag at the beginning of ISR in case to get least amount of jitter if it is used for timing purposes */
631+
if(int_status & USB_ISTR_SOF) {
632+
clear_istr_bits(USB_ISTR_SOF);
633+
if (tu_stm32_sof_cb) tu_stm32_sof_cb();
634+
dcd_event_sof(0, USB->FNR & USB_FNR_FN, true);
635+
}
636+
630637
if(int_status & USB_ISTR_RESET) {
631638
// USBRST is start of reset.
632639
clear_istr_bits(USB_ISTR_RESET);
@@ -664,11 +671,6 @@ void dcd_int_handler(uint8_t rhport) {
664671
dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
665672
}
666673

667-
if(int_status & USB_ISTR_SOF) {
668-
clear_istr_bits(USB_ISTR_SOF);
669-
dcd_event_sof(0, USB->FNR & USB_FNR_FN, true);
670-
}
671-
672674
if(int_status & USB_ISTR_ESOF) {
673675
if(remoteWakeCountdown == 1u)
674676
{

src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
130130
// this callback and defining a custom mapping in your application
131131
TU_ATTR_WEAK uint8_t tu_stm32_edpt_number_cb(uint8_t addr);
132132

133+
// This callback is called on SOF and can be used to e.g. capture a timer value for timing purposes
134+
TU_ATTR_WEAK void tu_stm32_sof_cb(void);
135+
133136
// prototypes
134137
TU_ATTR_ALWAYS_INLINE static inline __IO uint16_t* pcd_ep_rx_cnt_ptr(USB_TypeDef * USBx, uint32_t bEpNum);
135138
TU_ATTR_ALWAYS_INLINE static inline __IO uint16_t* pcd_ep_tx_cnt_ptr(USB_TypeDef * USBx, uint32_t bEpNum);

0 commit comments

Comments
 (0)