cancel
Showing results for 
Search instead for 
Did you mean: 

Writing Interrupt Handlers

dimax
Senior
Posted on December 13, 2012 at 13:00

Hi,

I wonder if C compiler has to know that the given function is an interrupt handler. Looking at the sample code I see not pragmas or any other ways to tell compiler about it. From the other side as far as I could understand Cortex-M3 documentation Interrupt Controller does not save all registers in stack before call to IRQ handler so it is not clear to me how damaging of other not saved registers is prevented?

Thanks.

 
5 REPLIES 5
Andrew Neil
Evangelist II
Posted on December 13, 2012 at 13:52

''I wonder if C compiler has to know that the given function is an interrupt handler''

 

No. That is one of the specific design features of the ARM Cortex-M architecture.

eg,

http://www.arm.com/files/pdf/CortexM3_Uni_Intro.pdf

 - see foot of p5

''Looking at the sample code I see not pragmas or any other ways to tell compiler about it''

Correct.

''Interrupt Controller does not save all registers in stack before call to IRQ handler so it is not clear to me how damaging of other not saved registers is prevented?''

 

The Interrupt Controller saves only enough registers so that the Compiler doesn't have to save any extra registers in addition to what it does for all functions.

sdobrets
Associate
Posted on April 08, 2014 at 13:50

You can't name your interrupt handler function arbitrarily (though the content of the function is up to you, of course). There's only a  fixed set of interrupts acquired by the processor with their names being preset. You have to call interrupt handler function in accordance with the interrupt it has to handle, e.g. void TIM1_UP_TIM10_IRQHandler(void)    for the function treating TIM10 update event. The names  available are listed in 'stm32f4xx.c ' file.

Posted on April 08, 2014 at 15:20

You can't name your interrupt handler function arbitrarily..

You could if you really wanted too. The names stored via the vector table are in startup_stm32fxx.s

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jpeacock2399
Associate II
Posted on April 08, 2014 at 15:41

Interrupt handler names are purely arbitrary in the sense that there are pre-defined names in the untime startup routines from ST and CMSIS.  But there's one good reason to change the names in the startup file and that's when a reentrant interrupt handler is used for multiple units of the same peripheral, for instance USART, SPI, CAN, I2C, as well as DMA and timers.  I use reentrant handlers frequently so I have a heavily modified runtime startup.

  Jack Peacock
Andrew Neil
Evangelist II
Posted on April 08, 2014 at 20:29

''You can't name your interrupt handler function arbitrarily''

Oh Yes You

Can

!

The names are entirely irrelevant as far as the chip is concerned - it neither knows nor cares anything of them.

The names are entirely arbitrary to as far as the compiler is concerned.

The restriction only comes if you want to be compatible with some existing source code - such as the  'stm32f4xx.c ' file provided by ST. But the names used there are entirely arbitrary.