#4 was switching from the Processor Expert version of the stack (which doesn't support delayed processing) to the full version and not getting the USB clock initialization right.
#5 was trying to access a USB register before the peripheral clock gate was enabled.
Here's my init now, for a 120 MHz PLL (taken from the PE init):
void usb_init(void)
{
SIM_SOPT2 |= SIM_SOPT2_USBSRC_MASK; /* Divided PllFll clock */
SIM_CLKDIV2 = (uint32_t)((SIM_CLKDIV2 & (uint32_t)~(uint32_t)(
SIM_CLKDIV2_USBDIV(0x03)
)) | (uint32_t)(
SIM_CLKDIV2_USBDIV(0x04) |
SIM_CLKDIV2_USBFRAC_MASK
)); /* Div=5 - Mult=2 */
/* Enable module clock */
/* SIM_SCGC4: USBOTG=1 */
SIM_SCGC4 |= SIM_SCGC4_USBOTG_MASK;
/* Reset module */
/* USB0_USBTRC0: USBRESET=1 */
USB0_USBTRC0 = USB_USBTRC0_USBRESET_MASK; /* Reset module */
while (USB_PDD_GetModuleResetPendingFlag(USB0_BASE_PTR)) {
; /* Wait for reset done */
}
/* Enable USB voltage regulator */
/* SIM_SOPT1: ??=1 */
SIM_SOPT1 |= 0x80U; /* Enable USB voltage regulator */
/* USB0_USBTRC0: ??=1 */
USB0_USBTRC0 = 0x40U; /* Enable internal pull-up */
/* USB0_USBCTRL: SUSP=1 */
USB0_USBCTRL = (USB_USBCTRL_SUSP_MASK | USB_USBCTRL_PDE_MASK); /* Disable weak pull-downs and suspend transceiver */
/* USB0_OTGCTL: DPHIGH=0,??=0,DPLOW=0,DMLOW=0,??=0,OTGEN=1,??=0,??=0 */
USB0_OTGCTL = USB_OTGCTL_OTGEN_MASK;
// BDTPAGE set in DCI
}
And from the PE CPU init, here's the MPU and AXBS setup:
/* SIM_SCGC7: MPU=1 */
SIM_SCGC7 |= SIM_SCGC7_MPU_MASK;
/* Initialization of the MPU module */
/* MPU_CESR: SPERR=0,VLD=0 */
MPU_CESR &= (uint32_t)~(uint32_t)((MPU_CESR_SPERR(0x1F) | MPU_CESR_VLD_MASK));
/* Initialization of the AXBS module */
/* AXBS_PRS0: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,M5=4,??=0,M4=3,??=0,??=0,??=0,??=0,??=0,M2=2,??=0,M1=1,??=0,M0=0 */
AXBS_PRS0 = AXBS_PRS_M5(0x04) |
AXBS_PRS_M4(0x03) |
AXBS_PRS_M2(0x02) |
AXBS_PRS_M1(0x01) |
AXBS_PRS_M0(0x00);
/* AXBS_PRS1: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,M5=4,??=0,M4=3,??=0,??=0,??=0,??=0,??=0,M2=2,??=0,M1=1,??=0,M0=0 */
AXBS_PRS1 = AXBS_PRS_M5(0x04) |
AXBS_PRS_M4(0x03) |
AXBS_PRS_M2(0x02) |
AXBS_PRS_M1(0x01) |
AXBS_PRS_M0(0x00);
/* AXBS_PRS2: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,M5=4,??=0,M4=3,??=0,??=0,??=0,??=0,??=0,M2=2,??=0,M1=1,??=0,M0=0 */
AXBS_PRS2 = AXBS_PRS_M5(0x04) |
AXBS_PRS_M4(0x03) |
AXBS_PRS_M2(0x02) |
AXBS_PRS_M1(0x01) |
AXBS_PRS_M0(0x00);
/* AXBS_PRS3: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,M5=4,??=0,M4=3,??=0,??=0,??=0,??=0,??=0,M2=2,??=0,M1=1,??=0,M0=0 */
AXBS_PRS3 = AXBS_PRS_M5(0x04) |
AXBS_PRS_M4(0x03) |
AXBS_PRS_M2(0x02) |
AXBS_PRS_M1(0x01) |
AXBS_PRS_M0(0x00);
/* AXBS_PRS4: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,M5=4,??=0,M4=3,??=0,??=0,??=0,??=0,??=0,M2=2,??=0,M1=1,??=0,M0=0 */
AXBS_PRS4 = AXBS_PRS_M5(0x04) |
AXBS_PRS_M4(0x03) |
AXBS_PRS_M2(0x02) |
AXBS_PRS_M1(0x01) |
AXBS_PRS_M0(0x00);
/* AXBS_CRS0: RO=0,HLP=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,ARB=0,??=0,??=0,PCTL=0,??=0,PARK=0 */
AXBS_CRS0 = (AXBS_CRS_ARB(0x00) | AXBS_CRS_PCTL(0x00) | AXBS_CRS_PARK(0x00));
/* AXBS_CRS1: RO=0,HLP=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,ARB=0,??=0,??=0,PCTL=0,??=0,PARK=0 */
AXBS_CRS1 = (AXBS_CRS_ARB(0x00) | AXBS_CRS_PCTL(0x00) | AXBS_CRS_PARK(0x00));
/* AXBS_CRS2: RO=0,HLP=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,ARB=0,??=0,??=0,PCTL=0,??=0,PARK=0 */
AXBS_CRS2 = (AXBS_CRS_ARB(0x00) | AXBS_CRS_PCTL(0x00) | AXBS_CRS_PARK(0x00));
/* AXBS_CRS3: RO=0,HLP=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,ARB=0,??=0,??=0,PCTL=0,??=0,PARK=0 */
AXBS_CRS3 = (AXBS_CRS_ARB(0x00) | AXBS_CRS_PCTL(0x00) | AXBS_CRS_PARK(0x00));
/* AXBS_CRS4: RO=0,HLP=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,ARB=0,??=0,??=0,PCTL=0,??=0,PARK=0 */
AXBS_CRS4 = (AXBS_CRS_ARB(0x00) | AXBS_CRS_PCTL(0x00) | AXBS_CRS_PARK(0x00));
/* AXBS_MGPCR0: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,AULB=0 */
AXBS_MGPCR0 = AXBS_MGPCR0_AULB(0x00);
/* AXBS_MGPCR1: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,AULB=0 */
AXBS_MGPCR1 = AXBS_MGPCR1_AULB(0x00);
/* AXBS_MGPCR2: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,AULB=0 */
AXBS_MGPCR2 = AXBS_MGPCR2_AULB(0x00);
/* AXBS_MGPCR4: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,AULB=0 */
AXBS_MGPCR4 = AXBS_MGPCR4_AULB(0x00);