Michael Hermann

USB Stack do's and dont's

Discussion created by Michael Hermann on Nov 17, 2018
Latest reply on Nov 23, 2018 by Michael Hermann

Hello,

 

I am working with the USB Stack 2.0.1 (newest release 2018/10, I hope) and the K2x family.

Years ago I wrote my own USB stack (for an 8 bit uc) and later used the ROM Stack of the LPC43xx and LPC1x.

 

I'd like to discuss and collect observations others have made with this stack. I'm rather new to this stack, so maybe I'm doing things not the way they are intended.

OTOH I can share some "pitfalls" that came unexpected at least for me and which may irk others, too.

 

Example:

When cancelling a pending transaction on an EP with USB_DeviceCancel() the stack immediately calls back the associated class callback as if the pending request had been serviced by the host.

You will have to check the length parameter of the message for the value 0xFFFFFFFF. It is set by the stack for an uninitialized buffer (USB_UNINITIALIZED_VAL_32). The buffer pointer may still be valid, i.e. not NULL.

If you don't check or take other precautions you may end up with reading some 4 GB of data . Or a hard fault at that, whichever comes first.

I detected this behaviour when cleaning up  CDC/ACM connections closed by the host.

 

My expectation was a "silent" cancellation (just a return code) and the Stack Manual doesn't mention the side effect.

 

Regards,

 

Mike

Outcomes