Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FSDEV fix/cleanup. #2574

Merged
merged 14 commits into from
Apr 11, 2024
Merged

FSDEV fix/cleanup. #2574

merged 14 commits into from
Apr 11, 2024

Conversation

HiFiPhile
Copy link
Collaborator

@HiFiPhile HiFiPhile commented Apr 5, 2024

Describe the PR

Tested on NUCLEO-G0B1RE, STM32L0538DISCO, STM32H573i-DK with audio, video and cdc_dual_ports examples.

@HiFiPhile HiFiPhile force-pushed the fsdev branch 3 times, most recently from eb34c2e to 34f3340 Compare April 5, 2024 13:33
Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fix, though I notice this PR disable double buffering for ISO (default behavior). If possible we should keep this, otherwise it may not keep up with 1023 packet size.

@@ -1055,8 +977,17 @@ bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet

pcd_set_eptype(USB, ep_idx, USB_EP_ISOCHRONOUS);

pcd_set_ep_tx_address(USB, ep_idx, pma_addr);
pcd_set_ep_rx_address(USB, ep_idx, pma_addr);
// Disable double buffering
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to keep double buffering for ISO if possible. Otherwise it may not keep up to 1023 byte per packet. Maybe we could find anothe way to fix this ?

@HiFiPhile
Copy link
Collaborator Author

HiFiPhile commented Apr 8, 2024

I would prefer to keep double buffering for ISO if possible. Otherwise it may not keep up to 1023 byte per packet.

In fact currently double buffering is not configured correctly, it's enabled but both buffer are pointed to the same address.
https://github.com/hathach/tinyusb/blob/d33fe38a6257bcdd60f51a57c9fd19ce2ad1f202/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c#L965C1-L967C76

Maybe it's better to fix the buffer stuff to enable true double buffering, since on older chips there is no mention that ISO double buffering can be disabled:
image
image

@HiFiPhile
Copy link
Collaborator Author

since on older chips there is no mention that ISO double buffering can be disabled:

Yeah it's broken on L0...

@hathach
Copy link
Owner

hathach commented Apr 9, 2024

since on older chips there is no mention that ISO double buffering can be disabled:

Yeah it's broken on L0...

thanks for testing it out, seems like we will definitely need double buffer for ISO.

src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c Dismissed Show dismissed Hide dismissed
@HiFiPhile
Copy link
Collaborator Author

I've reworked the PR, now it has correct ISO double buffering handing.

It's enabled only for device with 2048b PMA, smaller devices has 2 buffers point to the same address as before, otherwise they will fail to run some examples. In my tests I didn't see single buffering cause any issue.

Tested on L0, G0, H5 to be sure nothing broken.

I put each change in one commit hope it's easier to review...

@hathach
Copy link
Owner

hathach commented Apr 10, 2024

superb !! thank you, will review and test this out soon enough.

uint16_t remaining = xfer->total_len - xfer->queued_len;
uint16_t cnt = remaining >= xfer->max_packet_size ? xfer->max_packet_size : remaining;
pcd_set_ep_rx_cnt(USB, EPindex, cnt);
pcd_set_ep_rx_cnt(USB, EPindex, remaining);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the call with remaining should be removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot !
In fact I'm not sure if it's even necessary, pcd_set_ep_rx_cnt() only reduce buffer size.

if((xfer->total_len != xfer->queued_len)) /* TX not complete */
xfer_ctl_t *xfer = xfer_ctl_ptr(ep_addr);

/* Ignore spurious int */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still have issue with this spurious interrupt ? I wondered if it is caused by incorrect double buffer configuration previously.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still necessary since Tx interrupt can't be masked, if I disable the EP the host will not happy seeing NAK.

Another way to fix is in classes driver's xfer_cb, always call usbd_edpt_xfer for iso even if there is nothing to send.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change the class driver, this is specifci to this dcd only. I see host send IN token while have nothing to send and ISO does not have NAK --> triggered interrupt with zero byte data. I think this is all good now. Though I think we should make it more ISO explicit thing (making changes atm)

Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect, thank you. Great works as usual and I am glad it is more robust now

@hathach hathach merged commit 6144da9 into hathach:master Apr 11, 2024
49 checks passed
@HiFiPhile HiFiPhile deleted the fsdev branch April 11, 2024 18:38
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.

2 participants