Thanks for your input guys.
The specific device in use is MK22FN128VLH10 - but the problem seems to be identical on all devices, where flash-write can't be done in HSRUN mode.
The USB should be running on the IRC48 MHz, the USB-clock is init'ed using;
CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcIrc48M, 48000000U);
Running the MCU at full speed in RUN-mode might work, but as we're running the MCU near it's temperature-limit, it's not something I would be comfortable doing in general.
I did some more debugging with your comments in mind and found that;
- The USB problem problem is caused by calling CLOCK_SetSimConfig
- The function CLOCK_SetSimConfig calls SIM-CLKDIV1, CLOCK_SetEr32kClock and CLOCK_SetPllFllSelClock
- The function causing problems, is CLOCK_SetPllFllSelClock.
- For the fun of it, I tried changing to RUN mode when doing a flash-write (without actually changing clock-speed) causes a hardfault (VECTTBL - indicates a BusFault on a vector table)
In my case, the attached functions to change between HSRUN and RUN-mode seems to work and solves my USB-problem. Only CLKDIV1 is changed, as the other clocks are within RUN-mode specs