STM32F4上的libopencm3中断表

STM32F4上的libopencm3中断表

本文介绍了STM32F4上的libopencm3中断表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的STM32F4上的项目中使用libopenCM3.我以前使用过标准外围设备库和ST开发的较新的硬件抽象层.

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.

这是我为libopenCM3所缺少的.您能告诉我在哪里可以找到这张桌子吗?还是以其他方式完成了?

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.

谢谢.

推荐答案

中断向量表位于 lib/cm3/vector中. c :

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

STM32F4的

IRQ_HANDLERSlib/stm32/f4/vector_nvic.c文件中定义.该文件将在构建库后可用(它是使用 irq2nvic_h 脚本生成的).在此文件中,您可以看到类似这样的内容:

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, \
    ...

dma1_stream0_isr()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.

如上所述,它可以归结为下一个:您只需要定义中断处理程序函数( ISR ),并在代码中使用正确的名称,您的函数将被放置为自动中断向量表.

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.

例如,如果要处理UART2中断,只需在代码中的某处实现usart2_isr()函数.有关ISR功能名称的完整列表,请参见include/libopencm3/stm32/f4/nvic.h.但是这些名字通常很简单.

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.

此外,请查看 libopencm3-examples 项目.机会是您会在那里找到所需的东西.

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

这篇关于STM32F4上的libopencm3中断表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 09:01