summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Kueppers <[email protected]>2022-11-06 12:40:14 +0100
committerMengsk <[email protected]>2022-12-29 12:33:16 +0100
commit1d37f5ef9b94d53d8a90b73934913aa4252011e5 (patch)
treec74f99ec24b99a8e7894f8c78ae0894ec58d55fc
parent76413a95d4463d11232810e42d4f1a64a30aed2b (diff)
Added improvements with regards to SOF timing jitter
-rw-r--r--src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c12
-rw-r--r--src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h3
2 files changed, 10 insertions, 5 deletions
diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
index fefa7a330..d6ca59756 100644
--- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
+++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
@@ -627,6 +627,13 @@ void dcd_int_handler(uint8_t rhport) {
// dcd_ep_ctr_handler(), so less need to loop here. The other interrupts shouldn't
// be triggered repeatedly.
+ /* Put SOF flag at the beginning of ISR in case to get least amount of jitter if it is used for timing purposes */
+ if(int_status & USB_ISTR_SOF) {
+ clear_istr_bits(USB_ISTR_SOF);
+ if (tu_stm32_sof_cb) tu_stm32_sof_cb();
+ dcd_event_sof(0, USB->FNR & USB_FNR_FN, true);
+ }
+
if(int_status & USB_ISTR_RESET) {
// USBRST is start of reset.
clear_istr_bits(USB_ISTR_RESET);
@@ -664,11 +671,6 @@ void dcd_int_handler(uint8_t rhport) {
dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
}
- if(int_status & USB_ISTR_SOF) {
- clear_istr_bits(USB_ISTR_SOF);
- dcd_event_sof(0, USB->FNR & USB_FNR_FN, true);
- }
-
if(int_status & USB_ISTR_ESOF) {
if(remoteWakeCountdown == 1u)
{
diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h
index d6f10c5a9..40af9b3a5 100644
--- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h
+++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h
@@ -130,6 +130,9 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
// this callback and defining a custom mapping in your application
TU_ATTR_WEAK uint8_t tu_stm32_edpt_number_cb(uint8_t addr);
+// This callback is called on SOF and can be used to e.g. capture a timer value for timing purposes
+TU_ATTR_WEAK void tu_stm32_sof_cb(void);
+
// prototypes
TU_ATTR_ALWAYS_INLINE static inline __IO uint16_t* pcd_ep_rx_cnt_ptr(USB_TypeDef * USBx, uint32_t bEpNum);
TU_ATTR_ALWAYS_INLINE static inline __IO uint16_t* pcd_ep_tx_cnt_ptr(USB_TypeDef * USBx, uint32_t bEpNum);