1
0
mirror of https://github.com/gdsports/USBHost_t36 synced 2024-11-11 19:55:04 -05:00

Reset & enable port, but EHCI stops with error :-(

This commit is contained in:
PaulStoffregen 2016-06-27 06:42:39 -07:00
parent 9264f60908
commit 453d04d42d

View File

@ -1,19 +1,26 @@
// usb host experiments.... // usb host experiments....
//void * periodictable[64] __attribute__ ((section(".dmabuffers"), used, aligned(4096)))
uint32_t periodictable[64] __attribute__ ((aligned(4096)));
void setup() void setup()
{ {
pinMode(32, OUTPUT); // pin 32 = USB switch, high=connect device pinMode(32, OUTPUT); // pin 32 = USB switch, high=connect device
digitalWrite(32, LOW); digitalWrite(32, LOW);
while (!Serial) ; // wait while (!Serial) ; // wait
print("USB Host Testing"); print("USB Host Testing");
MPU_RGDAAC0 |= 0x30000000;
MCG_C1 |= MCG_C1_IRCLKEN; // enable MCGIRCLK 32kHz MCG_C1 |= MCG_C1_IRCLKEN; // enable MCGIRCLK 32kHz
OSC0_CR |= OSC_ERCLKEN; OSC0_CR |= OSC_ERCLKEN;
SIM_SOPT2 |= SIM_SOPT2_USBREGEN; // turn on USB regulator SIM_SOPT2 |= SIM_SOPT2_USBREGEN; // turn on USB regulator
SIM_SOPT2 &= ~SIM_SOPT2_USBSLSRC; // use IRC for slow clock SIM_SOPT2 &= ~SIM_SOPT2_USBSLSRC; // use IRC for slow clock
print("power up USBHS PHY"); print("power up USBHS PHY");
SIM_USBPHYCTL |= SIM_USBPHYCTL_USBDISILIM; // disable USB current limit SIM_USBPHYCTL |= SIM_USBPHYCTL_USBDISILIM; // disable USB current limit
SIM_USBPHYCTL = SIM_USBPHYCTL_USBDISILIM | SIM_USBPHYCTL_USB3VOUTTRG(6); // pg 237 //SIM_USBPHYCTL = SIM_USBPHYCTL_USBDISILIM | SIM_USBPHYCTL_USB3VOUTTRG(6); // pg 237
SIM_SCGC3 |= SIM_SCGC3_USBHSDCD | SIM_SCGC3_USBHSPHY | SIM_SCGC3_USBHS; SIM_SCGC3 |= SIM_SCGC3_USBHSDCD | SIM_SCGC3_USBHSPHY | SIM_SCGC3_USBHS;
USBHSDCD_CLOCK = 33 << 2;
print("init USBHS PHY & PLL"); print("init USBHS PHY & PLL");
// init process: page 1681-1682 // init process: page 1681-1682
USBPHY_CTRL &= ~USBPHY_CTRL_SFTRST; // CTRL pg 1698 USBPHY_CTRL &= ~USBPHY_CTRL_SFTRST; // CTRL pg 1698
@ -52,15 +59,32 @@ void setup()
// USBHS_PORTSC 1619 00002000 // USBHS_PORTSC 1619 00002000
// USBHS_USBMODE 1629 00005000 // USBHS_USBMODE 1629 00005000
print("begin ehci reset");
USBHS_USBCMD |= USBHS_USBCMD_RST;
count = 0;
while (USBHS_USBCMD & USBHS_USBCMD_RST) {
count;
}
print(" reset waited ", count);
for (int i=0; i < 64; i++) {
//periodictable[i] = (void *)1;
periodictable[i] = 1;
}
USBHS_USBINTR = 0; USBHS_USBINTR = 0;
USBHS_PERIODICLISTBASE = 0; // TODO: data.. USBHS_PERIODICLISTBASE = (uint32_t)periodictable;
USBHS_FRINDEX = 0;
USBHS_ASYNCLISTADDR = 0; // TODO: data.. USBHS_ASYNCLISTADDR = 0; // TODO: data..
// turn on the USBHS controller // turn on the USBHS controller
USBHS_USBMODE = USBHS_USBMODE_TXHSD(5) | USBHS_USBMODE_CM(3); // host mode USBHS_USBMODE = USBHS_USBMODE_TXHSD(5) | USBHS_USBMODE_CM(3); // host mode
USBHS_USBCMD = USBHS_USBCMD_ITC(8) | USBHS_USBCMD_RS | USBHS_USBCMD = USBHS_USBCMD_ITC(0) | USBHS_USBCMD_RS | USBHS_USBCMD_ASP(3) |
USBHS_USBCMD_FS2 | USBHS_USBCMD_FS(0); // periodic table is 64 pointers USBHS_USBCMD_FS2 | USBHS_USBCMD_FS(0) | // periodic table is 64 pointers
USBHS_USBCMD_PSE;
USBHS_PORTSC1 |= USBHS_PORTSC_PP; USBHS_PORTSC1 |= USBHS_PORTSC_PP;
//USBHS_PORTSC1 |= USBHS_PORTSC_PFSC; // force 12 Mbit/sec
//USBHS_PORTSC1 |= USBHS_PORTSC_PHCD; // phy off
} }
void port_status() void port_status()
@ -77,12 +101,14 @@ void port_status()
} else { } else {
Serial.print("off "); Serial.print("off ");
} }
if (n & USBHS_PORTSC_PHCD) {
Serial.print("phyoff ");
}
if (n & USBHS_PORTSC_PE) { if (n & USBHS_PORTSC_PE) {
if (USBHS_PORTSC_SUSP) { if (n & USBHS_PORTSC_SUSP) {
Serial.print("suspend "); Serial.print("suspend ");
} else { } else {
Serial.print("enable "); // not working... why? Serial.print("enable ");
} }
} else { } else {
Serial.print("disable "); Serial.print("disable ");
@ -101,10 +127,24 @@ void port_status()
Serial.print("overcurrent "); Serial.print("overcurrent ");
} }
if (n & USBHS_PORTSC_CCS) { if (n & USBHS_PORTSC_CCS) {
Serial.print("connected"); Serial.print("connected ");
} else { } else {
Serial.print("not-connected"); Serial.print("not-connected ");
} }
// print info about the EHCI status
Serial.print(" run=");
Serial.print(USBHS_USBCMD & 1); // running mode
Serial.print(",halt=");
Serial.print((USBHS_USBSTS >> 12) & 1); // halted mode
Serial.print(",err=");
Serial.print((USBHS_USBSTS >> 4) & 1); // error encountered!
Serial.print(",asyn=");
Serial.print((USBHS_USBSTS >> 15) & 1); // running the async schedule
Serial.print(",per=");
Serial.print((USBHS_USBSTS >> 14) & 1); // running the periodic schedule
Serial.print(",index=");
Serial.print(USBHS_FRINDEX); // periodic index
Serial.println(); Serial.println();
} }
@ -120,15 +160,17 @@ void loop()
Serial.println("Plug in device..."); Serial.println("Plug in device...");
digitalWrite(32, HIGH); // connect device digitalWrite(32, HIGH); // connect device
} }
if (count == 6) { if (count == 5) {
Serial.println("Initiate Reset Sequence..."); Serial.println("Initiate Reset Sequence...");
USBHS_PORTSC1 |= USBHS_PORTSC_PR; USBHS_PORTSC1 |= USBHS_PORTSC_PR;
} }
if (count == 16) { if (count == 15) {
Serial.println("End Reset Sequence..."); Serial.println("End Reset Sequence...");
USBHS_PORTSC1 &= ~USBHS_PORTSC_PR; USBHS_PORTSC1 &= ~USBHS_PORTSC_PR;
} }
if (count > 5000) {
while (1) ; // stop here
}
} }
void print(const char *s) void print(const char *s)