为什么我的中断会被调用,但不会进入处理程序? [英] Why does my interrupt get called, but won't enter the handler?

查看:71
本文介绍了为什么我的中断会被调用,但不会进入处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以中断模式接收来自USART的通信.调试器向我展示了在按键时调用了中断,但是执行陷入了向量表定义中.

I'm trying to recieve communication from an USART in interrupt mode. The debugger shows me that the interrupt is getting called on a keypress, but the execution gets stuck in the vector table definition.

我使用以下命令初始化我的usart.

I initialize my usart with the following.

static void MX_USART2_UART_Init(void)
{
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 19200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }

  /* USER CODE END USART2_Init 2 */
  LED_Initialize();
  USART2->CR1=USART_CR1_RE|USART_CR1_TE|USART_CR1_UE|USART_CR1_RXNEIE; // Enable interrupt
  NVIC_SetPriority(USART2_IRQn, 2); // set priority level
  NVIC_EnableIRQ(USART2_IRQn); // Enable in NVIC
}


void USART2_IRQHandler(void)
{
    blink_led();
}

如果我在调试模式下运行该应用程序,按下一个键,然后停止并逐步执行代码,我会发现它在此处包含的startup_stm32f446xx.s内部的分支指令上循环.

If I run the application in debug mode, hit a key, stop and step through the code, I find it's looping on the branch instruction here, inside of the included startup_stm32f446xx.s.

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

所以我知道正在生成中断,但似乎找不到我的处理程序.即使不在调试模式下,我的LED也不会闪烁,这是我已经单独测试的功能.我不确定此问题是否来自HAL库.我已经阅读了他们的文档和他们的NVIC启用说明的变体,以得到相同的结果.usart在轮询中工作正常,但是我需要中断其功能.

So I know the interrupt is getting generated, but it can't seem to find my handler. Even not in debug mode, my LED doesn't blink, which is a function I've tested seperateky. I'm not sure if this issue is from from the HAL library. I've read through their documentation and variations with their NVIC enable instructions to the same result. The usart works fine in polling, but I need interrupts for my functionality.

推荐答案

您的问题带有"c ++"标记,因此我假设您使用C ++编译器编译项目.C ++编译器使用name-mangle函数名称,可防止分支指令查找其目标,因为它的真实名称不再是USART2_IRQHandler.

Your question has "c++" tag, so I assume you compile your project with a C++ compiler. C++ compilers name-mangle function names, which prevents the branch instruction to find its target, because its real name isn't USART2_IRQHandler anymore.

您需要在ISR前面加上外部"C" ,以告诉C ++不要对其进行名称修改.

You need prefix your ISR with extern "C" to tell C++ not to name-mangle it.

extern "C" void USART2_IRQHandler(void) {
    blink_led(); 
}

这篇关于为什么我的中断会被调用,但不会进入处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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