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

nrf_usbd_common: Do not trigger DMA in low power mode #81596

Merged
merged 2 commits into from
Nov 26, 2024
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
10 changes: 8 additions & 2 deletions drivers/usb/common/nrf_usbd_common/nrf_usbd_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,10 @@ static void usbd_dmareq_process(void)
{
if ((m_ep_dma_waiting & m_ep_ready) &&
(k_sem_take(&dma_available, K_NO_WAIT) == 0)) {
const bool low_power = nrf_usbd_common_suspend_check();
uint32_t req;

while (0 != (req = m_ep_dma_waiting & m_ep_ready)) {
while (!low_power && 0 != (req = m_ep_dma_waiting & m_ep_ready)) {
uint8_t pos;

if (NRFX_USBD_CONFIG_DMASCHEDULER_ISO_BOOST &&
Expand Down Expand Up @@ -1310,7 +1311,11 @@ bool nrf_usbd_common_is_started(void)
bool nrf_usbd_common_suspend(void)
{
bool suspended = false;
unsigned int irq_lock_key = irq_lock();
unsigned int irq_lock_key;

/* DMA doesn't work in Low Power mode, ensure there is no active DMA */
k_sem_take(&dma_available, K_FOREVER);
irq_lock_key = irq_lock();

if (m_bus_suspend) {
if (!(NRF_USBD->EVENTCAUSE & USBD_EVENTCAUSE_RESUME_Msk)) {
Expand All @@ -1327,6 +1332,7 @@ bool nrf_usbd_common_suspend(void)
}

irq_unlock(irq_lock_key);
k_sem_give(&dma_available);

return suspended;
}
Expand Down
35 changes: 19 additions & 16 deletions drivers/usb/udc/udc_nrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,22 @@ static void udc_nrf_thread(void *p1, void *p2, void *p3)
case UDC_NRF_EVT_HAL:
ep = evt.hal_evt.data.eptransfer.ep;
switch (evt.hal_evt.type) {
case NRF_USBD_COMMON_EVT_SUSPEND:
LOG_INF("SUSPEND state detected");
nrf_usbd_common_suspend();
udc_set_suspended(udc_nrf_dev, true);
udc_submit_event(udc_nrf_dev, UDC_EVT_SUSPEND, 0);
break;
case NRF_USBD_COMMON_EVT_RESUME:
LOG_INF("RESUMING from suspend");
udc_set_suspended(udc_nrf_dev, false);
udc_submit_event(udc_nrf_dev, UDC_EVT_RESUME, 0);
break;
case NRF_USBD_COMMON_EVT_WUREQ:
LOG_INF("Remote wakeup initiated");
udc_set_suspended(udc_nrf_dev, false);
udc_submit_event(udc_nrf_dev, UDC_EVT_RESUME, 0);
break;
case NRF_USBD_COMMON_EVT_EPTRANSFER:
start_xfer = true;
if (USB_EP_DIR_IS_IN(ep)) {
Expand Down Expand Up @@ -499,22 +515,6 @@ static void udc_sof_check_iso_out(const struct device *dev)
static void usbd_event_handler(nrf_usbd_common_evt_t const *const hal_evt)
{
switch (hal_evt->type) {
case NRF_USBD_COMMON_EVT_SUSPEND:
LOG_INF("SUSPEND state detected");
nrf_usbd_common_suspend();
udc_set_suspended(udc_nrf_dev, true);
udc_submit_event(udc_nrf_dev, UDC_EVT_SUSPEND, 0);
break;
case NRF_USBD_COMMON_EVT_RESUME:
LOG_INF("RESUMING from suspend");
udc_set_suspended(udc_nrf_dev, false);
udc_submit_event(udc_nrf_dev, UDC_EVT_RESUME, 0);
break;
case NRF_USBD_COMMON_EVT_WUREQ:
LOG_INF("Remote wakeup initiated");
udc_set_suspended(udc_nrf_dev, false);
udc_submit_event(udc_nrf_dev, UDC_EVT_RESUME, 0);
break;
case NRF_USBD_COMMON_EVT_RESET:
LOG_INF("Reset");
udc_submit_event(udc_nrf_dev, UDC_EVT_RESET, 0);
Expand All @@ -523,6 +523,9 @@ static void usbd_event_handler(nrf_usbd_common_evt_t const *const hal_evt)
udc_submit_event(udc_nrf_dev, UDC_EVT_SOF, 0);
udc_sof_check_iso_out(udc_nrf_dev);
break;
case NRF_USBD_COMMON_EVT_SUSPEND:
case NRF_USBD_COMMON_EVT_RESUME:
case NRF_USBD_COMMON_EVT_WUREQ:
case NRF_USBD_COMMON_EVT_EPTRANSFER:
case NRF_USBD_COMMON_EVT_SETUP: {
struct udc_nrf_evt evt = {
Expand Down
Loading