Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions bsp/at32/libraries/rt_drivers/drv_usbfsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "drv_config.h"

//#define DRV_DEBUG
#define LOG_TAG "drv.usb"
#define LOG_TAG "drv.usb.fsh"
#include <drv_log.h>

static struct rt_completion urb_completion;
Expand Down Expand Up @@ -76,7 +76,7 @@ void usbh_connect_callback(usbh_core_type *uhost)
if (!connect_status)
{
connect_status = RT_TRUE;
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb connected\n"));
LOG_D("usb connected");
rt_usbh_root_hub_connect_handler(hcd, 1, RT_FALSE);
}
}
Expand All @@ -87,7 +87,7 @@ void usbh_disconnect_callback(usbh_core_type *uhost)
if (connect_status)
{
connect_status = RT_FALSE;
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb disconnnect\n"));
LOG_D("usb disconnnect");
rt_usbh_root_hub_disconnect_handler(hcd, 1);
}
}
Expand All @@ -99,7 +99,7 @@ void usbd_notify_urbchange_callback(usbh_core_type *uhost, uint8_t chnum, urb_st

static rt_err_t drv_reset_port(rt_uint8_t port)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("reset port\n"));
LOG_D("reset port");
usbh_reset_port(&p_usbfs_instance->p_otg_core->host);
return RT_EOK;
}
Expand Down Expand Up @@ -224,7 +224,7 @@ static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbyte

if(usbh_get_status((&p_usbfs_instance->p_otg_core->host), pipe->pipe_index) == HCH_NAK)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("nak\n"));
LOG_D("nak");
if (pipe->ep.bmAttributes == USB_EP_ATTR_INT)
{
rt_thread_delay((pipe->ep.bInterval * RT_TICK_PER_SECOND / 1000) > 0 ? (pipe->ep.bInterval * RT_TICK_PER_SECOND / 1000) : 1);
Expand All @@ -242,7 +242,7 @@ static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbyte
}
else if (usbh_get_status(&p_usbfs_instance->p_otg_core->host, pipe->pipe_index) == HCH_STALL)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("stall\n"));
LOG_D("stall");
pipe->status = UPIPE_STATUS_STALL;
if (pipe->callback != RT_NULL)
{
Expand All @@ -252,7 +252,7 @@ static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbyte
}
else if (usbh_get_status(&p_usbfs_instance->p_otg_core->host, pipe->pipe_index) == URB_ERROR)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("error\n"));
LOG_D("error");
pipe->status = UPIPE_STATUS_ERROR;
if (pipe->callback != RT_NULL)
{
Expand All @@ -262,7 +262,7 @@ static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbyte
}
else if(URB_DONE == usbh_get_urb_status(&p_usbfs_instance->p_otg_core->host, pipe->pipe_index))
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("ok\n"));
LOG_D("ok");
pipe->status = UPIPE_STATUS_OK;
if (pipe->callback != RT_NULL)
{
Expand Down
47 changes: 25 additions & 22 deletions bsp/imxrt/libraries/drivers/drv_usbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include <usb/host/usb_host_ehci.h>
#include <rtdevice.h>

//#define DRV_DEBUG
#define LOG_TAG "drv.usb.host"
#include <drv_log.h>

/* USB PHY configuration */
#ifndef BOARD_USB_PHY_D_CAL
Expand Down Expand Up @@ -171,12 +174,12 @@ static int _ehci0_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nb
usb_host_transfer_t *transfer;
if (imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].pipe_handle == NULL)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("error operation on null pipe\n"));
LOG_D("error operation on null pipe");
return -1;
}
if (USB_HostMallocTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, &transfer) != kStatus_USB_Success)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("error to get transfer\n"));
LOG_D("error to get transfer");
return -1;
}
transfer->transferBuffer = buffer;
Expand Down Expand Up @@ -228,13 +231,13 @@ static int _ehci0_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nb
rt_completion_init(&(imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].urb_completion));
if (USB_HostEhciWritePipe(((usb_host_instance_t *)imxrt_usb_host_obj[USBH0_INDEX].host_handle)->controllerHandle, imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].pipe_handle, transfer) != kStatus_USB_Success)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb host failed to send\n"));
LOG_D("usb host failed to send");
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, transfer);
return -1;
}
if (-RT_ETIMEOUT == rt_completion_wait(&(imxrt_usb_host_obj[USBH0_INDEX].pipes[pipe->pipe_index].urb_completion), RT_WAITING_FOREVER))
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb transfer timeout\n"));
LOG_D("usb transfer timeout");
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH0_INDEX].host_handle, transfer);
return -1;
}
Expand All @@ -243,7 +246,7 @@ static int _ehci0_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nb
{
case kStatus_USB_Success:
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("ok\n"));
LOG_D("ok");
pipe->status = UPIPE_STATUS_OK;
if (pipe->callback != RT_NULL)
{
Expand All @@ -264,7 +267,7 @@ static int _ehci0_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nb
}
case kStatus_USB_TransferStall:
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("stall\n"));
LOG_D("stall");
pipe->status = UPIPE_STATUS_STALL;
if (pipe->callback != RT_NULL)
{
Expand All @@ -277,7 +280,7 @@ static int _ehci0_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nb
case kStatus_USB_TransferFailed:
default:
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("error\n"));
LOG_D("error");
pipe->status = UPIPE_STATUS_ERROR;
if (pipe->callback != RT_NULL)
{
Expand Down Expand Up @@ -358,25 +361,25 @@ static usb_status_t usb0_host_callback(usb_device_handle handle, usb_host_config
{
imxrt_usb_host_obj[USBH0_INDEX].connect_status = RT_TRUE;
imxrt_usb_host_obj[USBH0_INDEX].device_handle = handle;
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb connected\n"));
LOG_D("usb connected");
rt_usbh_root_hub_connect_handler(&(imxrt_usb_host_obj[USBH0_INDEX].uhcd), OTG_PORT, RT_TRUE);
}
break;

case kUSB_HostEventNotSupported:
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb device not supported\n"));
LOG_D("usb device not supported");
break;

case kUSB_HostEventEnumerationDone:
RT_DEBUG_LOG(RT_DEBUG_USB, ("enumeration done\n"));
LOG_D("enumeration done");
break;

case kUSB_HostEventDetach:
if (imxrt_usb_host_obj[USBH0_INDEX].connect_status)
{
imxrt_usb_host_obj[USBH0_INDEX].connect_status = RT_FALSE;
imxrt_usb_host_obj[USBH0_INDEX].device_handle = handle;
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb disconnnect\n"));
LOG_D("usb disconnnect");
rt_usbh_root_hub_disconnect_handler(&(imxrt_usb_host_obj[USBH0_INDEX].uhcd), OTG_PORT);
(void)USB_HostCloseDeviceInterface(handle, NULL);
}
Expand Down Expand Up @@ -448,12 +451,12 @@ static int _ehci1_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nb
usb_host_transfer_t *transfer;
if (imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].pipe_handle == NULL)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("error operation on null pipe\n"));
LOG_D("error operation on null pipe");
return -1;
}
if (USB_HostMallocTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, &transfer) != kStatus_USB_Success)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("error to get transfer\n"));
LOG_D("error to get transfer");
return -1;
}
transfer->transferBuffer = buffer;
Expand Down Expand Up @@ -505,13 +508,13 @@ static int _ehci1_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nb
rt_completion_init(&(imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].urb_completion));
if (USB_HostEhciWritePipe(((usb_host_instance_t *)imxrt_usb_host_obj[USBH1_INDEX].host_handle)->controllerHandle, imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].pipe_handle, transfer) != kStatus_USB_Success)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb host failed to send\n"));
LOG_D("usb host failed to send");
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, transfer);
return -1;
}
if (-RT_ETIMEOUT == rt_completion_wait(&(imxrt_usb_host_obj[USBH1_INDEX].pipes[pipe->pipe_index].urb_completion), RT_WAITING_FOREVER))
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb transfer timeout\n"));
LOG_D("usb transfer timeout");
(void)USB_HostFreeTransfer(imxrt_usb_host_obj[USBH1_INDEX].host_handle, transfer);
return -1;
}
Expand All @@ -521,7 +524,7 @@ static int _ehci1_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nb
{
case kStatus_USB_Success:
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("ok\n"));
LOG_D("ok");
pipe->status = UPIPE_STATUS_OK;
if (pipe->callback != RT_NULL)
{
Expand All @@ -542,7 +545,7 @@ static int _ehci1_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nb
}
case kStatus_USB_TransferStall:
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("stall\n"));
LOG_D("stall");
pipe->status = UPIPE_STATUS_STALL;
if (pipe->callback != RT_NULL)
{
Expand All @@ -555,7 +558,7 @@ static int _ehci1_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nb
case kStatus_USB_TransferFailed:
default:
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("error\n"));
LOG_D("error");
pipe->status = UPIPE_STATUS_ERROR;
if (pipe->callback != RT_NULL)
{
Expand Down Expand Up @@ -636,25 +639,25 @@ static usb_status_t usb1_host_callback(usb_device_handle handle, usb_host_config
{
imxrt_usb_host_obj[USBH1_INDEX].connect_status = RT_TRUE;
imxrt_usb_host_obj[USBH1_INDEX].device_handle = handle;
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb connected\n"));
LOG_D("usb connected");
rt_usbh_root_hub_connect_handler(&(imxrt_usb_host_obj[USBH1_INDEX].uhcd), OTG_PORT, RT_TRUE);
}
break;

case kUSB_HostEventNotSupported:
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb device not supported\n"));
LOG_D("usb device not supported");
break;

case kUSB_HostEventEnumerationDone:
RT_DEBUG_LOG(RT_DEBUG_USB, ("enumeration done\n"));
LOG_D("enumeration done");
break;

case kUSB_HostEventDetach:
if (imxrt_usb_host_obj[USBH1_INDEX].connect_status)
{
imxrt_usb_host_obj[USBH1_INDEX].connect_status = RT_FALSE;
imxrt_usb_host_obj[USBH1_INDEX].device_handle = handle;
RT_DEBUG_LOG(RT_DEBUG_USB, ("usb disconnnect\n"));
LOG_D("usb disconnnect");
rt_usbh_root_hub_disconnect_handler(&(imxrt_usb_host_obj[USBH1_INDEX].uhcd), OTG_PORT);
(void)USB_HostCloseDeviceInterface(handle, NULL);
}
Expand Down
Loading