cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB55RB can't allocate memory after GPIO Interrupt

PSpin.2
Associate

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?

2 REPLIES 2
Remy ISSALYS
ST Employee

Hello,

Maybe you can try to start a task when you receive the interrupt instead of managing a flag in main function.

Best Regards

Bob S
Principal

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).