cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Init Vector Table

Carlos Hernandez
Associate II
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
1 ACCEPTED SOLUTION

Accepted Solutions
Andrew Neil
Evangelist III
Posted on March 14, 2018 at 19:34

For basic getting-started tips, see:

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

View solution in original post

12 REPLIES 12
David SIORPAES
ST Employee
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.
Andrew Neil
Evangelist III
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()

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

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.

Posted on March 14, 2018 at 18:05

Thanks Neil.

Now, I'll give ISRs names.

Is it possible to modify the startup code? Is it Flash right?

Posted on March 14, 2018 at 18:33

Carlos Hernandez wrote:

Is it possible to modify the startup code?

Of course - it's all just source code!

But it's one of those, 'if you need to ask the question, then you probably shouldn't be messing with it' cases ...

Andrew Neil
Evangelist III
Posted on March 14, 2018 at 19:34

For basic getting-started tips, see:

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

Posted on March 14, 2018 at 19:19

Yeah, I just want to see how it works. I checked the Programing Manual and Reference Manual and both documents don't have a code explanation of the startup code. Do you have a good reference for this?

Regarding the Interrupts, I did this:

void EXTI0_IRQHandler(void){

    //Executed whenever the interrupt is set

    if(EXTI_GetITStatus(EXTI_Line0) == RESET) //

        return;

    i=0;

    do{

          GPIO_WriteBit(GPIOD,GPIO_Pin_14, Bit_SET);

          delay(6000000);

          GPIO_WriteBit(GPIOD,GPIO_Pin_14, Bit_RESET);

          delay(6000000);

          ++i;

    }while(i<5);

    EXTI_ClearITPendingBit(EXTI_Line0); //Aknoledge that we receive the interrupt.

}

I understand everything here, but it's not clear yet: where I put the parameter [WEAK] to give a default IRQ if the current one is not defined. Moreover, there are difference between the microcontroller vendor of how to use interrupts, in this case STM  requires NVIC and External Interrupt initialization. Is there a code reference to know this STM features. I overviewed the STM programming and reference manual but I couldn't find a place where they points these cases.

Thanks in advance.

Posted on March 14, 2018 at 19:33

Having delays in you ISRs is a Really Bad Idea!

:(

where I put the parameter [WEAK]

You don't - because you are not providing the defaults!

The defaults are already provided for you!