Skip to content

Fix isochronous out endpoints only receiving data on odd frames (on the STM32f411 mcu) - #152

Open
theawsomeavr wants to merge 1 commit into
dmitrystu:masterfrom
theawsomeavr:master
Open

Fix isochronous out endpoints only receiving data on odd frames (on the STM32f411 mcu)#152
theawsomeavr wants to merge 1 commit into
dmitrystu:masterfrom
theawsomeavr:master

Conversation

@theawsomeavr

Copy link
Copy Markdown

Description

When using isochronous out endpoints for receiving USB audio packets on an
STM32f411, data is only received on odd frames, ignoring half of the USB audio data.

The reference manual RM0383
on page 789 under the internal data flow states that:

"The core receives data on an isochronous OUT endpoint in a particular frame only if the
following condition is met:
EONUM (in OTG_FS_DOEPCTLx) = SOFFN[0] (in OTG_FS_DSTS)
."

The EONUM bit in the DOEPCTL register is normally set (for each endpoint using
bits SEVNFRM and SODDFRM) whenever a USB transfer complete interrupt is
triggered to the opposite value of the current frame, so the endpoint
receives data on the next frame.

The fix

Implemented the processing of the USB_OTG_GINTSTS_OEPINT OUT interrupt event
on evt_poll core function so that it can catch the transfer complete
interrupt event USB_OTG_DOEPINT_XFRC for each endpoint, and then update the
selected frame bit EONUM if the endpoint is isochronous.

Also unmasked the bits USB_OTG_DOEPMSK_XFRCM and USB_OTG_GINTMSK_OEPINT on
registers OTGD->DOEPMSK and OTG->GINTMSK respectively in order for the USB
core to trigger and set said flags.

I've implemented similar handling to what is done on tinyUSB's dcd_dwc2.c#L387 on
function edpt_schedule_packets which is called whenever an out endpoint triggers an interrupt.

// control
if (depctl.type == DEPCTL_EPTYPE_ISOCHRONOUS) {
  const dwc2_dsts_t dsts = {.value = dwc2->dsts};
  const uint32_t odd_now = dsts.frame_number & 1u;
  if (odd_now != 0) {
    depctl.set_data0_iso_even = 1;
  } else {
    depctl.set_data1_iso_odd = 1;
  }
}

Demo

https://github.com/theawsomeavr/libusb_stm32_audio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant