cancel
Showing results for 
Search instead for 
Did you mean: 

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

taz1000
Associate III

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
Bob S
Principal

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.

View solution in original post

2 REPLIES 2
Bob S
Principal

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.

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.