After searching for USB0_IRQHandler I found a topic with identical observation MK2251212_features.h error? USB IRQ Location? , despite the fact that mr Donald Bosley was using DMA and some USB functionalities and I am not.
In my case after thorough debugging session I managed to find that not necessarily
cmd_get_datetime();
is causing trouble.
The first line causing problems is the call to
hardware_init();
which has the following body:
void hardware_init(void) {
/* enable clock for PORTs */
CLOCK_SYS_EnablePortClock(PORTA_IDX);//This line does NOT cause error
CLOCK_SYS_EnablePortClock(PORTC_IDX);//This line does NOT cause error
CLOCK_SYS_EnablePortClock(PORTD_IDX);//This line does NOT cause error
/* Init board clock */
BOARD_ClockInit();//These DO
dbg_uart_init();//These DO
}
and the BOARD_ClockInit(); and dbg_uart_init() are the lines causing the jump to the Default interrupt, leading to an infinite loop.
My guess is that the ISR vector table is somehow wrong. Am I right? If yes - how to fix it?
NOTE: I do not use UART (it seems that the error is connected with it)

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EDIT: I found this in SDK FAQ:
I’m trying to use a driver and keep falling into the default ISR in startup_<mcu>.s
Make sure to include an interrupt handler for the peripheral you’re using inside your project. By default, all the peripheral IRQ handlers go into a default handler that does an infinite branch. The easiest way to fix this issue is to add the C:\Freescale\KSDK_1.2.0\platform\drivers\src\<drivername>\fsl_<drivername>_irq.c file inside your project.
I placed fsl_rtc_irq.c in my Project folder, however this did not change the behaviour. Application is still jumping to infinite Default IRQ. What am I doing wrong?
EDIT2:
Relocating vectors to RAM
from "Interrupt_handling_KSDK.pdf" also did not help. Program still goes to USB0_IRQHandler.
Maybe I should add some of the Cross ARM C Linker -> Miscellaneous -> Other linker flags from the working SDK RTC example?
They are as follows:
-Xlinker -z -Xlinker muldefs --specs=nano.specs -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -Os -mapcs -Xlinker -static -Xlinker --defsym=__stack_size__=0x2000 -Xlinker --defsym=__heap_size__=0x2000
^ I have checked them, and with this linker flags the project does not compile.
After performing the steps from Edit1 and Edit2 the program again "crashes" with the call to cmd_get_datetime()
hardware_init(); does not cause the jump to Default ISR now.