1

在 Cube MX 生成的 [devicename]_it.c 文件中,每个 IRQ 处理程序中有多个用户代码部分,例如下面的 ADC_IRQHandler

void ADC_IRQHandler(void)
{
   /* USER CODE BEGIN ADC_IRQn 0 */

   /* USER CODE END ADC_IRQn 0 */

   /* USER CODE BEGIN ADC_IRQn 1 */

   /* USER CODE END ADC_IRQn 1 */
}

多个部分的意图是什么?

4

1 回答 1

0

If you tick the option in CubeMX to generate a call to the HAL ADC handler, and regenerate the code, it'd put the call to HAL_ADC_IRQHandler() between the two user code sections. You can have user code both before and after the HAL stuff.

However, I find it a poor idea to handle an interrupt both by HAL code and user code in the IRQHandler function, because that'd usually mean reading registers twice, which could have some unwanted side effects. If the HAL handler is called, then it'd be better to put user code in the appropriate callback function, which would be called when HAL has found out the cause of the interrupt.

于 2019-06-20T18:10:00.560 回答