Hi
This is probably the watchdog.
When debugging make sure that you disable the watchdog otherwise it will reset the device after a few seconds when stepping code and cause strange things to happen with the debugger.
Check the macro for your target (in app_hw_kinetis.h)
eg.
#define WATCHDOG_DISABLE() (!_READ_PORT_MASK(E, SWITCH_2)) // pull this input down to disable watchdog (hold switch 2 at reset)
There is usually an input that can be help in a particular state to disable the watchdog when debugging. Otherwise set to 1 so that it is always disabled.
Be careful if you use a device with backup watchdog timer [#define BACKUP_WATCHDOG_TIMER] (rather than core watchdog) since this watchdog continues to run after a reset. To stop it after it has once been configured a power cycle is required.
Regards
Mark