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

[nRF52840][usbd_hid_generic] How to read the data in OUT ENDPOINT?

Hello Nordic experts,

I am using nRF52840 and SDK 15.3.0. I have added an OUT ENDPOINT to the usbd_hid_generic example by following the suggestions in https://devzone.nordicsemi.com/f/nordic-q-a/36145/nrf52840-usbd_hid_generic-endpoint-out-error. I can see the OUT ENDPOINT in USB description so it was successfully added. Also, I have a tool to send data to that OUT ENDPOINT. Now, I would like to ask how do I program to read that data stored in OUT ENDPOINT using Keil? (I will use that data to control the LEDs in nRF52840)

#define HID_GENERIC_EPOUT NRF_DRV_USBD_EPOUT1

// .....

#define ENDPOINT_LIST()                                      \
(                                                            \
        HID_GENERIC_EPIN,                                    \
		HID_GENERIC_EPOUT                                    \
)

// .....

Thank you for your kind support in advance.

Kind regards,

Louis

  • Haojz said:
    After data is sent to OUT EP(0x01), APP_USBD_HID_USER_EVT_IN_REPORT_DONE function is only entered once when we press the button(meanwhile the mouse function is not activated), keeping LED lighting up and not turning off. If I go deeper into the sub-function codes, I cannot understand what is going on.

     Have you checked that the data you receive is correct, and as well the "out_report_size" is 4?

    The LED for the IN report is inverted on the callback (ie: when the host has ACKed), so it might be a problem in the USB communication after the OUT packet is received. Hard to say, as I do not have all the debug information here (usb sniffer trace, checks on validity of data, etc). 

     

    Kind regards,

    Håkon

  • Hello Håkon,

    Have you checked that the data you receive is correct, and as well the "out_report_size" is 4?

    I have checked in hid_generic_mouse_process_state function that the in_report is correctly set and this function works fine. The "out_report_size" is 4 as default. 

    so it might be a problem in the USB communication after the OUT packet is received

    Yes, I think so, but I am not able to find exactly where. The good news is I can still get the data from IN EP from linux side, and it is only the mouse and LED that do not work well.

    Therefore, I change my goal now: I want to remove all things regarding the mouse functions, only leaving the communication tunnels(IN EP & CONTROL EP/OUT EP) to transmit some data and execute some control commands from linux side. I have tried removing mouse-regarding functions manually but the code stopped to work afterwards(it is quite complicated to modify), so do you have clear code only for HID USB communication via endpoints or do you know any easier way to realize this goal? 

    Thank you for your kind support again and I look forward to hearing from you soon.

    Kind regards,

    Louis

     

  • Hi Louis,

     

    Sorry for the late reply.

    Haojz said:
    Therefore, I change my goal now: I want to remove all things regarding the mouse functions, only leaving the communication tunnels(IN EP & CONTROL EP/OUT EP) to transmit some data and execute some control commands from linux side. I have tried removing mouse-regarding functions manually but the code stopped to work afterwards(it is quite complicated to modify), so do you have clear code only for HID USB communication via endpoints or do you know any easier way to realize this goal? 

    Do you need a generic data interface, ie: non keyboard/mouse, to receive and send data (HID not really a requirement)? If yes, then the USB CDC example can be beneficial to look at. Using that you should be able to send and receive data using a COM port interface.

    If you require to use HID, then a generic HID descriptor can be used, but it will require some changes to the descriptor. Here's a generic HID descriptor taken from one of the older nRFready Desktop dongle projects (nRF24LU1+ based):

    0x06, 0x0a, 0xff,              // USAGE_PAGE (Generic Desktop)
    0x09, 0x01,                    // USAGE (Vendor Usage 1)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x09, 0x02,                    //   USAGE (Vendor Usage 2)
    0xa1, 0x00,                    //   COLLECTION (Physical)
    0x06, 0x00, 0xff,              //     USAGE_PAGE (Generic Desktop)
    0x09, 0x03,                    //     USAGE (Vendor Usage 1)
    0x09, 0x04,                    //     USAGE (Vendor Usage 1)
    0x15, 0x80,                    //     LOGICAL_MINIMUM (-128)
    0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
    0x35, 0x00,                    //     PHYSICAL_MINIMUM (0)
    0x46, 0xff, 0x00,              //     PHYSICAL_MAXIMUM (255)
    0x75, 0x08,                    //     REPORT_SIZE (8)
    0x95, 0x20,                    //     REPORT_COUNT (32)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    0x09, 0x05,                    //     USAGE (Vendor Usage 1)
    0x09, 0x06,                    //     USAGE (Vendor Usage 1)
    0x15, 0x80,                    //     LOGICAL_MINIMUM (-128)
    0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
    0x35, 0x00,                    //     PHYSICAL_MINIMUM (0)
    0x46, 0xff, 0x00,              //     PHYSICAL_MAXIMUM (255)
    0x75, 0x08,                    //     REPORT_SIZE (8)
    0x95, 0x20,                    //     REPORT_COUNT (32)
    0x91, 0x02,                    //     OUTPUT (Data,Var,Abs)
    0xc0,                          //   END_COLLECTION
    0xc0                           // END_COLLECTION

      

    Kind regards,

    Håkon

  • Dear Håkon,

    Thank you for your reply. I think you are right and I am trying CDC example, but how do I use CDC example in Linux? The infocenter only has tutorial for Windows. (And what commands do I use to send and receive data? In order to achieve the goal above, do I need to change anything in the SDK?)

    Kind regards,

    Louis

  • Hi Louis,

     

    You can use a generic UART/serial terminal, like screen, putty, minicom, or any other COM-port capable program to interface with the device.

     

    Kind regards,

    Håkon

Related