AnsweredAssumed Answered

USB COMMAND_DONE semaphore not working

Question asked by arnogir on Oct 28, 2016
Latest reply on Nov 7, 2016 by arnogir



I'm facing a problem on USB stack.

Fisrt, my configuration:

K70, MQX 4.1

I try to update usb files from MQX4.2 (not usbv2, just Usb) but problem still present.


So when USB is plugged, like done in HVAC demo, I do following:


usb_fs_ptr->DEV_FD_PTR = fopen(block_device_name, 0);

Wtih the same key, sometime return will be null, sometime return will be OK.


I debug on under layer:

_io_fopen -> _io_usb_mfs_open -> _io_usb_mfs_open_internal.

In this function, we wait a semaphore (_lwsem_wait_ticks(&info_ptr-> COMMAND_DONE, ...)


This semaphore is post in _io_usb_ctrl_callback.


When all work, in  io_usb_mfs_open_interna we wait COMMAND_DONE, then the _io_usb_ctrl_callback is called (from _task_build_internal/_usb_khci_task/_usb_khci_process_tr_complete_io/_usb_ctrl_callback.


But when not working, the function _io_usb_ctrl_callback is called before the fopen call the lwsem wait.

So the post not trig the wait semaphore...


To resume, if the _lwsem_post arrive before the _lwsem_wait_ticks, we will blocked!


This semaphore behavior is Ok? Could you help me to find frome where problem comes?


Thank you