Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teensy 4.1: implement USB remote wakeup #345

Draft
wants to merge 1 commit into
base: chibios-21.11.x
Choose a base branch
from
Draft
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
14 changes: 12 additions & 2 deletions ext/nxp-middleware-usb/device/usb_device_ehci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,13 @@ usb_status_t USB_DeviceEhciCancel(usb_device_controller_handle ehciHandle, uint8
return kStatus_USB_Success;
}

static uint32_t ms_to_cycles(const uint32_t val) {
// 600 cycles at 0.6 cycles/ns == 1μs
const uint32_t cycles_per_us = 600;
const uint32_t ms_to_us = 1000;
return val * ms_to_us * cycles_per_us;
}

/*!
* @brief Control the status of the selected item.
*
Expand Down Expand Up @@ -1696,8 +1703,11 @@ usb_status_t USB_DeviceEhciControl(usb_device_controller_handle ehciHandle, usb_
#endif
ehciState->registerBase->PORTSC1 &= ~USBHS_PORTSC1_PHCD_MASK;
ehciState->registerBase->PORTSC1 |= USBHS_PORTSC1_FPR_MASK;
startTick = deviceHandle->hwTick;
while ((deviceHandle->hwTick - startTick) < 10U)
// For easier ChibiOS integration, directly query the (already
// enabled) CYCCNT register instead of the deviceHandle->hwTick
// variable, which ChibiOS currently does not update.
startTick = DWT->CYCCNT;
while ((DWT->CYCCNT - startTick) < ms_to_cycles(10U))
{
__NOP();
}
Expand Down
8 changes: 6 additions & 2 deletions os/hal/ports/MIMXRT1062/LLD/USBHSv1/hal_usb_lld.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,16 @@ static usb_status_t usb_device_callback(usb_device_handle handle, uint32_t callb
break;

case kUSB_DeviceEventSuspend:
printf_debug(" suspend");
printf_debug(" suspend--nxp");
// Call USB_DeviceSetStatus() to enable the “detect resume” interrupt.
usb_device_struct_t *dev_handle = (usb_device_struct_t *)handle;
(void)USB_DeviceSetStatus(dev_handle, kUSB_DeviceStatusBusSuspend, NULL);
printf_debug(" suspend--chibi");
_usb_suspend(usbp);
break;

case kUSB_DeviceEventResume:
printf_debug(" resume");
printf_debug(" resume--chibi");
_usb_wakeup(usbp);
break;
}
Expand Down
6 changes: 4 additions & 2 deletions os/hal/ports/MIMXRT1062/LLD/USBHSv1/hal_usb_lld.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,10 @@ struct USBDriver {
* @notapi
*/
#define usb_lld_wakeup_host(usbp) \
do{ \
} while (false)
do{ \
usb_device_struct_t *dev_handle = (usb_device_struct_t *)handle; \
(void)USB_DeviceSetStatus(dev_handle, kUSB_DeviceStatusBusResume, NULL); \
} while (0)


/*===========================================================================*/
Expand Down
4 changes: 2 additions & 2 deletions os/hal/ports/MIMXRT1062/LLD/USBHSv1/usb_device_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@
#define USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE (0U)
#endif
/*! @brief Whether the low power mode is enabled or not. */
#define USB_DEVICE_CONFIG_LOW_POWER_MODE (0U)
#define USB_DEVICE_CONFIG_LOW_POWER_MODE (1U)

#if ((defined(USB_DEVICE_CONFIG_LOW_POWER_MODE)) && (USB_DEVICE_CONFIG_LOW_POWER_MODE > 0U))
/*! @brief Whether device remote wakeup supported. 1U supported, 0U not supported */
#define USB_DEVICE_CONFIG_REMOTE_WAKEUP (0U)
#define USB_DEVICE_CONFIG_REMOTE_WAKEUP (1U)

/*! @brief Whether LPM is supported. 1U supported, 0U not supported */
#define USB_DEVICE_CONFIG_LPM_L1 (0U)
Expand Down