This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

usbd_hid_composite not working on Mac?

Hi
my USB keyboard application works on Windows and Linux but not on a MacBook Air with
macOS Sierra 10.12.6. So I did step back and tried the combined HID example
nRF5_SDK_16.0.0_98a08e2/examples/peripheral/usbd_hid_composite/hex/usbd_hid_composite_pca10056.hex
with md5sum 6ffe5856a45b765a6ecf10ec0e348cdc
surprise: it does not work either

what I did:
flash the example hex file on PCA10056  version 2.0.1
connect the board to the MacBook Air

result:
mouse works perfectly as expected
keyboard is visible in the OS settings dialog for keyboards
no reaction at all on button3 (SHIFT) and button4 (letter G)
unexpected behaveour of LED3  - the picture below shows the LED timing on an oscilloscope:
stable for about 20ms then 4 toggles in row

led3 toggle timing

I look at the code and from this point I'm guessing:
the LED might get inverted in APP_USBD_HID_USER_EVT_OUT_REPORT_READY
is the OS asking for information?
or trying to discover the type of the keyboard by provoking a reaction (which is not delivered by the example code)?

I'm aware that the OS does not recognize the type of the keyboard and it asks me to press the button right of LEFT-SHIFT.
This button might be 'Z' on an standard US keyboard or the additional "NON-US-KEY" (keycode 100 decimal) on non-US keyboards.
The DevKit is not a real keyboard so I can't press this key and I skip this step and set the european keyboard type later manually.
But this does not help - the keyboard part of the DevKit example is still stuck.

I'm new to USB and HID. And I don't know how to low level debug USB/HID on a Mac.
So I tried comparing USB descriptors of the example with a Holtek keyboard which works fine.
But I couldn't find a notable difference.
Just one detail - it could be a hint or spurious neglectable glitch:
when I compared descriptors on Linux I saw an empty (all zeroes) IN report coming from the Holtek keyboard at the beginning.
I didn't expect this report and I don't know if I should pay attention to it.

question:
are you able to reproduce the problem connecting the composite HID example to a Mac?

despite searching forums a lot I have no clue yet what to look for.
suggestions are welcome - for example: should I dive into USB spec to find if an OS can ask questions to a keyboard and the example does not cover this dialog?

best regards
Peter

  • Hi Peter,

    I am seeing the same thing. For reference I attach hex files and USB analyzer traces: USB composite.zip. I do not have any progress though, unfortunately.

    Update: We are continuing to look into this and will update this thread when I have more information.

    Einar

  • Hi Einar

    thank you very much for the analyzer traces, they are VERY helpful. I have to be cautious with interpretation for I'm a beginner and it's not clear what is cause and what is consequence. In the traces SDK16 with Nordic vendor id I see the start of the famous 4-transfers-with-20ms-pause loop I saw on my oscilloscope.

    Interesting detail: the very first group (at 7.673 141) appears spontaneously 12.3 ms after the last "Class request" and is only 3 IN reports long (not 4).

    Comparing this to Apple vendor id: the time between the last "Class request" and the last "Get Descriptor" is 9.5ms. And the last "Class request" appears only for Apple vendor id - it might be asking for an Apple specific feature - and gets answered with STALLED (maybe because it is not implemented).

    This might give me 2 clues:
    a) STALLED might execute code which resets something in the driver
    b) there might be some timeout in the range of 10-12ms which expires before the last "Get Descriptor" call appears

    Before reading those traces I expected to have more interaction when macOS tries to identify an unknown keyboard. Now I see it's the other way around: there is one more request when macOS tries to get some additional information it expects from an Apple keyboard but not from a third party product. This makes sense.

    enough for today - I will try to understand more the next days

    best regards
    Peter

  • Hi Peter,

    Sounds good. Please let me know if you make any progress. I will update this thread when we have some results.

    Einar

  • Hi Einar

    further analyzing the dumps: I see SDK14 sets wMaxPacketSize == 8 in the IN Endpoint Descriptor for both mouse and keyboard while SDK16 sets wMaxPacketSize == 64

    wild speculation: the internal buffer is only 8 bytes long, but gets cleared 64 bytes deep (array index out of bounds). this would overwrite memory. The additional request for some Apple specific feature (vendor ID Apple) leads to STALLED because the requested feature is not implement and restores some of the overwritten values.
    wild speculations, but for the moment I it's the most promising trail I see. I have to check that in the code.

    Not yet clear: does the host activate boot protocol or not ?

    And I see the precompiled hex version in SDK14 does not set SUBLANGUAGE for the strings, it's just ENGLISH. I don't know if this is legal - it HAS an impact on host behaviour, but I do not think this should lead to trouble. Also I see variations in the order the interfaces are set up: I assume that the host spawns a thread per interface

    best regards
    Peter

  • Hi Peter,

    We were also looking at the packet lengths. However, changing 

                APP_USBD_CLASS_DESCRIPTOR_WRITE(LSB_16(NRF_DRV_USBD_EPSIZE)); // wMaxPacketSize LSB
                APP_USBD_CLASS_DESCRIPTOR_WRITE(MSB_16(NRF_DRV_USBD_EPSIZE)); // wMaxPacketSize MSB

    to

                APP_USBD_CLASS_DESCRIPTOR_WRITE(8); // wMaxPacketSize LSB
                APP_USBD_CLASS_DESCRIPTOR_WRITE(0); // wMaxPacketSize MSB

    in app_usbd_hid_mouse.c and app_usbd_hid_kbd.c died not have an effect, at lest. (I might have been long shot, though).

    The SDK team has allocated time to analyze this issue in more detail, and I will let you know when they make progress. Please continue to let me know if you have any new findings.

    Einar

Related