Support about USB HID Receive Data from PC in nRF52840

Now, I use USB for transfer and receive data with PC. But when I use the example zephyr/samples/subsys/usb/hid : https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/subsys/usb/hid. It only have transfer data from chip to PC and not to receive. I try to many ways but it don't work. I don't read anything. 

Now, I use NCS v 2.3.0 for code and VS Code for my project.

Please so help me. 

Parents
  •  Thank you for your reply. I am so happy for that. Sorry but my project requires USB HID not USB CDC ACM. I use hid_int_ep_write is very good but  hid_int_ep_read is not working. When I send data from PC, my NRF52 chip don't receive anything. 

    This is my prj.conf:

    CONFIG_USB_DEVICE_STACK=y
    CONFIG_USB_DEVICE_HID=y
    CONFIG_USB_DEVICE_PRODUCT="Zephyr HID sample"
    CONFIG_USB_DEVICE_PID=0x0006
    CONFIG_USB_HID_BOOT_PROTOCOL=y
    CONFIG_USB_DEVICE_VID=0x2FD4
    CONFIG_USB_DEVICE_MANUFACTURER="Emotiv"
    CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n

    CONFIG_LOG=y
    CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y

    CONFIG_USB_DEVICE_SOF=n
    # CONFIG_USB_HID_REPORTS=2
    CONFIG_ENABLE_HID_INT_OUT_EP=y
    CONFIG_USB_HID_POLL_INTERVAL_MS=1
    CONFIG_HID_INTERRUPT_EP_MPS=64
    And this is my code:
    static const uint8_t hid_report_desc[] = {
        HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP),
        HID_USAGE(HID_USAGE_GEN_DESKTOP_UNDEFINED),
        HID_COLLECTION(HID_COLLECTION_APPLICATION),
        HID_LOGICAL_MIN8(0x00),
        HID_LOGICAL_MAX16(0xFF, 0x00),
        HID_REPORT_ID(REPORT_ID_1),
        HID_REPORT_SIZE(8),
        HID_REPORT_COUNT(1),
        HID_USAGE(HID_USAGE_GEN_DESKTOP_UNDEFINED),
        HID_INPUT(0x02),
        HID_OUTPUT(0x01),
        HID_END_COLLECTION,
    };
    static void send_report(struct k_work *work)
    {
        int ret, wrote;

        if (!atomic_test_and_set_bit(hid_ep_in_busy, HID_EP_BUSY_FLAG)) {
            ret = hid_int_ep_write(hdev, (uint8_t *)&report_1,
                           sizeof(report_1), &wrote);
            if (ret != 0) {
                /*
                 * Do nothing and wait until host has reset the device
                 * and hid_ep_in_busy is cleared.
                 */
                LOG_ERR("Failed to submit report");
            } else {
                LOG_DBG("Report submitted");
            }
        } else {
            LOG_DBG("HID IN endpoint busy");
        }
    }

    static void int_in_ready_cb(const struct device *dev)
    {
        ARG_UNUSED(dev);
        if (!atomic_test_and_clear_bit(hid_ep_in_busy, HID_EP_BUSY_FLAG)) {
            LOG_WRN("IN endpoint callback without preceding buffer write");
        }
    }

    static void int_out_ready_cb(const struct device *dev)
    {
        ARG_UNUSED(dev);
        if (!atomic_test_and_clear_bit(hid_ep_in_busy, HID_EP_BUSY_FLAG)) {
            LOG_WRN("IN endpoint callback without preceding buffer write");
        }
    }

    static void on_idle_cb(const struct device *dev, uint16_t report_id)
    {
        LOG_DBG("On idle callback");
        k_work_submit(&report_send);
    }

    static void report_event_handler(struct k_timer *dummy)
    {
        /* Increment reported data */
        report_1.value++;
        k_work_submit(&report_send);
    }

    static void protocol_cb(const struct device *dev, uint8_t protocol)
    {
        LOG_INF("New protocol: %s", protocol == HID_PROTOCOL_BOOT ?
            "boot" : "report");
    }

    static const struct hid_ops ops = {
        .int_in_ready = int_in_ready_cb,
        .on_idle = on_idle_cb,
        .protocol_change = protocol_cb,
        .int_out_ready = int_out_ready_cb,
    };
  • Hi!

    Looking at your snippet, I don't see where you are calling hid_int_ep_read()

    Maybe try adding that in the int_out_ready_cb() function

  • Oh thank you. I work fine right now. If I have some trouble in the future, I will contact you later and thank you for support.

Reply Children
No Data
Related