2024-11-19 05:20 AM - last edited on 2024-11-19 05:25 AM by SofLit
my daily job is C# programming, so after a break on stm32,
I started again with platformIO and CubeMx
( and thought how hard can it be to turn a led on and off ? )
the problem i have with the STM32F0 discovery ( the green one )
the EXTI IRQ event is not triggered.
i found this example.
https://www.youtube.com/watch?v=xawN4Y7uSJ4
https://moons.link/en/post-256/
https://deepbluembedded.com/stm32-external-interrupt-example-lab/
after chanchig the project with the CubeMx32 tool
the function changed
MX_GPIO_Init()
from what i read in the documentation.
you can override the weak callback function by adding this.
so when the button is pushed the second led toggles.
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == UserButton1_Pin) // If The INT Source Is EXTI Line9 (A9 Pin)
{
HAL_GPIO_TogglePin(LD4_GPIO_Port, LD4_Pin); // Toggle The Output (LED) Pin
}
}
there should also be an IRQhandler function.
void EXTI0_IRQHandler(void)
{
/* USER CODE BEGIN EXTI0_IRQn 0 */
//HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
/* 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 */
}
and the last step where i am not sure about is this.
after reading a lot and some puzzling, i cannot get it to work.
thanks
Solved! Go to Solution.
2024-11-19 09:02 AM
It goes into the Default_Handler because you don't have defined the proper interrupt handler, i.e. EXTI0_1_IRQHandler() (the weak EXTI0_1_IRQHandler in the startup code, which is in that case used, is then just an alias of Default_Handler).
JW
2024-11-19 11:28 AM
@johannv99 wrote:
to answer the question where it "hangs" ( infinite loop )
after push the button...
it is this file generated by cubeMx
( startup_stm32f051x8.s )
Did you test the ioc I've shared or not? please answer that question.
Thank you.
2024-11-19 12:20 PM
I tried your ioc file and project, but it had the same problem.
I think Mr Waclawek could be right.
i found 2 similar cases.
this is the loop where it hangs, ( because of the Default_Handler )
here it looks like there is a solution for the startup_stm32F051x8.s file.
https://community.st.com/t5/stm32-mcus-products/exti-irq-with-userbutton-problem/td-p/427227
I think slowly i am getting there.
2024-11-19 12:25 PM
Could you please share the complete poject?
2024-11-19 04:27 PM
The STM32 CubeMx tool saves you lots of time, figuring out what functions you have left on free pins.
also port configuration and all other options. are real handy.
other option is, if your project has to change to a different cpu variant, it will save lots of time.
one thing is if you are new to using it, take some time to click through the interface.
one checkbox missed, for a port and the function was not generated. and lots of coding debbuging time etc.
thanks for all help.
@mr waclawek.jan
this was indeed missing when code was generated. there was only a default_handler.
EXTI0_1_IRQHandler() ( EXTI0_1_IRQHandler )