Help ! This error is non-deterministic. Sometimes it happens, sometimes not. When it happens, it seems to be right after I read something from the UART and always in the first seconds of the program execution.
You will find my snapshot attachment very descriptive.
The truth is that i surely put too much weight on my esp32 : I use 2 sockets, one of which runs non stop, the bluetooth, a hardware timer which blinks a led, UART communication.
All of these interact through freeRTOS Tasks (using xEventGroup, xQueue) but also through classic pthreads.
UART read (which is where the exception seems to happen) is run by a pthread.
I try to find where exactly in my code did the exception happen, but I cannot.
I checked the CORE DUMP and through menuconfig I demanded to print via UART all messages (Info, Errors, ... everything). But still, I cannot find nothing that determines where the error actually happened. I guess that's because of the errors nature (stack overflow) but again , why is it sometimes happens and sometimes not?
Anyway, if stack is not enough , what do you propose me to do ? I already tried to increase Main Task stack size from 3584 to 7168(since pthreads live inside mother main task) but this didn't help.
Could there be an implication between hardware timer interrupts and UART?
Could there be an implication between hardware timer interrupts and pthread mutex I also use after using UART RX ?
thanks !
EDIT : My impression was wrong. This error not only happens in the beginning of my program.
stack Overflow in task pthread
stack Overflow in task pthread
- Attachments
-
- esp32.jpg (570.02 KiB) Viewed 11887 times
Last edited by filchr on Fri Jun 29, 2018 7:29 am, edited 1 time in total.
Re: stack Overflow in task pthread
In your code, are you creating any additional tasks/threads? If so, what stack size are you allocating and/or what statements are you calling to created those tasks/threads?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: stack Overflow in task pthread
If its really pthread stack error then you have in menuconfig settings to change pthread stack size. By default its 3kB.
Re: stack Overflow in task pthread
Code: Select all
// Start TX uart task
xTaskCreate(tx_task, "uart_tx_task", 1024*2, NULL, configMAX_PRIORITIES-1, NULL);
// Start bluetooth task
xTaskCreate(bt_app_gap_start_up, "connected_to_wifi_program", 2048, NULL, 5, NULL);
// Creating pthread for server usage
pthread_t server_thread;
if (pthread_create(&server_thread, NULL, servering, NULL))
ESP_LOGE(USER_TAG, "###|COULD NOT start server thread.");
// First intilialize the mutex between the thread & the main thread.
// A socket is shared between rxUART_thread & main thread.
// so, I need a mutex, so that they don't access it at the same time
if (pthread_mutex_init(&lockSocket, NULL) != 0)
ESP_LOGE(USER_TAG, "Could not initialize mutex");
//creating pthread for rx uart
pthread_t rxUART_thread;
if (pthread_create(&rxUART_thread, NULL, rx_thread, NULL))
ESP_LOGE(USER_TAG, "###|COULD NOT start server thread.");
I tried extending the stack using pthread_attr_setStackSize but then I realized that all pthread_attr are disabled for the pthread implementation of ESP32.
But yes ! As chegewara is saying we can extend the pthread task stack size by menuconfig !
Up untill now, the error did not repeat itself thankfully.
Re: stack Overflow in task pthread
See also the following issue:
https://github.com/espressif/esp-idf/issues/988
While the make menuconfig seems to allow us to specify a stack size for all new pthreads, this doesn't appear to offer granularity on the amount of stack for any given thread. The issue listed above seems to point to a new function called esp_pthread_set_cfg() which can be used to set the stack size for the next pthread to be created ... this might allow one to tune the stack size on a per pthread creation basis.
I'd also like to mention that C++ exceptions do seem to work for me ... but one has to explicitly enable them in make menuconfig. C++ exceptions handling is off by default.
https://github.com/espressif/esp-idf/issues/988
While the make menuconfig seems to allow us to specify a stack size for all new pthreads, this doesn't appear to offer granularity on the amount of stack for any given thread. The issue listed above seems to point to a new function called esp_pthread_set_cfg() which can be used to set the stack size for the next pthread to be created ... this might allow one to tune the stack size on a per pthread creation basis.
I'd also like to mention that C++ exceptions do seem to work for me ... but one has to explicitly enable them in make menuconfig. C++ exceptions handling is off by default.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: stack Overflow in task pthread
kolban , thanks for the info !
As far as C++ exceptions are concerned, are you sure they do work? I mean, in my system they do compile but when it comes to the point of getting them thrown, the core dumps.
I leave a screenshot here, of my code and the errors I am getting for the above issue.
As you can see exception in main thread happens naturally.
As far as C++ exceptions are concerned, are you sure they do work? I mean, in my system they do compile but when it comes to the point of getting them thrown, the core dumps.
I leave a screenshot here, of my code and the errors I am getting for the above issue.
As you can see exception in main thread happens naturally.
- Attachments
-
- exceptions_in_tasks.png (457.36 KiB) Viewed 11785 times
Re: stack Overflow in task pthread
C++ exception support is turned off by default in menuconfig, which means that throwing an exception immediately calls std::terminate which calls abort() (as shown in the log).filchr wrote: As far as C++ exceptions are concerned, are you sure they do work? I mean, in my system they do compile but when it comes to the point of getting them thrown, the core dumps.
I leave a screenshot here, of my code and the errors I am getting for the above issue.
As you can see exception in main thread happens naturally.
This is the item which must be enabled to use C++ exceptions:
http://esp-idf.readthedocs.io/en/latest ... EXCEPTIONS
Once C++ exception support is enabled, you should be able to throw/catch exceptions from any RTOS task or pthread.
Note that turning on C++ exception support will increase the overall stack usage of any C++ code, so if a 3KB pthread stack size was already borderline then it will definitely be too small with exception support enabled. You can increase the default size in menuconfig, or switch to creating tasks with FreeRTOS APIs (and explicit stack size in the function call), or you can call esp_pthread_set_cfg() as mentioned by kolban above.
Who is online
Users browsing this forum: daniel_3in, sshwarts and 107 guests