cancel
Showing results for 
Search instead for 
Did you mean: 

HAL interrupt function

ajimathew
Associate III

Dear @KDJEM.1 

Whenever, I implement the HAL_Interrupt functions(say HAL_UART_Receive_IT();). What is happening at the backend, to use those interrupt function I should enable the global interrupt (NVIC) in CubeIDE. What are these global interrupts

also can we say callBack functions as ISR,s ?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Piranha
Chief II

Generally an ISR is the function, which is executed by the CPU, when it processes the interrupt - for example, USART1_IRQHandler(). With HAL typically the ISR calls HAL_USART_IRQHandler() and that one calls the callbacks like HAL_USART_TxCpltCallback() etc. These HAL functions are not ISRs, but they are called from ISRs and therefore run in an interrupt context.

View solution in original post

5 REPLIES 5
Tinnagit
Senior II

yes, you have to enable the global interrupt (NVIC) in CubeIDE. 

if you don't enable it that the program vector may go to mistake address and it's going to be stuck.

and it need a call back function for each interrupt which you can see their function by go to core -> src -> stm32xxx_it.c looking for it IRQhandler.

you 'll see HAL IRQ and open it declaration of that function.
In the declaration file that was opened you can find callback function for it interrupt.
and you should extern the function in your place where you use it.

good lick

KDJEM.1
ST Employee

Hello @ajimathew ,

When you use the HAL_UART_Receive_IT(), you needs to enable the global interrupt (NVIC) in STM32CubeIDE (Please refer to Getting started with UART).

For STM32L4 example  

The UART HAL driver can be used as follows:
1. Declare a UART_HandleTypeDef handle structure (eg. UART_HandleTypeDef huart).
2. Initialize the UART low level resources by implementing the HAL_UART_MspInit() API:
– Enable the USARTx interface clock.
– UART pins configuration:
◦ Enable the clock for the UART GPIOs.
◦ Configure these UART pins as alternate function pull-up.
– NVIC configuration if you need to use interrupt process (HAL_UART_Transmit_IT() and
HAL_UART_Receive_IT() APIs):
◦ Configure the USARTx interrupt priority.
◦ Enable the NVIC USART IRQ handle

 The callback function can be used for each interrupt.

Thank you.

Kaouthar

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

ajimathew
Associate III

 

okay then callback function is ISR? Can we tell like that? @KDJEM.1 

Hi @ajimathew ,

The Callback functions aren't ISR. These functions are used when the project need an interrupt.

For example, when the USART communication is performed using Interrupts or DMA, These API's return the
HAL status. The end of the data processing will be indicated through the dedicated USART IRQ when
using Interrupt mode or the DMA IRQ when using DMA mode. The HAL_USART_TxCpltCallback(),
HAL_USART_RxCpltCallback() and HAL_USART_TxRxCpltCallback() user callbacks will be executed
respectively at the end of the transmit or Receive process The HAL_USART_ErrorCallback()user
callback will be executed when a communication error is detected.

For more explanation, I recommend you to take a look to Description of STM32L4/L4+ HAL and low-layer drivers user manual.

When your question is answered, please close this topic by choosing "Accept as Solution". This will help other users find that answer faster.

Kaouthar

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Piranha
Chief II

Generally an ISR is the function, which is executed by the CPU, when it processes the interrupt - for example, USART1_IRQHandler(). With HAL typically the ISR calls HAL_USART_IRQHandler() and that one calls the callbacks like HAL_USART_TxCpltCallback() etc. These HAL functions are not ISRs, but they are called from ISRs and therefore run in an interrupt context.