Portenta H7 project crashing now - a loop() stack size issue?

I had a project working fine.
After adding some code - it crashes now. I get the red morse-code LED.

I guess I found what is going on:
I assume, the stack size is too small.
What is the stack region/size configured?
What is the stack size for loop() function and for RTOS threads?
How to figure out my "memory layout" when compiling a Portenta H7 mbed project?

This was my original code:

void loop() {
    EthernetClient client = server.available();

    if (client)
    {

This crashes now (even it was working fine before).
I assume:

  • I have added more stuff to function setup()

  • it crashes now due to missing space on stack (for local variables)

I can fix by changing it to (use static):

void loop() {
    static EthernetClient client = server.available();
    //if (!GConfigDone)
    //    return;                         // not yet ready, potentiallay called too early

    if (client)
    {

So, it looks like, this client variable is a "huge" object and needs plenty of space on stack.
The static keyword fixes the issue (sure, it does not place client object anymore on stack).

It raises the following questions:

  1. How do I know how large an object is?
    When I create an instance of EthernetClient as client - how large is it?
    (for my stack space)
    Sure, I could do a print("%d", sizeof(client)); but I want to get a clue during/before compile time, not just running the code to see (anyway too late - crashing already before I would see my print).
    Hard to see and parse the nested inheritances of classes, esp. if not all Open Source code
    is provided by Arduino.

  2. Are there any hints as "not to do", e.g. "can this object be a local one?"
    Can it be created all the time again?
    (what is the destructor doing when it returns from function? Really all properly released?)

Also unknown:

  • Is there a guarantee that function loop() is called just after function setup() has completely finished?
    It is even more a bit tricky question because during my setup() I create other RTOS threads. So, some code launched runs in parallel to setup() (? not sure, but possible). But my loop() function might depend on fact, that all, including all child threads started and creating objects, have completed.
    When loop() is called "too early" it might miss some resource because setup() has finished "too late".

OK, not the issue here (I tried to make sure but not needed).
So, my issue here is: my stack seems to be corrupted now after adding just a tiny bit of more code.
"rrrrrr": if I could get a nice debugger on Portenta - it would make the life easier.
FW development for Arduino, Portenta H7 ... is not really easy, actually painful with all these slow tools and slow workflow (turn-around time for "change - compile - flash - try again" is way too slow).
Debugging just with UART available - what an old-fashioned approach.

Please, Arduino team:
provide full Open Source (I mean: all code, e.g. startup code, clock config code ...)
and
add a nice debugger to the board (or make it possible to use other IDEs with real debugger).
Thank you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.