2022-10-13 04:24 AM
The problem can be simplyfied to this code:
int startFlag = 0;
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){
startFlag = 1;
}
int main(){
if(startFlag== 1){
//crashes at first iteration (Hard_Fault_Handler)
int *test = malloc(sizeof(int));
}
}
But this works like a intened:
int main(){
int *test = malloc(sizeof(int));
}
I really dont see the obvious issue here. I made sure that the Callback function is completly finished and also tried it with " volatile int startFlag = 0;" but it didn't help.
Can someone help me?
2022-10-28 08:58 AM
Hello,
Maybe you can try to start a task when you receive the interrupt instead of managing a flag in main function.
Best Regards
2022-10-28 10:26 AM
That is obviously NOT your real code, or not ALL of your real code. You don't show any code that enables the EXTI interrupt, thus startFlag cannot be == 1.
Yes, you need to use "volatile", even if you didn't see any difference in this example. That is needed for any variable that is accessed in an interrupt function and a non-interrupt function (or even multiple interrupt functions).