This WiFi Code causes Stack overflow

iseries1
Posts: 4
Joined: Tue Apr 16, 2024 11:38 am

This WiFi Code causes Stack overflow

Postby iseries1 » Tue Apr 16, 2024 11:47 am

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.
Attachments
testing.zip
(15.73 KiB) Downloaded 125 times

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: This WiFi Code causes Stack overflow

Postby ESP_Sprite » Wed Apr 17, 2024 2:31 am

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

iseries1
Posts: 4
Joined: Tue Apr 16, 2024 11:38 am

Re: This WiFi Code causes Stack overflow

Postby iseries1 » Wed Apr 17, 2024 12:43 pm

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

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: This WiFi Code causes Stack overflow

Postby ESP_Sprite » Thu Apr 18, 2024 12:30 am

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?

Who is online

Users browsing this forum: No registered users and 128 guests