Sorry for late answer. Thanks for your suggestion I have read value from CPSR register at first intstruction in reset handler. After I run application from debugger CPSR value is 0x000000d3, but after a suspicious restart CPSR value is: 0x400000d2. This means that microcontroller is in IRQ mode. But how to handle what's make that crash?
Edit:
I have checked at stack pointer. I have found value in [sp - 4] which indicate that last intruction is come from aic handler.
Edit2:
After further tests it seems that irq_handler jump to 0x00000000 memory address.
Code:
ldr r0, =AIC_BASE
ldr r1, [r0, #AIC_IVR_OFFSET]
str r0, [r0, #AIC_IVR_OFFSET]
mov lr, pc
bx r1 //jump to 0x00000000
// Mark end of interrupt
ldr r0, =AIC_BASE // stack pointer [sp - 4] hold this memory address
str r0, [r0, #AIC_EOICR_OFFSET]
R0 = 0xfffff000
R1 = 0x00000000
How to retrieve irq source?
Edit3:
Another update I have read some data register from AIC.
0xFFFFF100 - Interrupt vector register = 0x00000000
0xFFFFF104 - FIQ Interrupt vector register = 0x00000000
0xFFFFF108 - Interrupt status register = 0x00000000
0xFFFFF10C - Interrupt pending register = 0x00002005
0xFFFFF110 - Interrupt mask register = 0x000020c6
AIC_IPR (Interrupt pending register) have set 3 bits (10000000000101)
This mean that is 3 current pending irq:
AT91C_ID_FIQ (uncorrect, I don't use this irq)
AT91C_ID_PIOA (correct)
AT91C_ID_TC1 (correct)
Maybe this is the point.
Edit4:
Finally I found a solution. The problem was in spurious interrupt. Btw. why this interrupt is not handled by default(jump to 0 address is not good idea). I lost one week to resolve this problem.