Binding an interrupt to a module - smartel99/NilaiTFO GitHub Wiki
For this example, we will bind the USART3_IRQHandler
to the UartModule.
- Under
USER CODE BEGIN PFP
in the filestm32f4xx_it.c
, located inCore/Src
(or the one corresponding to the STM32 being used), add the declaration of a function to be used as the forwarding function:stm32f4xx_it.c
:
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
void Uart3_Callback(void);
/* USER CODE END PFP */
- In the interrupt handler, add a call to the forwarding function we just declared, followed with a
return
statement:stm32f4xx_it.c
:
/**
* @brief This function handles USART3 global interrupt.
*/
void USART3_IRQHandler(void)
{
/* USER CODE BEGIN USART3_IRQn 0 */
Uart3_Callback( );
return;
/* USER CODE END USART3_IRQn 0 */
HAL_UART_IRQHandler(&huart3);
/* USER CODE BEGIN USART3_IRQn 1 */
/* USER CODE END USART3_IRQn 1 */
}
The return
statement is really important! Omitting it will cause HAL_UART_IRQHandler
to disable the RX interrupt!
- In
interfaces/interruptsVector.cpp
(create the file if it doesn't exist...), we now implement our forwarding function. Notice theextern "C"
prefacing it, it is what makes the connection between the C code of the interrupt and the CPP code of our module.
interfaces/interruptsVector.cpp
:
extern "C" void Uart3_Callback(void)
{
static UartModule* module = UART3_MODULE;
module->HandleReceptionIRQ( );
}
To do this with any other module/interrupt, just do exactly the same thing with the names you want, it's not that hard...