I'm trying to get familiar with USBOTG module in Kinetis K60D512 MCU and I'm encountering some issues I'm not sure about.
First I don't understand why there's an USB interrupt signalizing set USBRST right after I enable only this interrupt source before pulling up D+ to signalize attached device.
///******* CLOCK configuration *****************
// Configure USB to be clocked from PLL0
SIM->SOPT2 |= SIM_SOPT2_PLLFLLSEL_MASK |SIM_SOPT2_USBSRC_MASK;
// Configure USB divider to be 2 (SYSCLOCK = 96MHz)
// USBclk = PLLclk × [ (USBFRAC+1) / (USBDIV+1) ]
SIM->CLKDIV2 = SIM_CLKDIV2_USBDIV(1);
// Enable USB-OTG IP clocking
SIM->SCGC4 |= SIM_SCGC4_USBOTG_MASK;
///********* USB configuration **********
// Enable interrupts
NVIC_EnableIRQ(USB0_IRQn);
// Configure enable USB regulator for device
SIM->SOPT1 |= SIM_SOPT1_USBREGEN_MASK;
// enable USB module
USB0->CTL |= USB_CTL_USBENSOFEN_MASK;
// Module reset
USB0->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
// set BDT address
USB0->BDTPAGE1 = (uint8_t) ((uint32_t)&bdt >> 8);
USB0->BDTPAGE2 = (uint8_t) ((uint32_t)&bdt >> 16);
USB0->BDTPAGE3 = (uint8_t) ((uint32_t)&bdt >> 24);
// enable control of pullups
USB0->OTGCTL |= USB_OTGCTL_OTGEN_MASK;
// enable weak pull-downs and turn on transceiver
USB0->USBCTRL |= USB_USBCTRL_PDE_MASK;
USB0->USBCTRL &= ~USB_USBCTRL_SUSP_MASK;
// clear all USB ISR flags
USB0->ISTAT = 0xFF;
// enable USB RESET interrupt
USB0->INTEN |= USB_INTEN_USBRSTEN_MASK;
/// !!!! This chunk is executed from an interrupt handler for a button:
// signalize attached device
USB0->CONTROL |= USB_CONTROL_DPPULLUPNONOTG_MASK;
USB0->OTGCTL |= USB_OTGCTL_DPHIGH_MASK;
Is there any documentation on the USB controller used in this kinetis I'm using? The reference manual isn't very comprehensive and I think some things would really deserve more information. USB Stack examples really doesn't cover this too.
Thanks a lot for any help.