Hi
A hard fault in normally inconspicuous code points to a clock (usually the flash clock) being run out of specification.
Therefore if you recall this code it would be a good idea to first set things like clock dividers back to their default values so that there is not the risk of setting up a clock that is directly connected to something that will be overclocked.
Consider the clock speeds at each point in the code that are really being applied to buses and identify whether they may not be connected yet in the program flow if all registers start with their defaults, but are if registers retain the settings after the first operation.
See also this for an overview of the operation, whereby the rules are simply to wait for clocks settings to become stable at each change and avoid any 'connected' clocks being out of specification: https://www.utasker.com/kinetis/MCG.html
Regards
Mark
[uTasker project developer for Kinetis and i.MX RT]
Contact me by personal message or on the uTasker web site to discuss professional training, solutions to problems or product development requirements