Skip to main content
PSpin.2
Visitor II
October 13, 2022
Question

STM32WB55RB can't allocate memory after GPIO Interrupt

  • October 13, 2022
  • 2 replies
  • 1310 views

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?

This topic has been closed for replies.

2 replies

Remy ISSALYS
Technical Moderator
October 28, 2022

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
Super User
October 28, 2022

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