This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STR91x interrupt handling problem

Dear Colleagues,

Here's my source code:

#include <91x_lib.h>
#include "masodik.h"

unsigned char gpio7_out = 0;

int main()
{
        GPIO_InitTypeDef GPIO_InitStruct;
        TIM_InitTypeDef TIM_InitStructure;

        GPIO_DeInit(GPIO7);
         GPIO_InitStruct.GPIO_Direction = GPIO_PinOutput;
         GPIO_InitStruct.GPIO_Pin = GPIO_Pin_All;
         GPIO_InitStruct.GPIO_Type = GPIO_Type_PushPull ;
        GPIO_InitStruct.GPIO_Alternate = GPIO_OutputAlt1;
         GPIO_Init (GPIO7, &GPIO_InitStruct);

        TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_2;
        TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;
        TIM_InitStructure.TIM_Prescaler = 0xFF;
        TIM_InitStructure.TIM_OC2_Modes = TIM_WAVE;
        TIM_InitStructure.TIM_Pulse_Level_2 = TIM_HIGH;
        TIM_InitStructure.TIM_Pulse_Length_2 = 0xA000;
        TIM_Init(TIM3, &TIM_InitStructure);
        TIM_ITConfig(TIM3, TIM_IT_OC2, ENABLE);

        VIC_ITCmd(TIM3_ITLine, ENABLE);
        VIC_Config(TIM3_ITLine, VIC_IRQ,0);
        TIM_CounterCmd(TIM3, TIM_CLEAR);
        TIM_CounterCmd(TIM3, TIM_START);

        gpio_out = 0;

        while (1);
}

and my interrupt handler:

void TIM3_IRQHandler(void)
{
   /*write your handler here*/
   /* ... */
  gpio_out ^= 0xAA;
  GPIO_Write(GPIO7, gpio_out);
  TIM_ClearFlag(TIM3, TIM_FLAG_OC2);
  TIM_CounterCmd(TIM3, TIM_CLEAR);
   /*write any value to VIC0 VAR*/
  VIC0->VAR = 0xFF;
  VIC1->VAR = 0xFF;
}

This program should blink every 2nd pin on GPIO7 within the TIM3 interrupt handler.
gpio7_out is a golbal variable.
My problem is that it runs until the 1st interrupt occurs, executes it, and then it gets stuck within an endless loop on the Undefined Handler interrupt.
At that time, the simulator says:
Non-aligned Access: ARM Instruction at 00000298H, Memory Access at 000000F7H
*** error 65: access violation at 0x000000F7 : no 'write' permission

Any ideas where am I going wrong?