Page 1 of 1

This WiFi Code causes Stack overflow

Posted: Tue Apr 16, 2024 11:47 am
by iseries1
Was having issues with ESP32 connecting to my router using APSTA mode and found that changing from a local variable to program variable fixed the issue.

Please find attached the sample testing code I used with ESP32 and ESP-IDF.

Mike

Tried with other ESP units with the same results.

Re: This WiFi Code causes Stack overflow

Posted: Wed Apr 17, 2024 2:31 am
by ESP_Sprite
...Okay, thanks for sharing, but did you have a question? In general, yes, if you declare variables inside your functions, it'll use up stack space, and if you didn't allocate enough of that to your task, it'll overflow your stack. Making variables global is one way around that, although normally people would just increase the stack size by a bit.

Re: This WiFi Code causes Stack overflow

Posted: Wed Apr 17, 2024 12:43 pm
by iseries1
Since IDF is in control of the stack it should not happen.

If I remove the string copies from the code the stack does not overflow.

In addition, even though the stack does not overflow it will never connect to the router.

Mike

Re: This WiFi Code causes Stack overflow

Posted: Thu Apr 18, 2024 12:30 am
by ESP_Sprite
iseries1 wrote:
Wed Apr 17, 2024 12:43 pm
Since IDF is in control of the stack it should not happen.
No, it is not. ESP-IDF will create the main task with the amount of stack you configure, and it's your job to reconfigure it if it's too small. Enter menuconfig and then Component config → ESP System Settings → Main task stack size to change it, or use xTaskCreate to create your own stack.
In addition, even though the stack does not overflow it will never connect to the router.
That is a different issue. Do you have logs for that problem?