Cortex-M4 setup vector table for external interrupts

I don't want to setup the vector table for all my external interrupts. For instance I only need the timer4 IRQhandler at IRQn 30. How can I make an offset in the table? Is this necessary?

Parents Reply Children
  • yasuhikokoumoto very much appreciated. I forgot about the .ALIGN 7. Great.

  • yasuhikokoumoto Hi, can you explain me the .align 7. I know .align 4 align to a word boundary.

  • The .align directive is a bit 'unnatural' and very confusing.

    in fact, it is based upon the power of two, and it's one directive, which I would like to change the rules for, if I could.

    But it is what it is, and it's too late to change it, because it's been like this for more than 15 years already.

    To give you a visual overview:

              .align              /* aligns to the default alignment for your architecture */

              .align    1         /* aligns to the next 16-bit boundary (halfword, 2-byte) */

              .align    2         /* aligns to the next 32-bit boundary (word, 4-byte) */

              .align    3         /* aligns to the next 64-bit boundary (double-word, 8-byte) */

              .align    4         /* aligns to the next 128-bit boundary (quad-word, 16-byte) */

              .align    5         /* aligns to the next 256-bit boundary (octa-word, 32-byte) */

              .align    6         /* aligns to the next 512-bit boundary (hexa-word, 64-byte) */

              .align    7         /* aligns to the next 1024-bit boundary (well, eh, 128-byte) */

    ... and so on.

    You can calculate the alignment by (1 << n) ... or if your calculator can handle it: 2 ^ n.

  • Hi jvanmont,

    I checked the STM32F42xx Reference Manual (http://www.st.com/st-web-ui/static/active/jp/resource/technical/document/reference_manual/DM00031020.pdf) and confirmed the timer4 interrupt is assigned to IRQ30. Do you want to know how to write the original startup.s? If it is so, please refer to the post "Writing your own startup code for Cortex-M" (Writing your own startup code for Cortex-M). I extracted the essential part from the post and added the new vector entry of the timer4 handler.

    ----[snip]-----

    .align  2

    .long  _stack/* 0x00000000 The initial stack pointer (defined by the linker-script) */

    .long  Reset_Handler   /* 0x00000004 */

    .long  NMI_Handler   /* 0x00000008 */

    .long  HardFault_Handler/* 0x0000000c */

    .long  MemManage_Handler/* 0x00000010 */

    .long  BusFault_Handler /* 0x00000014 */

    .long  UsageFault_Handler/* 0x00000018 */

    .long  0     /* 0x0000001c */

    .long  0     /* 0x00000020 */

    .long  0     /* 0x00000024 */

    .long  0     /* 0x00000028 */

    .long  SVC_Handler   /* 0x0000002c */

    .long  DebugMon_Handler /* 0x00000030 */

    .long  0     /* 0x00000034 */

    .long  PendSV_Handler   /* 0x00000038 */

    .long  SysTick_Handler  /* 0x0000003c */

    /*  .long      ..._IRQHandler */

    /* 0x00000040 and forward. IRQ vectors specific to your microcontroller follows here... */

    .align 7 /* 0x00000080 */

    .space 0x38 /* 0x000000B8 */

    .long tim4_IRQHandler

      .text  /* Put everything in the text-section from now on... */

      .align  /* Make sure address is aligned for code output */

    ----[snip]-----

    Best regards,

    Yasuhiko Koumoto.

  • Hi jvanmont,

    there are two ways to specify the 'align parameter'. One is to specify a direct byte boundary and another is to specify a boundary by the power of two. GCC (GNU-assembler) adopts the latter way. Regarding ALIGN 7, please refer to the jensbauer's explanations.


    Best regards,
    Yasuhiko Koumoto.