STM32F4上的Libopencm3中断表 [英] Libopencm3 interrupt table on STM32F4

查看:30
本文介绍了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.

谢谢.

推荐答案

你能告诉我在哪里可以找到这张桌子吗?

Can you please show me where to find this table?

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

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

STM32F4的

IRQ_HANDLERS定义在lib/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

所以这些函数在默认情况下只是阻塞处理程序.但它们被定义为weak,因此您可以轻松地在代码中重新定义它们.

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中断表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆