Hello Álvaro,
I hope you are doing well.
Whenever you change the clock of the MCU, you must wait until the clock signal stabilizes before executing any instruction, otherwise your program will most certainly crash.
You can use the clock Config Tool of MCU Xpresso to select the MCG configuration that you like and apply it to your MCU through the clock SDK driver (fsl_clock.c).
I hope this info comes handy. Do not hesitate to ask about any doubt or concern you have about your application.
Best regards
Javier