Libopencm3 interrupt table on STM32F4

2019-07-25 07:18发布

I'm using libopenCM3 for my project on STM32F4. I've used previously Standard Peripheral Library and newer Hardware Abstraction Layer developed by ST.

In these libraries you have assembly file (startup file) with the definition of vector table.

This is what I'm missing for libopenCM3. Can you please show me where to find this table? Or is it done some another way?

I really need to use interrupts in my project.

Thanks.

1条回答
姐就是有狂的资本
2楼-- · 2019-07-25 07:57

Can you please show me where to find this table?

Interrupt vector table is located in lib/cm3/vector.c:

__attribute__ ((section(".vectors")))
vector_table_t vector_table = {
    ...
    .irq = {
        IRQ_HANDLERS
    }
};

And IRQ_HANDLERS for STM32F4 are defined in lib/stm32/f4/vector_nvic.c file. This file will be available after building the library (it's generated with irq2nvic_h script). In this file you can see something like this:

#define IRQ_HANDLERS \
    [NVIC_DMA1_STREAM0_IRQ] = dma1_stream0_isr, \
    [NVIC_ADC_IRQ] = adc_isr, \
    ...

Functions like dma1_stream0_isr() and adc_isr() are defined like this:

#pragma weak adc_isr = blocking_handler

So these functions are just blocking handlers by default. But they are defined as weak, so you can easily redefine them in your code.

Or is it done some another way?

As discussed above, it boils down to next: you just need to define interrupt handler function (ISR) with correct name in your code, and your function will be placed to interrupt vector table automatically.

For instance, if you want to handle UART2 interrupt, just implement usart2_isr() function somewhere in your code. For the whole list of ISR function names refer to include/libopencm3/stm32/f4/nvic.h. But those names are usually pretty straight-forward.

Also, check out the libopencm3-examples project. The chances are you will find just what you need there.

查看更多
登录 后发表回答