nimaltd / gsm_v5

gsm module library for STM32 LL
GNU General Public License v3.0
232 stars 86 forks source link

gsm_call_dial() function locks the program #34

Closed ogulcan90 closed 2 years ago

ogulcan90 commented 3 years ago

Hi,

I tried the library and I can send sms properly, but when I try to make phone call, the program stucks in a way that all tasks stop working.

Here is my FreeRTOS configuration: image

Here is my gsmTask: image

Here is my GSMRun Task: image

It sends the AT command, my phone rings, so when I debug, I see that the PC comes here (line 39 of call.c, inside gsm_call_dial() function): image

Then it goes to atc_command() function and spends some time in this loop (located between line 195 & line 198 of atc.c): image

Then I press resume to see where it stucks, and I see that it stucks in line 278 of heap_4.c: configASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 ); image

which is in vPortFree function.

This means the FreeRTOS somehow cannot deallocate the memory that it allocated before.

Does anyone has any idea on the solution of this problem?

Thank you. Cheers, Ogulcan

nimaltd commented 3 years ago

Hello. Please increase FREERTOS heap size and try again.

ogulcan90 commented 2 years ago

Here is my FreeRTOS heap size: image

I also increased tasks' stack sizes a little more: image

But still I have the same problem...

Do you have any other suggestions?

Thanks. Ogulcan

d-serj commented 2 years ago

Hi @ogulcan90 According to the assertion you are trying to free the memory that was not allocated before.

Why it is happening is very interesting issue to dive in 🙂

First of all it could be because you are trying to free the memory twice. If you are trying to free the memory twice most likely that you are using this already freed memory in other places that would lead to heap memory corruption. Thats why it is very good programming practice to set all the pointers to NULL after they were freed.

Also you can try step by step debugging and make yourself sure that memory was allocated well and pointer holds actual value to this memory. If memory was allocated well save the value where the pointer is pointing to. Then at vPortFree call compare saved value with actual value that is passing as a parameter to vPortFree. If they are different most likely you faced with stack memory corruption and the pointer value was overwritten somewhere in the stack.

ogulcan90 commented 2 years ago

Hi @nimaltd and @d-serj ,

I solved the problem by increasing _ATC_SEARCH_CMD_MAX from 5 to 10.

The thing is in atc_command() function, there are these line:

    if (items >= _ATC_SEARCH_CMD_MAX)
      break;

in which the memory is allocated but it breaks before freeing.

I suggest you to free the memory before this break.

Also you might want to find a way to address this lack of number of _ATC_SEARCH_CMD_MAX.

Thank you for your interest.

Regards, Ogulcan