Hi Daniel ,
Thank you for getting back to me .
I tried the following
1. use the hid-mouse example as it is with usbd_next_proj.conf
2. use with loopback class
1. proj.conf
CONFIG_LOG=y
CONFIG_USB_DEVICE_STACK_NEXT=y
CONFIG_USBD_LOOPBACK_CLASS=y
2. main.c
#include "sample_usbd.h"
/*located on zephyrproject/zephyr/samples/subsys/usb/common*/
#include <zephyr/kernel.h>
#include <zephyr/usb/usbd.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(app, LOG_LEVEL_DBG);
static void msg_cb(struct usbd_context *const usbd_ctx,
const struct usbd_msg *const msg) {
LOG_INF("USBD message: %s", usbd_msg_type_string(msg->type));
if (usbd_can_detect_vbus(usbd_ctx)) {
if (msg->type == USBD_MSG_VBUS_READY) {
if (usbd_enable(usbd_ctx)) {
LOG_ERR("Failed to enable device support");
}
}
if (msg->type == USBD_MSG_VBUS_REMOVED) {
if (usbd_disable(usbd_ctx)) {
LOG_ERR("Failed to disable device support");
}
}
}
}
int main(void) {
struct usbd_context *sample_usbd;
int ret;
sample_usbd = sample_usbd_init_device(msg_cb);
if (sample_usbd == NULL) {
k_msleep(100);
return 0;
}
if (!usbd_can_detect_vbus(sample_usbd)) {
ret = usbd_enable(sample_usbd);
{
if (ret) {
LOG_ERR("Failed to enable usb support !");
return ret;
}
}
}
return 0;
}
in both cases I got <err> usbd_core: Failed to init device driver . to be little more specific -12(-ENOMEM)
after tracing the issue back I pin point the error to udc_mcux_init(...) function located in drivers/usb/udc/udc_mcux_ehci.c
to narrow it further
/* Init MCUX USB device driver. */
status = mcux_if->deviceInit(priv->controller_id,
&priv->mcux_device, &(priv->mcux_device.controllerHandle));
if (status != kStatus_USB_Success) {
return -ENOMEM;
}