I implemented custom USB class with two interrupt and one bulk endpoint. I used usb_device_cdc_acm.c from SDK 2.1 as a template. USB device is full speed on MK22.
Sometimes the bulk endpoint freezes in busy state. On PC side reading from the bulk endpoint timeouts then (libusb_bulk_transfer used on PC side) even though on MCU side I can see the endpoint is in busy state transferring data.
Structure s_UsbDeviceKhciState has tranferLength = 0x28a, transferDone = 0 and state = 0x6040 forever. I have to reset MCU to reenable data transfers on my bulk endpoint.
Can you please help me diagnose the problem?
EDIT: It seems that the issue is caused by switching from HSRUN to RUN mode with USB module enabled. My CPU have to run with 120 MHz, but sometimes I need to write internal flash memory, which is not possible from HSRUN mode so I have to switch to RUN. When I don't switch from HSRUN to RUN and I disable writing to flash then this issue with frozen bulk endpoint doesn't happen, at least it seems to.