diff --git a/firmware/target/arm/rk27xx/debug-rk27xx.c b/firmware/target/arm/rk27xx/debug-rk27xx.c
index 5c2d356..7786e50 100644
--- a/firmware/target/arm/rk27xx/debug-rk27xx.c
+++ b/firmware/target/arm/rk27xx/debug-rk27xx.c
@@ -43,6 +43,9 @@
extern unsigned long sd_debug_time_rd;
extern unsigned long sd_debug_time_wr;
+extern volatile uint32_t udc_irq[8];
+extern volatile uint32_t udc_setup;
+
bool dbg_hw_info(void)
{
int line;
@@ -62,6 +65,11 @@ bool dbg_hw_info(void)
_DEBUG_PRINTF("SCU_DIVCON1: 0x%0x", SCU_DIVCON1);
_DEBUG_PRINTF("SCU_CLKCFG: 0x%0x", SCU_CLKCFG);
_DEBUG_PRINTF("SCU_CHIPCFG: 0x%0x", SCU_CHIPCFG);
+ _DEBUG_PRINTF("INTC_IMR: 0x%0x", INTC_IMR);
+ _DEBUG_PRINTF("INTC_IECR: 0x%0x", INTC_IECR);
+ _DEBUG_PRINTF("udc_irq[] 1:0x%0x 2:0x%0x 3:0x%0x 4:0x%0x 5:0x%0x 6:0x%0x 7:0x%0x", udc_irq[0],udc_irq[1],udc_irq[2],udc_irq[3],udc_irq[4],udc_irq[5],udc_irq[6],udc_irq[7]);
+ _DEBUG_PRINTF("udc_setup: %d", udc_setup);
+
line++;
_DEBUG_PRINTF("sd_debug_time_rd: %d", sd_debug_time_rd);
_DEBUG_PRINTF("sd_debug_time_wr: %d", sd_debug_time_wr);
diff --git a/firmware/target/arm/rk27xx/usb-drv-rk27xx.c b/firmware/target/arm/rk27xx/usb-drv-rk27xx.c
index 3001509..b137293 100644
--- a/firmware/target/arm/rk27xx/usb-drv-rk27xx.c
+++ b/firmware/target/arm/rk27xx/usb-drv-rk27xx.c
@@ -98,6 +98,10 @@ static struct endpoint_t endpoints[16] = {
{USB_ENDPOINT_XFER_INT, DIR_IN, false, NULL, 0, 0, false, {0, 0, 0}}, /* IIN15 */
};
+volatile uint32_t udc_irq[8] = {0,0,0,0,0,0,0,0};
+volatile uint32_t udc_irq_idx = 0;
+volatile uint32_t udc_setup = 0;
+
static void setup_received(void)
{
static uint32_t setup_data[2];
@@ -229,17 +233,35 @@ static void int_write(int ep)
endpoints[ep_num].buf += xfer_size;
}
+static void udc_phy_reset(void)
+{
+ DEV_CTL |= (1<<7); // SOFT POR
+ udelay(10000);
+ DEV_CTL &= ~(1<<7);
+}
+
+static void udc_soft_connect(void)
+{
+ DEV_CTL |= (1<<8) | /* Configure CSR done */
+ (1<<4) | /* Device soft connect */
+ (1<<3); /* Device self power */
+}
+
/* UDC ISR function */
void INT_UDC(void)
{
uint32_t txstat, rxstat;
int tmp, ep_num;
-
+
/* read what caused UDC irq */
uint32_t intsrc = INT2FLAG & 0x7fffff;
-
+
+ udc_irq[udc_irq_idx & 7] = intsrc;
+ udc_irq_idx++;
+
if (intsrc & (1<<1)) /* setup interrupt */
{
+ udc_setup++;
setup_received();
}
else if (intsrc & (1<<2)) /* ep0 in interrupt */
@@ -286,7 +308,25 @@ void INT_UDC(void)
}
else if (intsrc & (1<<4)) /* usb reset */
{
- usb_drv_init();
+ EN_INT = (1<<6) | /* Enable Suspend Interrupt */
+ (1<<5) | /* Enable Resume Interrupt */
+ (1<<4) | /* Enable USB Reset Interrupt */
+ (1<<3) | /* Enable OUT Token receive Interrupt EP0 */
+ (1<<2) | /* Enable IN Token transmits Interrupt EP0 */
+ (1<<1); /* Enable SETUP Packet Receive Interrupt */
+
+ INTCON = (1<<2) | /* interrupt high active */
+ (1<<0); /* enable EP0 interrupts */
+
+ TX0CON = (1<<6) | /* Set as one to enable the EP0 tx irq */
+ (1<<2); /* Set as one to response NAK handshake */
+
+ RX0CON = (1<<7) |
+ (1<<4) | /* Endpoint 0 Enable. When cleared the endpoint does
+ * not respond to an SETUP or OUT token
+ */
+
+ (1<<3); /* Set as one to response NAK handshake */
}
else if (intsrc & (1<<5)) /* usb resume */
{
@@ -300,6 +340,9 @@ void INT_UDC(void)
}
else if (intsrc & (1<<7)) /* usb connect */
{
+ udc_phy_reset();
+ udelay(10000);
+ udc_soft_connect();
}
else
{
@@ -641,9 +684,6 @@ void usb_drv_init(void)
{
int ep_num;
- /* enable USB clock */
- SCU_CLKCFG &= ~(1<<6);
-
/* 1. do soft disconnect */
DEV_CTL = (1<<3); /* DEV_SELF_PWR */
@@ -657,14 +697,14 @@ void usb_drv_init(void)
/* 4. clear SOFT_POR bit */
DEV_CTL &= ~(1<<7);
- /* 5. configure minimal EN_INT */
+ /* 5. configure minimal EN_INT */
EN_INT = (1<<6) | /* Enable Suspend Interrupt */
(1<<5) | /* Enable Resume Interrupt */
(1<<4) | /* Enable USB Reset Interrupt */
(1<<3) | /* Enable OUT Token receive Interrupt EP0 */
(1<<2) | /* Enable IN Token transmits Interrupt EP0 */
(1<<1); /* Enable SETUP Packet Receive Interrupt */
-
+
/* 6. configure INTCON */
INTCON = (1<<2) | /* interrupt high active */
(1<<0); /* enable EP0 interrupts */
@@ -681,8 +721,8 @@ void usb_drv_init(void)
(1<<3); /* Set as one to response NAK handshake */
/* 8. write final bits to DEV_CTL */
- DEV_CTL = (1<<8) | /* Configure CSR done */
- (1<<6) | /* 16-bit data path enabled. udc_clk = 30MHz */
+ DEV_CTL |= (1<<8) | /* Configure CSR done */
+ // (1<<6) | /* 16-bit data path enabled. udc_clk = 30MHz */
(1<<4) | /* Device soft connect */
(1<<3); /* Device self power */
@@ -707,16 +747,18 @@ void usb_drv_init(void)
BIN_TXCON(ep_num) |= (ep_num<<8)|(1<<3)|(1<<2); /* ep_num, enable, NAK */
}
}
+
+
}
/* turn off usb core */
void usb_drv_exit(void)
{
- DEV_CTL = (1<<3); /* DEV_SELF_PWR */
+// DEV_CTL = (1<<3); /* DEV_SELF_PWR */
/* disable USB interrupts in interrupt controller */
- INTC_IMR &= ~(1<<16);
- INTC_IECR &= ~(1<<16);
+// INTC_IMR &= ~(1<<16);
+// INTC_IECR &= ~(1<<16);
/* we cannot disable UDC clock since this causes data abort
* when reading DEV_INFO in order to check usb connect event
diff --git a/firmware/target/arm/rk27xx/usb-rk27xx.c b/firmware/target/arm/rk27xx/usb-rk27xx.c
index 20bf867..8e32d80 100644
--- a/firmware/target/arm/rk27xx/usb-rk27xx.c
+++ b/firmware/target/arm/rk27xx/usb-rk27xx.c
@@ -32,6 +32,8 @@ int usb_status = USB_EXTRACTED;
void usb_init_device(void)
{
+ INTC_IMR |= (1<<16);
+ INTC_IECR |= (1<<16);
}
void usb_attach(void)