From 417b167c28bdb65f4b906f0d6a2eb896a16b3637 Mon Sep 17 00:00:00 2001 From: Simon Kueppers Date: Sun, 8 Jan 2023 15:32:30 +0100 Subject: [PATCH] Switched from usb-stack assisted SOF measurement to pure software solution to keep API compatibility to the original tinyusb --- stm32/aioc-fw/Src/usb.c | 9 ++------- stm32/aioc-fw/Src/usb.h | 2 +- stm32/aioc-fw/Src/usb_audio.c | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/stm32/aioc-fw/Src/usb.c b/stm32/aioc-fw/Src/usb.c index 15d7054..426ef39 100644 --- a/stm32/aioc-fw/Src/usb.c +++ b/stm32/aioc-fw/Src/usb.c @@ -7,7 +7,8 @@ // We have ISOCHRONOUS endpoints defined that share the same endpoint number, but have opposing directions. // However with STM32 hardware, ISOCHRONOUS endpoints use both RX and TX structures of the same endpoint register in hardware -// We circumvent a clash by defining our own custom endpoint map for the tiny usb stack +// We circumvent a clash by defining our own custom endpoint map for the tiny usb stack. +// This callback is probably not needed with new versions of tinyusb uint8_t tu_stm32_edpt_number_cb(uint8_t addr) { switch (addr) { @@ -38,12 +39,6 @@ uint8_t tu_stm32_edpt_number_cb(uint8_t addr) } } -void tu_stm32_sof_cb(void) -{ - /* Capture timer value */ - USB_SOF_TIMER->EGR = TIM_EGR_CC1G; -} - // FIXME: Do all three need to be handled, or just the LP one? // USB high-priority interrupt (Channel 74): Triggered only by a correct // transfer event for isochronous and double-buffer bulk transfer to reach diff --git a/stm32/aioc-fw/Src/usb.h b/stm32/aioc-fw/Src/usb.h index 4283cd7..056b08f 100644 --- a/stm32/aioc-fw/Src/usb.h +++ b/stm32/aioc-fw/Src/usb.h @@ -5,7 +5,7 @@ #include "usb_serial.h" #define USB_SOF_TIMER TIM2 -#define USB_SOF_TIMER_CCR TIM2->CCR1 +#define USB_SOF_TIMER_CNT TIM2->CNT #define USB_SOF_TIMER_HZ 72000000UL void USB_Init(void); diff --git a/stm32/aioc-fw/Src/usb_audio.c b/stm32/aioc-fw/Src/usb_audio.c index 5db78d7..a78ae76 100644 --- a/stm32/aioc-fw/Src/usb_audio.c +++ b/stm32/aioc-fw/Src/usb_audio.c @@ -581,7 +581,7 @@ void tud_audio_feedback_params_cb(uint8_t func_id, uint8_t alt_itf, audio_feedba TU_ATTR_FAST_FUNC void tud_audio_feedback_interval_isr(uint8_t func_id, uint32_t frame_number, uint8_t interval_shift) { static uint32_t prev_cycles = 0; - uint32_t this_cycles = USB_SOF_TIMER_CCR; /* Load from capture register, which is set in tu_stm32_sof_cb */ + uint32_t this_cycles = USB_SOF_TIMER_CNT; uint32_t feedback; /* Calculate number of master clock cycles between now and last call */