Skip to main content
Visitor II
March 14, 2018
Solved

STM32F4 Init Vector Table

  • March 14, 2018
  • 4 replies
  • 11004 views
Posted on March 14, 2018 at 01:06

Hi, I'm following a TI tutorial where the author is creating a Init Vector to determine which exception and interrupts are able to that program...

He's basically creating an array of pointers to int and pass function pointers.

I know that the microcontroller in that TI board is the same than the STM32F4 (Arm cortex M4).

I did a overview of the manual and I couldn't figure out how to set your own Vector.

Here you call it Interrupt Vector but, it's equal to their Init Vector...

The memory of this vector starts at 0x0000.

I just need some guidance or example to set this vector in my STM32F4

Thanks in advance.

#stm32f4
    This topic has been closed for replies.
    Best answer by Andrew Neil
    Posted on March 14, 2018 at 19:34

    For basic getting-started tips, see:

    https://community.st.com/0D50X00009XkWm7SAF

    4 replies

    ST Employee
    March 14, 2018
    Posted on March 14, 2018 at 09:43

    The Vector Table is located by default in 0x0 (aliased at flash start 0x08000000) and there is where the linker places all exception handler addresses (which include interrupts). So, if your build system setup is ok, Vector Table should already be in 0x0.

    If you want to change the Vector Table location, for example because you want to place it in RAM so you can set exception addresses dynamically, you will need to use the VTOR register.

    See 'Exception Model' section 2.3 in 

    http://www.st.com/content/ccc/resource/technical/document/programming_manual/6c/3a/cb/e7/e4/ea/44/9b/DM00046982.pdf/files/DM00046982.pdf/jcr:content/translations/en.DM00046982.pdf

     for all the details.
    Super User
    March 14, 2018
    Posted on March 14, 2018 at 11:06

    It's not clear what you're asking - do you just want to create your own ISRs, or are you (as

    siorpaes.david

    ‌ described) trying to change the location of the vector table.

    I just need some guidance or example to set this vector in my STM32

    This is in every single example from ST:

    The ST-provided startup code provides default handlers for each and every available interrupt vector.

    These are defined with the 'weak' attribute. This means that all you have to do is to provide a function with the exact same name - and it will override the default, and automatically be populated in the vector table.

    eg, from startup_stm32l072xx.s:

    Default_Handler PROC

    EXPORT WWDG_IRQHandler [WEAK]

    EXPORT PVD_IRQHandler [WEAK]

    EXPORT RTC_IRQHandler [WEAK]

    EXPORT FLASH_IRQHandler [WEAK]

    EXPORT RCC_IRQHandler [WEAK]

    EXPORT EXTI0_1_IRQHandler [WEAK]

    EXPORT EXTI2_3_IRQHandler [WEAK]

    EXPORT EXTI4_15_IRQHandler [WEAK]

    EXPORT DMA1_Channel1_IRQHandler [WEAK]

    EXPORT DMA1_Channel2_3_IRQHandler [WEAK]

    EXPORT DMA1_Channel4_5_6_7_IRQHandler [WEAK]

    EXPORT ADC1_COMP_IRQHandler [WEAK]

    EXPORT LPTIM1_IRQHandler [WEAK]

    EXPORT TIM2_IRQHandler [WEAK]

    EXPORT TIM21_IRQHandler [WEAK]

    EXPORT I2C1_IRQHandler [WEAK]

    EXPORT SPI1_IRQHandler [WEAK]

    EXPORT USART2_IRQHandler [WEAK]

    EXPORT LPUART1_IRQHandler [WEAK]

    So, to write your own handler for the LPUART1 IRQ, you just need to call itLPUART1_IRQHandler()

    Visitor II
    March 14, 2018
    Posted on March 14, 2018 at 17:45

    Thank David and Andrew for your fast response,

    Indeed, I don't want to change the Vector Table location, so rather than that I would like to define my own handlers.

    The question is:  if I need to create a C array to define all the function pointers or just define those function in my source code?

    Default_Handler PROC

    EXPORT WWDG_IRQHandler                [WEAK]

    EXPORT EXTI2_3_IRQHandler             [WEAK]

    Can I use something like this, if the previous answer is an array?

    const int __vector_table[] ={

            Default_Handler PROC

            EXPORT WWDG_IRQHandler [WEAK]

    };

    Here Default_Handler PROC is not a type neither WWDG_IRQHandler. I tried to compile but of course it failed.

    Kind Regards

    Super User
    March 14, 2018
    Posted on March 14, 2018 at 18:03

    Carlos Hernandez wrote:

    The question is:  if I need to create a C array

    No, you don't.

    As noted previously, this is all done for you in the startup code - the only thing you need to do is to give your ISRs the correct names.

    Super User
    March 14, 2018
    Posted on March 14, 2018 at 19:34

    For basic getting-started tips, see:

    https://community.st.com/0D50X00009XkWm7SAF

    Visitor II
    March 14, 2018
    Posted on March 14, 2018 at 20:25

    Thanks Neil!

    Explorer
    December 23, 2023

    Hello Carlos,

     

    I'm very new to MC dev myself and I've just start working on them. I suspect you were following Miro Samek tutorial. I'm following that myself. I want to override the default interrupt handler for SysTICK interrupt.  This is what i could find in start up code in startup_stm32f401xx.s:

     

    PUBWEAK SysTick_Handler
    SECTION .text:CODE:REORDER:NOROOT(1)
    SysTick_Handler
    B SysTick_Handler

    How and where do I override this handler to do my own defined activities (such as glowing an LED) when ISR is hit?

    I am using an STM32F410RE on a nucleo board

     

    . @Andrew Neil @Carlos Hernandez @David SIORPAES . Would really appreciate some help on this.

    Super User
    January 10, 2024

    The key is in the "weak" in "PUBWEAK"

    The "weak" means, "here is a definition of this symbol, but  any other definition will override it"

    So all you have to do is to provide your own definition of SysTick_Handler; ie, just define a function with the name SysTick_Handler.

    eg, the HAL will automatically create one in the stm32xxxxx_it.c file:

    /**
     * @brief This function handles System tick timer.
     */
    void SysTick_Handler(void)
    {
     /* USER CODE BEGIN SysTick_IRQn 0 */
    
     /* USER CODE END SysTick_IRQn 0 */
     HAL_IncTick();
     /* USER CODE BEGIN SysTick_IRQn 1 */
    
     /* USER CODE END SysTick_IRQn 1 */
    }