| uint32_t periodictable[64] __attribute__ ((aligned(4096), used)); | uint32_t periodictable[64] __attribute__ ((aligned(4096), used)); | ||||
| uint32_t qh[12] __attribute__ ((aligned(64))); | |||||
| volatile uint32_t qh[12] __attribute__ ((aligned(64))); | |||||
| uint32_t qtd_dummy[8] __attribute__ ((aligned(32))); | |||||
| uint32_t qtd_setup[8] __attribute__ ((aligned(32))); | uint32_t qtd_setup[8] __attribute__ ((aligned(32))); | ||||
| uint32_t qtd_in[8] __attribute__ ((aligned(32))); | uint32_t qtd_in[8] __attribute__ ((aligned(32))); | ||||
| uint32_t qtd_outack[8] __attribute__ ((aligned(32))); | uint32_t qtd_outack[8] __attribute__ ((aligned(32))); | ||||
| uint32_t setupbuf[2] __attribute__ ((aligned(8))); | |||||
| uint32_t inbuf[16] __attribute__ ((aligned(64))); | |||||
| void setup() | void setup() | ||||
| qh[0] = ((uint32_t)qh) | 2; | qh[0] = ((uint32_t)qh) | 2; | ||||
| qh[1] = 0x0040E000; // addr=0, ep=0 | qh[1] = 0x0040E000; // addr=0, ep=0 | ||||
| qh[2] = 0x40000000; | qh[2] = 0x40000000; | ||||
| qh[3] = (uint32_t)qtd_setup; | |||||
| qh[3] = 0; | |||||
| qh[4] = 1; | qh[4] = 1; | ||||
| qh[5] = 0; | |||||
| qh[6] = 0; | |||||
| qh[5] = 1; | |||||
| qh[6] = 0x40; | |||||
| qh[7] = 0; | qh[7] = 0; | ||||
| qh[8] = 0; | qh[8] = 0; | ||||
| qh[9] = 0; | qh[9] = 0; | ||||
| qh[10] = 0; | qh[10] = 0; | ||||
| qh[11] = 0; | qh[11] = 0; | ||||
| qtd_setup[0] = 1; | |||||
| qtd_setup[1] = 1; | |||||
| qtd_setup[2] = 0; // 0 = not active | |||||
| qtd_setup[3] = 0; | |||||
| qtd_setup[4] = 0; | |||||
| qtd_setup[5] = 0; | |||||
| qtd_setup[6] = 0; | |||||
| qtd_setup[7] = 0; | |||||
| qtd_dummy[0] = 1; | |||||
| qtd_dummy[1] = 1; | |||||
| qtd_dummy[2] = 0x40; // 0x40 = halted | |||||
| qtd_dummy[3] = 0; | |||||
| qtd_dummy[4] = 0; | |||||
| qtd_dummy[5] = 0; | |||||
| qtd_dummy[6] = 0; | |||||
| qtd_dummy[7] = 0; | |||||
| // 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_ASYNCLISTADDR = (uint32_t)qh; | USBHS_ASYNCLISTADDR = (uint32_t)qh; | ||||
| USBHS_USBCMD = USBHS_USBCMD_ITC(0) | USBHS_USBCMD_RS | USBHS_USBCMD_ASP(3) | | 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_USBCMD_ASE; | |||||
| // USBHS_USBCMD_PSE | | |||||
| USBHS_USBCMD_ASE; | |||||
| USBHS_PORTSC1 |= USBHS_PORTSC_PP; | USBHS_PORTSC1 |= USBHS_PORTSC_PP; | ||||
| //USBHS_PORTSC1 |= USBHS_PORTSC_PFSC; // force 12 Mbit/sec | //USBHS_PORTSC1 |= USBHS_PORTSC_PFSC; // force 12 Mbit/sec | ||||
| //USBHS_PORTSC1 |= USBHS_PORTSC_PHCD; // phy off | //USBHS_PORTSC1 |= USBHS_PORTSC_PHCD; // phy off | ||||
| } | } | ||||
| void read_descriptor(uint16_t value, uint16_t index, uint32_t len) | |||||
| { | |||||
| uint32_t token; | |||||
| if (len > 512) len = 512; | |||||
| Serial.println("Read Device Descriptor..."); | |||||
| qtd_setup[0] = (uint32_t)qtd_in; | |||||
| qtd_setup[1] = 1; | |||||
| qtd_setup[2] = 0x00080E80; | |||||
| qtd_setup[3] = (uint32_t)setupbuf; | |||||
| setupbuf[0] = (value << 16) | (0x06 << 8) | 0x80; | |||||
| setupbuf[1] = (len << 16) | index; | |||||
| qtd_in[0] = (uint32_t)qtd_outack; | |||||
| qtd_in[1] = 1; | |||||
| qtd_in[2] = 0x80000000 | (len << 16) | 0x0D80; | |||||
| qtd_in[3] = (uint32_t)inbuf; | |||||
| qtd_outack[0] = 1; | |||||
| qtd_outack[1] = 1; | |||||
| qtd_outack[2] = 0x80400C80; | |||||
| qtd_outack[3] = 0; | |||||
| // add to QH | |||||
| // Save the content of the token field of the first qTD to be added | |||||
| token = qtd_setup[2]; | |||||
| // Change the token of the first qTD so its Halted bit is set as 1 | |||||
| // and all other bits are zero | |||||
| qtd_setup[2] = 0x40; | |||||
| // copy the content of the first qTD to the dummy qTD | |||||
| memcpy(qtd_dummy, qtd_setup, 32); | |||||
| // Link the first qTD to the last of the qTD of the newly qTD list | |||||
| qtd_outack[0] = (uint32_t)qtd_setup; | |||||
| // Restore the token value to the previous dummy qTD's oken field | |||||
| qtd_dummy[2] = token; | |||||
| // qtd_setup becomes the dummy token... so this only works once! | |||||
| delay(1); | |||||
| Serial.println(qtd_dummy[2], HEX); | |||||
| Serial.println(qtd_in[2], HEX); | |||||
| Serial.println(qtd_outack[2], HEX); | |||||
| Serial.println(qtd_setup[2], HEX); | |||||
| } | |||||
| void loop() | void loop() | ||||
| { | { | ||||
| static unsigned int count=0; | static unsigned int count=0; | ||||
| Serial.println("End Reset Sequence..."); | Serial.println("End Reset Sequence..."); | ||||
| USBHS_PORTSC1 &= ~USBHS_PORTSC_PR; | USBHS_PORTSC1 &= ~USBHS_PORTSC_PR; | ||||
| } | } | ||||
| if (count == 22) { | |||||
| read_descriptor(1, 0, 8); // device descriptor | |||||
| } | |||||
| if (count > 5000) { | if (count > 5000) { | ||||
| while (1) ; // stop here | while (1) ; // stop here | ||||
| } | } |