How interrups works in buttons in STM32 ?

MrChips

Joined Oct 2, 2009
34,956
I went back and read what you wrote in post #1.
Your problem is that you are confused by how a function is declared and then called.

You did not “copy” the function and move it to main.c.
What you did was you copied a line of text for the purpose of editing in a different place.

You need to go back and learn how to create and use functions by doing something simple.

You will see the name of the function in possibly two, three or more places.

1) the function definition
2) a function call
3) a function prototype

Go and read how to do these three things.
 

Thread Starter

Xenon02

Joined Feb 24, 2021
504
I went back and read what you wrote in post #1.
Your problem is that you are confused by how a function is declared and then called.
I was more confused that HAL (Callback) was the only one having void but HAL_Delay or HAL_GetTick or HAL_GPIO_Toggle and many more don't have void or declared anything. But The Callback is the first HAL I see that is being defined as "void" HAL_....

But my friend told me that the whole magic was hidden in what "weak" means next to function.
Weak means that if the function is not defined, then it is defined in a place where "weak" is. When it is defined somewhere else then it will use that definition.
So I imagined it this way that "weak" HAL Callback is ignored and instead jump into the Callback I defined that's all. I just didn;t know that the "weak" Callback can be ignored and will know where to find the defined Callback and use that instead.

https://stackoverflow.com/questions...re-their-uses-i-am-using-a-stm32f429-micro-co - something like I said is also written here.

That's how it worked.

Also


You will see the name of the function in possibly two, three or more places.

1) the function definition
2) a function call
3) a function prototype

Well look at this :


C:
Code:
void EXTI0_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI0_IRQn 0 */

  /* USER CODE END EXTI0_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
  /* USER CODE BEGIN EXTI0_IRQn 1 */

  /* USER CODE END EXTI0_IRQn 1 */
}
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); - 1. this is a function because it has a block of code in another file, 2. this is a function call because we use the function and put arguments in it.
3. I've found something like this about function prototype :
1697028102363.png
A function definiton and a function call. So the combination of 1 and 2 of your points.

HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); is a call function while his function definition is in another file.


What does have these 3 points with Callback function ? It acts differently because of "weak" in front of the function.
And that confused me.
 

MrChips

Joined Oct 2, 2009
34,956
The __weak declaration allows the code to compile even though you have not yet written it. It allows you to create your own function with the same name.
 

Thread Starter

Xenon02

Joined Feb 24, 2021
504
The __weak declaration allows the code to compile even though you have not yet written it. It allows you to create your own function with the same name.
Something like I said before.
So basically when I write the same function without _weak declaration then it will be executed something like that :

The interrupt starts so :

1697030360451.png

Following the interrupt code :

It will execute the void HAL_GPIO_EXTI_IRQHandler function, it will skip _weak void HAL_GPIO_EXTI_Callback and the interrupt then jumps into main file (diffenet file than the interrupt file) to execute void HAL_GPIO_EXTI_Callback without file and in main file the interrupt stops and goes back to main function.

Something like that ? Trying to say it in my own way for you to judge whether it has sense or not. Because _weak void HAL_GPIO_EXTI_Callback is not a call function like here :

1697030616050.png
 
Top