cancel
Showing results for 
Search instead for 
Did you mean: 

How to USB in combination with a barcode scanner (as a host only peripheral for reading)?

wh
Associate III

I have a USB device in HOST only mode using the CDC middleware to receive data from a barcode scanner set in RS232 mode. This is working accept for the enormous amount of (spurious) host channels interrupt USB_OTG_GINTSTS_HCINT. When I monitor the number of received interrupt they add up to more 65000 a second. This will have a real bad influence on the rest of the system behavior. I there anyone who had the same experience? Is there a good example somewhere that show the right way to do it?

(When I disable the USB_OTG_GINTSTS_HCINT interrupt the performance improves but then I don't receive any data anymore)

Thanks in advance

Wim

2 REPLIES 2

Which STM32?

This is most probably the infamous "NAK flood" - when a bulk endpoint in the device does not have data to send or can't receive more data, it NAKs the host's request; but the handler in Cube upon receiving the NAK immediately retries again. This has been discussed here already.

There's no hardware support for scheduling this in some less aggressive manner; in software, the solution is to avoid retrying communication at the given endpoint for some time. I know this may be not simple and even less so, if you use some ready-made library such as Cube. In the thread linked above, there is a solution offered in the form of disabling NAK interrupts when they occur the first time, and then reenabling them at SOF; I personally don't use it but IMO this may work satisfactorily probably for most practical applications.

JW

wh
Associate III

Thank you for the answer!!! Looks like this is the problem. By the way I'm using the STM32L476 device. I'll dive into the discussion link to see how I can solve the problem. Perhaps someone out there already has some example code available. It would really help me out.

Thanks again,

Wim