Skip to main content
Visitor II
December 20, 2019
Solved

How to disable USB Receive (OUT) (response with NACK) for a while ?

  • December 20, 2019
  • 1 reply
  • 1077 views

I'm implementing USB CDC for my project.

In the USB callback function (CDC_Receive_HS), I copy the contents to a user's data array and exit the function. I process the received data in the main function. (not in USB interrupt routine)

What I want to do is not to receive any data while while the program is processing the data.

After data processing is done, re-enable the receiving.

(I think) the most proper way is to make USB engine response to OUT with NACK.  

Is there a way to enable/disable "Response to OUT with NACK" ?

Is there more appropriate way ?

    This topic has been closed for replies.
    Best answer by Bob S

    In CDC_Receive_HS(), don't re-enable the receive process (for USB FS devices, that is USBD_CDC_SetRxBuffer() and USBD_CDC_ReceivePacket(), I don't know what functions HS interfaces use). Then in your main loop, when you are done processing the data call those two functions (or their HS equivalent) to tell the UBS interface to stop NAK-ing and accept more data.

    1 reply

    Bob SAnswer
    Super User
    December 20, 2019

    In CDC_Receive_HS(), don't re-enable the receive process (for USB FS devices, that is USBD_CDC_SetRxBuffer() and USBD_CDC_ReceivePacket(), I don't know what functions HS interfaces use). Then in your main loop, when you are done processing the data call those two functions (or their HS equivalent) to tell the UBS interface to stop NAK-ing and accept more data.

    taz1000Author
    Visitor II
    December 23, 2019

    Great Thanks.

    As your comment, "moving USBD_CDC_ReceivePacket( ) into main routine" does what I want.

    if USBD_CDC_ReceivePacket( ) is not called in ISR (interrupt service routine), USBD_CDC OUT (from PC to MCU) is not activated (MCU responses with NACK).

    After I finish all necessary processing and call USBD_CDC_ReceivePacket ( ), USB_CD_ OUT is activated back.