Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52840 usbd_hid_generic endpoint out error

Hi,

    I modiy the usbd_hid_generic example to tow endpoint by sdk15.0.When i use the USB testtool send some datas to usb deivce,the datas cannot be read properly by NRF_USBD_EP_OK status.

code:

static ret_code_t endpoint_out_event_handler(app_usbd_class_inst_t const * p_inst,
app_usbd_hid_inst_t const * p_hinst,
app_usbd_hid_ctx_t * p_hid_ctx,
app_usbd_complex_evt_t const * p_event)
{
if (p_hinst->p_hid_methods->ep_transfer_out == NULL)
{
return NRF_ERROR_NOT_SUPPORTED;
}

NRF_LOG_INFO("ep out status: %d",p_event->drv_evt.data.eptransfer.status);
if (p_event->drv_evt.data.eptransfer.status == NRF_USBD_EP_OK)
{
/* Notify user about last successful transfer. */
user_event_handler(p_inst, p_hinst, APP_USBD_HID_USER_EVT_OUT_REPORT_READY);
}

return p_hinst->p_hid_methods->ep_transfer_out(p_inst);
}

debug log:

my usb hid config codes:

/**
* @brief Enable USB power detection
*/
#ifndef USBD_POWER_DETECTION
#define USBD_POWER_DETECTION true
#endif

/**
* @brief HID generic class interface number.
* */
#define HID_GENERIC_INTERFACE 0

/**
* @brief HID generic class endpoint number.
* */
#define HID_GENERIC_EPIN NRF_DRV_USBD_EPIN1
#define HID_GENERIC_EPOUT NRF_DRV_USBD_EPOUT1


/* GPIO used as LED & buttons in this example */
#define LED_USB_START (BSP_BOARD_LED_0)
#define LED_HID_REP_IN (BSP_BOARD_LED_2)

/**
* @brief Number of reports defined in report descriptor.
*/
#define REPORT_IN_QUEUE_SIZE 1

/**
* @brief Size of maximum output report. HID generic class will reserve
* this buffer size + 1 memory space. */
#define REPORT_OUT_MAXSIZE 64

/**
* @brief HID generic class endpoints count.
* */
#define HID_GENERIC_EP_COUNT 1

/**
* @brief List of HID generic class endpoints.
* */
#define ENDPOINT_LIST() \
( \
HID_GENERIC_EPIN,HID_GENERIC_EPOUT \
)

/**
* @brief User event handler.
* */
static void hid_user_ev_handler(app_usbd_class_inst_t const * p_inst,
app_usbd_hid_user_event_t event);

/**
* @brief Reuse HID mouse report descriptor for HID generic class
*/
APP_USBD_HID_GENERIC_SUBCLASS_REPORT_DESC(consumer_desc,USBD_GENERIC_REPORT_DESCRIPTOR(64));

static const app_usbd_hid_subclass_desc_t * reps[] = {&consumer_desc};

/*lint -save -e26 -e64 -e123 -e505 -e651*/

/**
* @brief Global HID generic instance
*/
APP_USBD_HID_GENERIC_GLOBAL_DEF(m_app_hid_generic,
HID_GENERIC_INTERFACE,
hid_user_ev_handler,
ENDPOINT_LIST(),
reps,
REPORT_IN_QUEUE_SIZE,
REPORT_OUT_MAXSIZE,
APP_USBD_HID_SUBCLASS_NONE,
APP_USBD_HID_PROTO_GENERIC);

usb report:

#define USBD_GENERIC_REPORT_DESCRIPTOR(rep_count) { \
0x05, 0x0C, /* usage page (generic desktop). Global item, applies to all subsequent items */\
0x09, 0x01, /* usage (mouse). Local item */\
0xA1, 0x01, /* collection (application) */\
0x15, 0x00, /* logical minimum (0) */\
0x25, 0xFF, /* logical maximum (255) */\
0x19, 0x01, /* usage minimum (1) */\
0x29, 0x08, /* usage maximum (8) */\
0x75, 0x08, /* report size (8bit) */\
0x95, rep_count, /* report count (64byte) */\
0x81, 0x02, /* input (data, var, abs) */\
0x15, 0x00, /* logical minimum (0) */\
0x25, 0xFF, /* logical maximum (255) */\
0x19, 0x01, /* usage minimum (1) */\
0x29, 0x08, /* usage maximum (8) */\
0x75, 0x08, /* report size (8bit) */\
0x95, rep_count, /* report count (64byte) */\
0x91, 0x02, /* output (data, var, abs) */\
0xC0, /* End Collection */\
}

Related