Skip to main content
hossein hosseini
Associate III
December 13, 2017
Question

how dose function name connect to interrupt address

  • December 13, 2017
  • 5 replies
  • 1397 views
Posted on December 13, 2017 at 13:20

hi.

i am writing a code for Exti interrupt  and i do that. But i get a qustion .

when we want to use interrupt , I mean when the interrupt happen , then cpu jump to that interrupt address and the function that we write on the IDE will run .

In fact , we write just interrupt name that it name is same with startup function name.

please watch my interrupt code in main:

void EXTI9_5_IRQHandler (void){

 

  GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_SET);

 

  while(1){

   

    if( EXTI_GetITStatus(EXTI_Line7) == SET){

      lcdPutInt(i);

      i++;

      delay_ms(200);

   

      lcdClear();

    }

  }

 

}

and the same name in startup_stm32f10x_hd_vl.s :

DCD EXTI9_5_IRQHandler

PUBWEAK EXTI9_5_IRQHandler

        SECTION .text:CODE:REORDER(1)

EXTI9_5_IRQHandler

        B EXTI9_5_IRQHandler

how does  the function and EXTI9_5_IRQHandler  in startup can connect?

i need some e

xplanation about

communication of this activity.

i use stm32f103re and IAR.

so thanks.

    This topic has been closed for replies.

    5 replies

    waclawek.jan
    Super User
    December 13, 2017
    Posted on December 13, 2017 at 13:38

    The processor expects the interrupt vectors - which are essentially function pointers, telling the processor where to jump when the interrupt occurs - at a fixed address (or in case of Cortex-M3/4/7, at an address given by SCB->VTOR).  That assembly code in startup file is a table of function pointers. The linker fills in the actual position of the interrupt code.

    JW

    AvaTar
    Senior III
    December 13, 2017
    Posted on December 13, 2017 at 13:46

    And to be more precise, the names of the interrupt function(s) must match exactly. This way, the linker makes the assignment.

    The WEAK attribute (or PUBWEAK, as in your Keil asm example) allows exactly two definitions of said symbol.

    One is 'weak', and can be overridden with another symbol - your interrupt handler in this case.

    This is general toolchain (compiler+linker) workings.

    mckenney
    Associate
    December 13, 2017
    Posted on December 13, 2017 at 13:43

    As you guessed, it matches by name, so your code just needs to spell it correctly.

    The key is in the word 'PUBWEAK', particularly the 'WEAK' part. An entry symbol that is defined as 'weak' can be replaced by another (implicitly 'strong') symbol of the same name, so if no one defines

    EXTI9_5_IRQHandler the linker will adopt the 'weak' one

    (in the .s file).

    Be aware that some linkers seem to do this better than others. I use maybe 4-5 different IDEs in a week, and for some I need to explicitly delete the 'weak' stuff to make it work.

    hossein hosseini
    Associate III
    December 15, 2017
    Posted on December 15, 2017 at 10:54

    Thanks all.

    i understand what you mean.

    i want to say that is i dont have startup_stm32f10x_hd_vl.s file , how can i used interrupt ?!! where is address  of registers ?!

    i mean for example i want to write a function with different name ,, and i want to connect this function to a interrupt, how can i do that ? which registers can i use to give it address?

    For example i have user manual , and i saw the RCC register and i modify the registers for set the stm32 clock.i dont need any defines or somthing like that.

    i know that we'll probably use this way , but i want to understand what  is happening in code that this event occur.

    so thanks.

    AvaTar
    Senior III
    December 15, 2017
    Posted on December 15, 2017 at 11:16

    I think you need to consult the IAR Workbench documentation.

    IAR has it's own startup files and naming conventions, as far as I remember, something like

    xxx_cstartup_iar.s

    .

    The 'weak' default handlers are either declared there, or included.