Hi, Derek,
Thanks for your comments and supports on different topics.
The USBH_Mouse.eww is empty, so I use Project | Add exist projects... command to import USBH_Mouse.ewp into workspace.
I changed L2K.c::pll_init()
/* First FEI must transition to FBE mode */
//MCG_C2 = MCG_C2_RANGE0(2) | MCG_C2_HGO0_MASK | MCG_C2_EREFS0_MASK | MCG_C2_IRCS_MASK;
MCG_C2 = (MCG_C2_LOCRE0_MASK | MCG_C2_RANGE0(1) | MCG_C2_EREFS0_MASK);
The USBH_mouse can be built, with same result of KL25Z_SC release.
Furthermore, I met anther strange issue. The code can not run in full speed, with or without debugger, it can only be used with step into command.
Load code, launch debugger, reset.
When press "go", it automatically stops at __iar_program_start: (addr, 0x4c50, instruct: 0x46c0)
When press "step over", it steps over _bsp_platform_init(), and stops at __iar_program_start: (addr, 0x4c50, instruct: 0x46c0)
When press "step into", it steps into each functions, if clock is setup, it can run in full speed then, the mouse LED keeps flashing by USB RESET.
Then I narrow down the issue into pll_init(), I found if I step into pll_init() function, it passed and never return to startup code, if I step over pll_init(), it will be reset to startup code, interesting but not good!
Conclusion: The pll_init() function is quite critical, since MCG registers have to be setup according to some procedure, first to FBE, then bala bala....
I also found two blue flags beside _bsp_platform_init() function in EWARM, however I have no idea about it, it isn't a red-dot breakpoints indicator.
I have checked hardware differences between FRDM and TWR boards. They are USB port (VBUS), UART pinout, slightly different on crystal but same 8MHz external clock. Other peripherals like infrared and etc are not important.
I started to doubt if the code has been fully tested in TWR board as well.
Anyway I will sit back and study documentation regarding Freescale USB stack and try to debug khci module.