Electronic – Cortex M0 – Defining an interrupt routine in assembly

armassemblyinterrupts

For a project I have some code that needs to be written in assembly due to precise timing requirements. I'd ideally like to implement my code in a timer interrupt routine. Right now, in C++ I can define an ISR as such:

extern "C" void TIM3_IRQHandler(void)
{
//code here
}

I'm using an STM32F030 chip, which from the datasheet shows that the Timer3 IRQ address is 0x00000080. My understanding is that there is an address stored at this location that marks the start of the interrupt handler.

How do I change the address at the above entry to point to the start address of my assembly code so that I can handle the interrupt in assembly? I know I can technically put inline assembly within the C function above, but there must be a way to handle the interrupt entirely in assembly.

I should note that I'm using the GNU ARM toolchain

Best Answer

How do I change the address at the above entry to point to the start address of my assembly code so that I can handle the interrupt in assembly?

Asssuming default startup, just declare the function with the correct name in assembler:

.syntax unified
.thumb
.arch armv6m
.text

.global TIM3_IRQHandler
  .thumb_func
TIM3_IRQHandler:
  BX LR
.end

Note: This example will deadlock (read: infinitely tail-chain), since the timer flags are not resetted properly.