maximum recursion depth exceeded

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: maximum recursion depth exceeded

Post by Roberthh » Tue May 12, 2020 7:50 am

SInce you raised that question both on this Forum and on the micropython.org forum, would you mind to tell, which version of the firmware you are using?
Note: If I compare the code of Pycom and MicroPython.org, I cannot tell where in the micropython.org the memory for the stack is allocated. It may be implicitly done in the esp-idf. But then the stack_size parameter is ignored

Edit: Reading further down the code and the espressif pages, I'm a little bit confused: The stack size is set in the code as stack len, means stack_size/sizeof(stack_element), which is typically a 32 bit sized. The espressif documentation however required the stack size to be given in bytes. See: https://docs.espressif.com/projects/esp ... ertos.html. But the telling in the doc is not clear. While for the paramter ulStackDepth, it tells: "*The size of the task stack specified as the number of bytes.* ", for the parameter pxStackBuffer it tells: *"Must point to a StackType_t array that has at least ulStackDepth indexes ", which indicates that the stack size is to be given in stack elements.

Also comparing the two ports:*
- in the micropython.org port, th->stack is set to the end of the stack, as returned by a call to pxTaskGetStackStart()
- in the Pycom port, th->stack is set to the lowest address of the stack, as allocated before.

Since the stack grows down, only one of both can be right, unless the entry is used for different purposes in both ports.

bitrat
Posts: 41
Joined: Fri Jul 26, 2019 4:13 am

Re: maximum recursion depth exceeded

Post by bitrat » Tue May 12, 2020 8:38 pm

Roberthh wrote:
Tue May 12, 2020 7:50 am
SInce you raised that question both on this Forum and on the micropython.org forum, would you mind to tell, which version of the firmware you are using?
Thanks Robert. I replied on the Pycom forum. I hope it's ok to post on both.

I'm using the Pycom port on LoPy and WiPy. I'm not too familiar with the C internals of either interpreter, or how they differ in this area of stack management.

==============

UPDATE

Missed the obvious!

mptask.h

Code: Select all

#define MICROPY_TASK_STACK_SIZE                 (8 * 1024)
#define MICROPY_TASK_STACK_SIZE_PSRAM           (16 * 1024)
mptask.c

Code: Select all

    if (chip_rev > 0) {
        stack_len = (MICROPY_TASK_STACK_SIZE_PSRAM / sizeof(StackType_t));
    } else {
        stack_len = (MICROPY_TASK_STACK_SIZE / sizeof(StackType_t));
    }
Just for testing, I hard coded #define MICROPY_TASK_STACK_SIZE (16 * 1024) but (to my surprise) I still had to set the larger stack size in my thread with _thread.stack_size(16 * 1024)

Anyway, it seems that solved the problem! Thankyou.

Cheers,
bitrat

Post Reply