Skip to content

Instantly share code, notes, and snippets.

@voidlizard
Created February 4, 2012 06:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voidlizard/1735911 to your computer and use it in GitHub Desktop.
Save voidlizard/1735911 to your computer and use it in GitHub Desktop.
diff --git a/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/inc/usb_core.h b/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/inc/usb_core.h
index 82a09e1..b38bb90 100644
--- a/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/inc/usb_core.h
+++ b/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/inc/usb_core.h
@@ -267,6 +267,7 @@ typedef struct _HCD
__IO uint32_t ConnSts;
__IO uint32_t ErrCnt[USB_OTG_MAX_TX_FIFOS];
__IO uint32_t XferCnt[USB_OTG_MAX_TX_FIFOS];
+ __IO uint32_t NakCnt[USB_OTG_MAX_TX_FIFOS];
__IO HC_STATUS HC_Status[USB_OTG_MAX_TX_FIFOS];
__IO URB_STATE URB_State[USB_OTG_MAX_TX_FIFOS];
USB_OTG_HC hc [USB_OTG_MAX_TX_FIFOS];
diff --git a/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/inc/usb_defines.h b/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/inc/usb_defines.h
index b119c25..ec1920b 100644
--- a/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/inc/usb_defines.h
+++ b/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/inc/usb_defines.h
@@ -230,6 +230,11 @@ enum USB_OTG_SPEED {
USB_SPEED_HIGH
};
+
+#ifndef USB_NAK_RETRY_ATTEMPTS
+#define USB_NAK_RETRY_ATTEMPTS 10000
+#endif
+
#endif //__USB_DEFINES__H__
diff --git a/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c b/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c
index 74e432a..c97a1d8 100644
--- a/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c
+++ b/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c
@@ -1095,6 +1095,7 @@ USB_OTG_STS USB_OTG_HC_StartXfer(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
pdev->host.hc[hc_num].xfer_buff ,
hc_num, pdev->host.hc[hc_num].xfer_len);
}
+
}
return status;
}
diff --git a/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/src/usb_hcd.c b/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/src/usb_hcd.c
index 9174bdc..74cb76c 100644
--- a/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/src/usb_hcd.c
+++ b/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/src/usb_hcd.c
@@ -97,6 +97,7 @@ uint32_t HCD_Init(USB_OTG_CORE_HANDLE *pdev ,
for (i= 0; i< USB_OTG_MAX_TX_FIFOS; i++)
{
pdev->host.ErrCnt[i] = 0;
+ pdev->host.NakCnt[i] = 0;
pdev->host.XferCnt[i] = 0;
pdev->host.HC_Status[i] = HC_IDLE;
}
diff --git a/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/src/usb_hcd_int.c b/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/src/usb_hcd_int.c
index ed7012d..e6e2a46 100644
--- a/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/src/usb_hcd_int.c
+++ b/lib/STM32_F105-07_F2xx_USB-Host-Device_Lib_V2.0.0/Libraries/STM32_USB_OTG_Driver/src/usb_hcd_int.c
@@ -475,11 +475,11 @@ uint32_t USB_OTG_USBH_handle_hc_n_Out_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t
else if (hcint.b.xfercompl)
{
pdev->host.ErrCnt[num] = 0;
+ pdev->host.NakCnt[num] = 0;
UNMASK_HOST_INT_CHH (num);
USB_OTG_HC_Halt(pdev, num);
CLEAR_HC_INT(hcreg , xfercompl);
pdev->host.HC_Status[num] = HC_XFRC;
- ledOn();
}
else if (hcint.b.stall)
@@ -493,6 +493,7 @@ uint32_t USB_OTG_USBH_handle_hc_n_Out_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t
else if (hcint.b.nak)
{
pdev->host.ErrCnt[num] = 0;
+ pdev->host.NakCnt[num]++;
UNMASK_HOST_INT_CHH (num);
USB_OTG_HC_Halt(pdev, num);
CLEAR_HC_INT(hcreg , nak);
@@ -583,7 +584,6 @@ uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t n
USB_OTG_HCCHAR_TypeDef hcchar;
USB_OTG_HCTSIZn_TypeDef hctsiz;
USB_OTG_HC_REGS *hcreg;
-
hcreg = pdev->regs.HC_REGS[num];
hcint.d32 = USB_OTG_READ_REG32(&hcreg->HCINT);
@@ -600,6 +600,7 @@ uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t n
}
else if (hcint.b.ack)
{
+ pdev->host.NakCnt[num] = 0;
CLEAR_HC_INT(hcreg ,ack);
}
@@ -633,6 +634,7 @@ uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t n
else if (hcint.b.xfercompl)
{
+ pdev->host.NakCnt[num] = 0;
if (pdev->cfg.dma_enable == 1)
{
@@ -700,7 +702,9 @@ uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t n
}
else if (hcint.b.nak)
- {
+ {
+ pdev->host.NakCnt[num]++;
+
if(hcchar.b.eptype == EP_TYPE_INTR)
{
UNMASK_HOST_INT_CHH (num);
@@ -711,9 +715,17 @@ uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t n
(hcchar.b.eptype == EP_TYPE_BULK))
{
/* re-activate the channel */
- hcchar.b.chen = 1;
- hcchar.b.chdis = 0;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[num]->HCCHAR, hcchar.d32);
+ /* dmz: check retrying number to avoid an eternal loop in interrupt handler */
+ if( pdev->host.NakCnt[num] < USB_NAK_RETRY_ATTEMPTS ) {
+ hcchar.b.chen = 1;
+ hcchar.b.chdis = 0;
+ USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[num]->HCCHAR, hcchar.d32);
+ } else {
+ pdev->host.ErrCnt[num] ++;
+ pdev->host.NakCnt[num] = 0;
+ pdev->host.HC_Status[num] = HC_NAK;
+ CLEAR_HC_INT(hcreg , nak);
+ }
}
pdev->host.HC_Status[num] = HC_NAK;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment