This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Question - USB EPDATA and EP0DATADONE Events

Hi,

I'm working on the Mbed-OS USB HAL implementation for the nRF52840. I'm having a bit of difficulty getting the expectations of the USB stack to match up with the event information the hardware gives me.

Specifically, I'm wondering when exactly the events EPDATA and EP0DATADONE occur. The datasheet gives some figures and descriptions but leaves some ambiguity.

For example, the status stage of a control transfer is handled by the hardware by triggering the EP0STATUS task. The Mbed-OS stack needs to know when the status stage transfer has been ACK'd. From the diagram in the datasheet for control transfers, it doesn't look like an EP0DATADONE event will be generated for a DATA token ACK during the status stage. However, the description in the USBD registers section makes it sound like it will:

nRF52840 Product Specification V1.0, 6.35.13 Registers, EVENTS_EP0DATADONE description:

An acknowledged data transfer has taken place on the control endpoint

Under what circumstances will EPDATA and EP0DATADONE events be generated? Is an EP0DATADONE event generated when the DATA token of the hardware-handled status stage ACK'd?

Similarly, is an EP0DATADONE event generated during the setup stage of a control transfer after the DATA token is ACK'd?

  • Hi,

     

     

    Under what circumstances will EPDATA and EP0DATADONE events be generated?

     EVENTS_EPDATA is generated for each successful transaction for EPs 1 to 7, while EP0DATADONE is signalling from the USBD that you have ACKed a payload on EP0.

    Since you know the total size of your descriptor, the firmware should start the task EP0STATUS when the last EVENTS_EP0DATADONE has been issued to allow the STATUS stage to start.

    Is an EP0DATADONE event generated when the DATA token of the hardware-handled status stage ACK'd?

    It is generated when the host ACKs the EP0 DATA, yes.

    Similarly, is an EP0DATADONE event generated during the setup stage of a control transfer after the DATA token is ACK'd?

     Yes. It's generated after you either send an ACK (control read) or receive an ACK (control write) on EP0. The figures for control read/write in the PS might be easier to read than my explanation:

    http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52840.ps/usbd.html?cp=2_0_0_5_34_8#concept_usb_ctrl_ep

     

    Kind regards,

    Håkon

  • Hi Håkon, thanks for your response

     EVENTS_EPDATA is generated for each successful transaction for EPs 1 to 7, while EP0DATADONE is signalling from the USBD that you have ACKed a payload on EP0.

    Alright, that is clear enough for EVENTS_EPDATA.

    Since you know the total size of your descriptor, the firmware should start the task EP0STATUS when the last EVENTS_EP0DATADONE has been issued to allow the STATUS stage to start.

    As I am developing a HAL driver for Mbed-OS it is not the case that I know the total size of the descriptor. The upper layers of the Mbed stack handle breaking the transfers up into chunks of ep_max_packet_size. I have been able to detect when the last packet is being sent in the data stage because the last transfer is always less than ep_max_packet_size (even if the total payload is a multiple of that, USB requires the device to send a zero-length-packet to notify the host it is done sending). So this is not really a problem.

    Is an EP0DATADONE event generated when the DATA token of the hardware-handled status stage ACK'd?

    It is generated when the host ACKs the EP0 DATA, yes.

    Similarly, is an EP0DATADONE event generated during the setup stage of a control transfer after the DATA token is ACK'd?

     Yes. It's generated after you either send an ACK (control read) or receive an ACK (control write) on EP0. The figures for control read/write in the PS might be easier to read than my explanation:

    http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52840.ps/usbd.html?cp=2_0_0_5_34_8#concept_usb_ctrl_ep

    So I have read through the datasheet a number of times. I understand that during the data stage of control transfers the EP0DATADONE event is generated after an ACK to/from the host. However, my question concerns cases that aren't described in the diagrams. I have marked up the datasheet diagram to better explain where I'm confused:

  • Hi,

    George Beckstien said:

    So I have read through the datasheet a number of times. I understand that during the data stage of control transfers the EP0DATADONE event is generated after an ACK to/from the host. However, my question concerns cases that aren't described in the diagrams. I have marked up the datasheet diagram to better explain where I'm confused:

    The stages here are incomplete wrt. signalling in the Setup stage and Status stage, as it focuses on the data stage only.

    The EVENTS_EP0DATADONE shall fire for any ACK that is either delivered or received on the control endpoint, regardless of what state the enumeration is in, as stated in the documentation:

    The EPDATA event indicates that a successful (acknowledged) data transaction has occurred on the data endpoint(s) flagged in register EPDATASTATUS. A successful (acknowledged) data transaction on endpoint 0 is signalled by the EP0DATADONE event.

     

    Kind regards,

    Håkon

Related