From 198c3dd20ea9096716769f857966f6f9bfee9076 Mon Sep 17 00:00:00 2001 From: alexrayne Date: Wed, 24 May 2017 13:11:41 +0200 Subject: [PATCH 1/4] !usbd:dwc_otg:ep reset:disable - surely disable endpoint on reset and stop. if ep leaved enabled - it miss new requests until transfer completes; --- lib/usbd/backend/usbd_dwc_otg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/usbd/backend/usbd_dwc_otg.c b/lib/usbd/backend/usbd_dwc_otg.c index ebb42f89..c27e0735 100644 --- a/lib/usbd/backend/usbd_dwc_otg.c +++ b/lib/usbd/backend/usbd_dwc_otg.c @@ -173,11 +173,11 @@ static void disable_all_non_ep0(usbd_device *dev) REBASE(DWC_OTG_DOEPxINT, i) = 0xFFFF; REBASE(DWC_OTG_DOEPxTSIZ, i) = 0; - REBASE(DWC_OTG_DOEPxCTL, i) = DWC_OTG_DOEPCTL_SNAK; + REBASE(DWC_OTG_DOEPxCTL, i) = DWC_OTG_DOEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; REBASE(DWC_OTG_DIEPxINT, i) = 0xFFFF; REBASE(DWC_OTG_DIEPxTSIZ, i) = 0; - REBASE(DWC_OTG_DIEPxCTL, i) = DWC_OTG_DIEPCTL_SNAK; + REBASE(DWC_OTG_DIEPxCTL, i) = DWC_OTG_DIEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; } REBASE(DWC_OTG_DAINTMSK) &= ~(DWC_OTG_DAINTMSK_OEPM(0) | DWC_OTG_DAINTMSK_IEPM(0)); From 60404f0bd675dd5109508eb19180065dbfc797dc Mon Sep 17 00:00:00 2001 From: alexrayne Date: Wed, 24 May 2017 13:23:50 +0200 Subject: [PATCH 2/4] !usbd:stop ep - forget to ensure disabling stoped ep. --- lib/usbd/backend/usbd_dwc_otg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/usbd/backend/usbd_dwc_otg.c b/lib/usbd/backend/usbd_dwc_otg.c index c27e0735..99f945bf 100644 --- a/lib/usbd/backend/usbd_dwc_otg.c +++ b/lib/usbd/backend/usbd_dwc_otg.c @@ -676,11 +676,11 @@ static void premature_urb_complete(usbd_device *dev, usbd_urb *urb, uint8_t ep_num = ENDPOINT_NUMBER(transfer->ep_addr); if (IS_IN_ENDPOINT(transfer->ep_addr)) { - REBASE(DWC_OTG_DIEPxCTL, ep_num) |= DWC_OTG_DIEPCTL_SNAK; + REBASE(DWC_OTG_DIEPxCTL, ep_num) |= DWC_OTG_DIEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; REBASE(DWC_OTG_DIEPxINT, ep_num) = 0xFFFF; REBASE(DWC_OTG_DAINTMSK) &= ~DWC_OTG_DAINTMSK_IEPM(ep_num); } else { - REBASE(DWC_OTG_DOEPxCTL, ep_num) |= DWC_OTG_DOEPCTL_SNAK; + REBASE(DWC_OTG_DOEPxCTL, ep_num) |= DWC_OTG_DOEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; REBASE(DWC_OTG_DOEPxINT, ep_num) = 0xFFFF ^ DWC_OTG_DOEPINT_STUP; REBASE(DWC_OTG_DAINTMSK) &= ~DWC_OTG_DAINTMSK_OEPM(ep_num); } From 2d02a6718ec8f61b71fc581f51514ba92615228d Mon Sep 17 00:00:00 2001 From: alexrayne Date: Thu, 25 May 2017 00:47:59 +0200 Subject: [PATCH 3/4] !usbd:stop ep - RM demands to use DxEPCTL.EPDIS flag only if EPENA is set! also better to avoid EPDIS interrupt for normaly completed and disabled endpoints --- lib/usbd/backend/usbd_dwc_otg.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/usbd/backend/usbd_dwc_otg.c b/lib/usbd/backend/usbd_dwc_otg.c index 99f945bf..8793c951 100644 --- a/lib/usbd/backend/usbd_dwc_otg.c +++ b/lib/usbd/backend/usbd_dwc_otg.c @@ -173,11 +173,17 @@ static void disable_all_non_ep0(usbd_device *dev) REBASE(DWC_OTG_DOEPxINT, i) = 0xFFFF; REBASE(DWC_OTG_DOEPxTSIZ, i) = 0; - REBASE(DWC_OTG_DOEPxCTL, i) = DWC_OTG_DOEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; + if ((REBASE(DWC_OTG_DOEPxCTL, i) & DWC_OTG_DOEPCTL_EPENA) == 0) + REBASE(DWC_OTG_DOEPxCTL, i) = DWC_OTG_DOEPCTL_SNAK; + else + REBASE(DWC_OTG_DOEPxCTL, i) = DWC_OTG_DOEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; REBASE(DWC_OTG_DIEPxINT, i) = 0xFFFF; REBASE(DWC_OTG_DIEPxTSIZ, i) = 0; - REBASE(DWC_OTG_DIEPxCTL, i) = DWC_OTG_DIEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; + if ((REBASE(DWC_OTG_DIEPxCTL, i) & DWC_OTG_DIEPCTL_EPENA) == 0) + REBASE(DWC_OTG_DIEPxCTL, i) = DWC_OTG_DIEPCTL_SNAK; + else + REBASE(DWC_OTG_DIEPxCTL, i) = DWC_OTG_DIEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; } REBASE(DWC_OTG_DAINTMSK) &= ~(DWC_OTG_DAINTMSK_OEPM(0) | DWC_OTG_DAINTMSK_IEPM(0)); @@ -676,11 +682,17 @@ static void premature_urb_complete(usbd_device *dev, usbd_urb *urb, uint8_t ep_num = ENDPOINT_NUMBER(transfer->ep_addr); if (IS_IN_ENDPOINT(transfer->ep_addr)) { - REBASE(DWC_OTG_DIEPxCTL, ep_num) |= DWC_OTG_DIEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; + if ((REBASE(DWC_OTG_DIEPxCTL, i) & DWC_OTG_DIEPCTL_EPENA) == 0) + REBASE(DWC_OTG_DIEPxCTL, ep_num) |= DWC_OTG_DIEPCTL_SNAK; + else + REBASE(DWC_OTG_DIEPxCTL, ep_num) |= DWC_OTG_DIEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; REBASE(DWC_OTG_DIEPxINT, ep_num) = 0xFFFF; REBASE(DWC_OTG_DAINTMSK) &= ~DWC_OTG_DAINTMSK_IEPM(ep_num); } else { - REBASE(DWC_OTG_DOEPxCTL, ep_num) |= DWC_OTG_DOEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; + if ((REBASE(DWC_OTG_DOEPxCTL, i) & DWC_OTG_DOEPCTL_EPENA) == 0) + REBASE(DWC_OTG_DOEPxCTL, ep_num) |= DWC_OTG_DOEPCTL_SNAK; + else + REBASE(DWC_OTG_DOEPxCTL, ep_num) |= DWC_OTG_DOEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; REBASE(DWC_OTG_DOEPxINT, ep_num) = 0xFFFF ^ DWC_OTG_DOEPINT_STUP; REBASE(DWC_OTG_DAINTMSK) &= ~DWC_OTG_DAINTMSK_OEPM(ep_num); } From 26d9a5fa1a7e13af53828d540910f9c67dfe2726 Mon Sep 17 00:00:00 2001 From: alexrayne Date: Thu, 25 May 2017 14:39:09 +0200 Subject: [PATCH 4/4] !usbd:stop ep - trivial fix, cause need test before publish --- lib/usbd/backend/usbd_dwc_otg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/usbd/backend/usbd_dwc_otg.c b/lib/usbd/backend/usbd_dwc_otg.c index 8793c951..dea71f45 100644 --- a/lib/usbd/backend/usbd_dwc_otg.c +++ b/lib/usbd/backend/usbd_dwc_otg.c @@ -682,14 +682,14 @@ static void premature_urb_complete(usbd_device *dev, usbd_urb *urb, uint8_t ep_num = ENDPOINT_NUMBER(transfer->ep_addr); if (IS_IN_ENDPOINT(transfer->ep_addr)) { - if ((REBASE(DWC_OTG_DIEPxCTL, i) & DWC_OTG_DIEPCTL_EPENA) == 0) + if ((REBASE(DWC_OTG_DIEPxCTL, ep_num) & DWC_OTG_DIEPCTL_EPENA) == 0) REBASE(DWC_OTG_DIEPxCTL, ep_num) |= DWC_OTG_DIEPCTL_SNAK; else REBASE(DWC_OTG_DIEPxCTL, ep_num) |= DWC_OTG_DIEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS; REBASE(DWC_OTG_DIEPxINT, ep_num) = 0xFFFF; REBASE(DWC_OTG_DAINTMSK) &= ~DWC_OTG_DAINTMSK_IEPM(ep_num); } else { - if ((REBASE(DWC_OTG_DOEPxCTL, i) & DWC_OTG_DOEPCTL_EPENA) == 0) + if ((REBASE(DWC_OTG_DOEPxCTL, ep_num) & DWC_OTG_DOEPCTL_EPENA) == 0) REBASE(DWC_OTG_DOEPxCTL, ep_num) |= DWC_OTG_DOEPCTL_SNAK; else REBASE(DWC_OTG_DOEPxCTL, ep_num) |= DWC_OTG_DOEPCTL_SNAK | DWC_OTG_DOEPCTL_EPDIS;