cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt Problem

ezrab
Associate II
Posted on October 17, 2010 at 11:32

hi i am trying to activate the Tim2 Interrupt but for some reason it does not work here is the program i wrote:

#include ''stm32F10x.h''

void setsystemclock(void);

void TIM2_IRQHandler(void);

int main(void)

{

    setsystemclock(); //set system clock to 24Mhz

    //rcc configuration

   RCC->APB1ENR=RCC_APB1RSTR_TIM2RST;//tim2 enable

    RCC->APB2ENR=RCC_APB2ENR_IOPCEN;//portc Clock enable

    //nvic configuration

     NVIC_EnableIRQ(TIM2_IRQn);

     //GPIO configuration

     GPIOC->CRL=0x33000000;//ports 6,7 as fast output

     GPIOC->CRH=0x33;//ports 8,9 as fast output

  //tim Configuration

     TIM2->ARR=65535;

     TIM2->EGR=TIM_EGR_UG;/*!<Update Generation */

     TIM2->CCMR1=0;

     TIM2->CCR1=40961;

     TIM2->CCER=TIM_CCER_CC1E;  /*!<Capture/Compare 1 output enable */

     TIM2->CCMR1=0;

     TIM2->DIER=TIM_DIER_CC1IE ;/*!<Capture/Compare 1 interrupt enable */

     TIM2->CR1=TIM_CR1_CEN;/*!<Counter enable */

    while(1)

    {

    }

}

void TIM2_IRQHandler(void)

{

  TIM2->SR=~TIM_SR_CC1IF; //Clears the TIMx's interrupt pending bits.

  GPIOC->ODR^=0xC0;

}

void setsystemclock(void)

{

      RCC->CR |= RCC_CR_HSEON;

    // Wait until it's ready

    while ((RCC->CR & RCC_CR_HSERDY) == 0)

        ;

    // Select PREDIV1 as PLL source and sett PLL mul to 3 (set bit 0)

    // for 8*3 = 24 MHz

    RCC->CFGR |= RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL_0;

    // Start PLL

    RCC->CR |= RCC_CR_PLLON;

    // Wait until it's ready

    while ((RCC->CR & RCC_CR_PLLRDY) == 0)

        ;

    // Select PLL as system clock

    RCC->CFGR |= RCC_CFGR_SW_PLL;

    // Here we can check if PLL is used, and maybe disable HSI

    // Disable HSI

    RCC->CR &= ~RCC_CR_HSION;

    RCC->CFGR|=RCC_CFGR_MCO_2; //sys clock output

}

what did i do wrong?

thanks for your help.

i get the following error:

 

BusFault_Handler:

DebugMon_Handler:

HardFault_Handler:

MemManage_Handler:

NMI_Handler<26731 (failed: LoadStrW)>:

    0x800018c: 0xe7fe         B.N       BusFault_Handler        ; 0x800018c

    0x800018e: 0xffff         DC16      65535                   ; '..'

    0x8000190: 0xffffffff     MRC2      p15, #7, pc, c15, c15, #7

    0x8000194: 0xffffffff     MRC2      p15, #7, pc, c15, c15, #7

    0x8000198: 0xffffffff     MRC2      p15, #7, pc, c15, c15, #7

    0x800019c: 0xffffffff     MRC2      p15, #7, pc, c15, c15, #7

    0x80001a0: 0xffffffff     MRC2      p15, #7, pc, c15, c15, #7

    0x80001a4: 0xffffffff     MRC2      p15, #7, pc, c15, c15, #7

18 REPLIES 18
Posted on October 17, 2010 at 14:32

Seems to build and run under Keil uv4.

TIM2 Interrupts periodically

The code enabling the PLL does not properly mask and set bits, and does not wait for the PLL to be selected as the source clock.

Try to determine what address is faulting in your code.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ezrab
Associate II
Posted on October 17, 2010 at 14:35

what should i add for the PLL ?

and how can i determine what address is faulting in my code?

thanks
ezrab
Associate II
Posted on October 17, 2010 at 15:30

and why cant i set breakpoint in void TIM2_IRQHandler(void)?

Posted on October 17, 2010 at 16:08

how can i determine what address is faulting in my code?

Single Step, Trace, Bisection, Instrumentation, or check the fault state the Cortex-M3 pushes onto the stack.

and why cant i set breakpoint in void TIM2_IRQHandler(void)?

Because the tool you are using sucks?

You can't set one, or it's not hitting it?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ezrab
Associate II
Posted on October 17, 2010 at 16:11

i am using IAR Embedded Workbench it says

One or more breakpoints could not be set and have been disabled.

when i run the program with breakpoint already set, and when i try to set it when i ran the program it does not let me.

how can i check the  fault state the Cortex-M3 pushes onto the stack?

thanks

ezrab
Associate II
Posted on October 17, 2010 at 16:14

when i checked the cstack in the tracer i saw the address 0x200003B8 what does it means?

Posted on October 17, 2010 at 19:45

i am using IAR Embedded Workbench it says, One or more breakpoints could not be set and have been disabled.

So the tool does suck, the chip should have 6-8 breakpoints, I don't think the STM32F100 (LV) has a reduced set, but can't find a good cite. The code as presented pretty much pastes into the demo/eval version of Keil uv4 and works as is. And you can breakpoint the interrupt.

how can i check the fault state the Cortex-M3 pushes onto the stack?

Add code to automate it, or just look at the registers, and dump memory regions within the debugger. You are interested in the PC (R15) when it faulted.

https://my.st.com/public/STe2ecommunities/mcu/Lists/ARM%20CortexM3%20STM32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/ARM CortexM3 STM32/HardFault Exception Why oh why!&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000626BE2B829C32145B9EB5739142DC17E&currentviews=2772

when i checked the cstack in the tracer i saw the address 0x200003B8 what does it means?

The stack is in RAM, you could view it in the debugger. Depending on how it faulted either the system or user stack will contain the fault data.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ezrab
Associate II
Posted on October 18, 2010 at 08:44

this is the value of PC 0x08000190 what does it means?

maybe the name of the interrupt routine is not ''void TIM2_IRQHandler(void)'' in IAR ?

ezrab
Associate II
Posted on October 18, 2010 at 08:58

i used the hard fault function and the PC now is 0x0800017A.