I have an issue with making usb_stack working on my MCU.
I am using kinetis K22FN1M MCU. The PCB is made by myself. I have used the usb_core code from kinetis SDK and eveyrhing seems to be ok.
I am trying to create an MSD class device.
I was trying to do some debugging and I found out that after the line USB_CLK_RECOVER_IRC_EN=0x3 (device init stage) the MCU goes into HardFault interrupt. So, the stack does not working. If I try to comment the line mention above then the device initializes, but of course does not work as it should (even though windows detects a new device on the bus). Are there any ideas what to do? I suspect that there is some issues with clocks....
Second issue may be somehow connected, I found out that during startup MCU does not want to switch to HSRUN mode. It remains in RUN mode.
I found out that PMPROT is 0x2A. I was trying to change it to 0xAA but it cannot be changed... remains 0x2A. So, in startup file I had to comment this functionality because otherwise MCU will be in infinite loop waiting for MCU to go to HSRUN. How to fix the PMPROT register to be able to write there?
Waiting for any help.