{"action":"created","issue":{"url":"https://api.github.com/repos/abcminiuser/lufa/issues/64","labels_url":"https://api.github.com/repos/abcminiuser/lufa/issues/64/labels{/name}","comments_url":"https://api.github.com/repos/abcminiuser/lufa/issues/64/comments","events_url":"https://api.github.com/repos/abcminiuser/lufa/issues/64/events","html_url":"https://github.com/abcminiuser/lufa/pull/64","id":117225347,"number":64,"title":"Fixed race condition when multiple SETUP messages queued.","user":{"login":"agprimatic","id":4685054,"avatar_url":"https://avatars.githubusercontent.com/u/4685054?v=3","gravatar_id":"","url":"https://api.github.com/users/agprimatic","html_url":"https://github.com/agprimatic","followers_url":"https://api.github.com/users/agprimatic/followers","following_url":"https://api.github.com/users/agprimatic/following{/other_user}","gists_url":"https://api.github.com/users/agprimatic/gists{/gist_id}","starred_url":"https://api.github.com/users/agprimatic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agprimatic/subscriptions","organizations_url":"https://api.github.com/users/agprimatic/orgs","repos_url":"https://api.github.com/users/agprimatic/repos","events_url":"https://api.github.com/users/agprimatic/events{/privacy}","received_events_url":"https://api.github.com/users/agprimatic/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-16T21:46:25Z","updated_at":"2015-11-17T17:02:49Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/abcminiuser/lufa/pulls/64","html_url":"https://github.com/abcminiuser/lufa/pull/64","diff_url":"https://github.com/abcminiuser/lufa/pull/64.diff","patch_url":"https://github.com/abcminiuser/lufa/pull/64.patch"},"body":"I was having a problem with STALL messages in my HID device, and I traced it down to this:\r\n\r\nWhen USB_Device_ProcessControlRequest() is called, it first does the HID-specific EVENT_USB_Device_ControlRequest() processing.  If that doesn't handle the request, then since Endpoint_isSETUPReceived() is still true, then to do the generic processing.  If _that_ doesn't handle the request, then it calls Endpoint_ClearSETUP() and stalls the transaction.\r\n\r\nIn my case, it looks like a new SETUP message is arriving between the Endpoint_ClearSETUP() in EVENT_USB_Device_ControlRequest() and the check for Endpoint_isSETUPReceived() right after EVENT_USB_Device_ControlRequest() returns.\r\n\r\nIn this case, the switch statement in USB_Device_ProcessControlRequest() tries to process the HID-specific message with the generic processing.  It doesn't handle the HID-specific message, so it falls through to the STALL code.\r\n\r\nMy suggestion is to only check for Endpoint_isSETUPReceived() once at the top of USB_Device_ProcessControlRequest().  If it is set, then try first the specific handler, then if that doesn't satisfy the request, then try the generic handler.  If _that_ doesn't handle the request, then generate the STALL.  I did this by using a request_handled variable, and modifying EVENT_USB_Device_ControlRequest() to return a value that says whether it handled the request or not.\r\n\r\nThis fixed my problem with the race condition.  I think my EVENT_USB_Device_ControlRequest() is taking longer than expected, so another message is queued up behind it.  By the time I retire the request, another request has arrived."},"comment":{"url":"https://api.github.com/repos/abcminiuser/lufa/issues/comments/157434119","html_url":"https://github.com/abcminiuser/lufa/pull/64#issuecomment-157434119","issue_url":"https://api.github.com/repos/abcminiuser/lufa/issues/64","id":157434119,"user":{"login":"NicoHood","id":6888294,"avatar_url":"https://avatars.githubusercontent.com/u/6888294?v=3","gravatar_id":"","url":"https://api.github.com/users/NicoHood","html_url":"https://github.com/NicoHood","followers_url":"https://api.github.com/users/NicoHood/followers","following_url":"https://api.github.com/users/NicoHood/following{/other_user}","gists_url":"https://api.github.com/users/NicoHood/gists{/gist_id}","starred_url":"https://api.github.com/users/NicoHood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NicoHood/subscriptions","organizations_url":"https://api.github.com/users/NicoHood/orgs","repos_url":"https://api.github.com/users/NicoHood/repos","events_url":"https://api.github.com/users/NicoHood/events{/privacy}","received_events_url":"https://api.github.com/users/NicoHood/received_events","type":"User","site_admin":false},"created_at":"2015-11-17T17:02:49Z","updated_at":"2015-11-17T17:02:49Z","body":"I think this can me merged with a single commit, not those thousands. Also a bool would suit better and not consume so much memory. I have **not** looked at the functionality at all, just those facts I saw."}}