esp_ping default stack is insufficient

dalbert
Posts: 14
Joined: Wed Nov 16, 2016 3:45 am

esp_ping default stack is insufficient

Postby dalbert » Wed May 14, 2025 7:08 am

Using ESP IDF 5.4.1 and esp_modem with the esp_ping reference code. The default ping task stack size using ESP_PING_DEFAULT_CONFIG() is 2.5K and with that stack size, I frequently get exceptions on ping_end (as the stack unwinds). Increasing the stack size to 4K completely eliminates the exceptions. Is there a way to determine the proper stack size?

MicroController
Posts: 2661
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: esp_ping default stack is insufficient

Postby MicroController » Wed May 14, 2025 8:14 am

Is there a way to determine the proper stack size?
uxTaskGetStackHighWaterMark() may help.

dalbert
Posts: 14
Joined: Wed Nov 16, 2016 3:45 am

Re: esp_ping default stack is insufficient

Postby dalbert » Thu May 15, 2025 11:31 pm

Thanks for the suggestion; I added the following to the esp_ping_thread()

Code: Select all

            if (ep->on_ping_end) {
                // Check stack usage
                UBaseType_t uxHighWaterMark;
                uxHighWaterMark = uxTaskGetStackHighWaterMark( NULL );
                ep->on_ping_end((esp_ping_handle_t)ep, (void *)uxHighWaterMark);
            }
Then printed the high water mark in my on_ping_end callback:

Code: Select all

    printf("%lu packets transmitted, %lu received, time %lums hwm=%u\r\n", transmitted, received, total_time_ms, (unsigned int)args);
With the default stack size (2048+512), the code generally fails:

Code: Select all

64 bytes from 69.147.92.12 icmp_seq=1 ttl=58 time=204 ms
64 bytes from 69.147.92.12 icmp_seq=2 ttl=58 time=279 ms
64 bytes from 69.147.92.12 icmp_seq=3 ttl=58 time=230 ms
64 bytes from 69.147.92.12 icmp_seq=4 ttl=58 time=521 ms
64 bytes from 69.147.92.12 icmp_seq=5 ttl=58 time=217 ms
Guru Meditation Error: Core  0 panic'ed (InstrFetchProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x00060723  PS      : 0x00060830  A0      : 0x8008b434  A1      : 0x3ffc9930
A2      : 0x3ffc8f90  A3      : 0x00000000  A4      : 0x3ffb36d0  A5      : 0x00060023
A6      : 0x00000001  A7      : 0x00000040  A8      : 0x80106e6c  A9      : 0x3ffc9910
A10     : 0x3ffc8f90  A11     : 0x00000014  A12     : 0x3ffb0108  A13     : 0x0000001c
A14     : 0x3ffc8f90  A15     : 0x0000001c  SAR     : 0x0000001b  EXCCAUSE: 0x00000014
EXCVADDR: 0x00060720  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffc


Backtrace: 0x00060720:0x3ffc9930 0x4008b431:0x3ffc9980
When I extend the stack by 64 bytes, it works and shows 20-28 bytes of stack remaining:

Code: Select all

    ping_config.task_stack_size =  2624;

Code: Select all

64 bytes from 69.147.92.11 icmp_seq=1 ttl=58 time=218 ms
64 bytes from 69.147.92.11 icmp_seq=2 ttl=58 time=272 ms
64 bytes from 69.147.92.11 icmp_seq=3 ttl=58 time=231 ms
64 bytes from 69.147.92.11 icmp_seq=4 ttl=58 time=271 ms
64 bytes from 69.147.92.11 icmp_seq=5 ttl=58 time=231 ms
5 packets transmitted, 5 received, time 1223ms hwm=20

Who is online

Users browsing this forum: ChatGPT-User, Google [Bot], PerplexityBot and 11 guests