9 years, 9 months ago.

K64F USB Host IRQ Interrupt Not Triggering

Hello,

So, I am trying to get the K64F to act as a USB Host to an external USB device. I am using the library "F401RE-USBHost" as a starting point.

I've seem to isolate the issue when setting up the USB IRQ Callback. It never gets called when I am unplugging/replugging in devices.

I believe it has to do something with this bit of code:

K64F Setting up as USB Host

    // Disable IRQ
    NVIC_DisableIRQ(USB0_IRQn);
    
#if defined(TARGET_K64F)
    MPU->CESR=0;
#endif

    // choose usb src as PLL
    SIM->SOPT2 |= (SIM_SOPT2_USBSRC_MASK | SIM_SOPT2_PLLFLLSEL_MASK);
    
    // enable OTG clock
    SIM->SCGC4 |= SIM_SCGC4_USBOTG_MASK;

    // USB Module Configuration
    // Reset USB Module
    USB0->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
    while(USB0->USBTRC0 & USB_USBTRC0_USBRESET_MASK);

    // Clear interrupt flag
    USB0->ISTAT = 0xff;

    // Set BDT Base Register
    USB0->BDTPAGE1=(uint8_t)((uint32_t)bdt>>8);
    USB0->BDTPAGE2=(uint8_t)((uint32_t)bdt>>16);
    USB0->BDTPAGE3=(uint8_t)((uint32_t)bdt>>24);

    // Set SOF threshold
    USB0->SOFTHLD = USB_SOFTHLD_CNT(1);

    // pulldown D+ and D-
    USB0->USBCTRL = USB_USBCTRL_PDE_MASK;

    USB0->USBTRC0 |= 0x40;

    // Host mode
    USB0->CTL |= USB_CTL_HOSTMODEEN_MASK;
    // Desable SOF packet generation
    USB0->CTL &= ~USB_CTL_USBENSOFEN_MASK;

    NVIC_SetVector(USB0_IRQn, (uint32_t)&_usbisr);
    NVIC_EnableIRQ(USB0_IRQn);
	
	USB0->INTEN = USB_INTEN_ATTACHEN_MASK;
	//(waiting here for the callback)

I have 2 questions....

1. Does anything seem wrong in the code above for the K64F acting as a USB Host?

2. I'm new to this world, my background is software development, where would I figure out what all these specific defines mean? For example, is there any documentation that says explicitly what "USB_USBCTRL_PDE_MASK" does? Besides reading the comment, where am I suppose to find some of this information? It may help me understand what's going on.

Thanks in advance.

I'm trying to get this to work too. I noticed that if I use r89 of the mbed libraries instead of r90 through r94, the interrupts occur as expected.

posted by Glen Akins 01 Mar 2015

Hi Jeff and Glen, have you finally managed to make this code work ? Was it a simple matter of mbed library version or have you made some changes in the initial code ?

posted by Abraham Brolh 03 Nov 2016

1 Answer

9 years, 9 months ago.

2 I can answer, you need the reference manual for that: http://cache.freescale.com/files/microcontrollers/doc/ref_manual/K64P144M120SF5RM.pdf. That register is found on page 1312. The _MASK defines are bitmasks, (in this case it is equal to (1<<6)), it is defined somewhere in the source code, but it simply refers to the PDE bit, which is:

Enables the weak pulldowns on the USB transceiver.
0 Weak pulldowns are disabled on D+ and D–.
1 Weak pulldowns are enabled on D+ and D–.

Accepted Answer

Erik,

Thanks! That's exactly what I needed. Now I can intelligently start figuring this out.

posted by Jeff King 16 Feb 2015