Z-uno2 Stack size

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
yves
Posts: 50
Joined: 17 Sep 2021 18:05

Z-uno2 Stack size

Post by yves »

Hi
I have a bug that looks like if I was using too much stack.
My configuration is as follow:
  • Z-Uno bootloader version:3.0.9
    Security:none
    Frequency:EU
    Device included:yes
    Device included securely by controller:no
    Controller:Fibaro HC2
Symptoms:
I use a Serial.println() inside a 4th level sub function after having filled the buffer using some Serial.print(). Strings are 20-30 chars long. What I see on the screen, is not what I was waiting (most of the time, nothing is printed).
If I just place the final Serial.println() in the calling function (ie at the 3rd level) it works.
All functions have very few things on the stack, at most 3 32bit variables, I extensively use global vars.

Question: is there a way to change stack size?

Thanks,
Yves
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Z-uno2 Stack size

Post by p0lyg0n1 »

Please provide the code. It doesn't look like a stack problem. It is about 2 kilobytes and such a small nesting cannot overflow it.
With respect,
Alex.
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Z-uno2 Stack size

Post by p0lyg0n1 »

In order not to be unfounded and immediately check the depth of the stack, I wrote a small sketch. Try it on your device. Nesting up to the 21st with 32 local variables works. If you put more - at some point, HardwareFault appears. It will be reflected in the listing by TX0.

Code: Select all

#define MY_SERIAL Serial0
ZUNO_ENABLE(LOGGING_DBG);
#define NESTING_LIMIT 21    // The maximum nesting value
#define LOCAL_DATA_SIZE 32  // Stack usage of local values
void setup(){
    MY_SERIAL.begin();
    MY_SERIAL.println(" --- STACK TEST using recursion ---");
}
void stacktester(uint32_t limit){
    uint32_t check_local[LOCAL_DATA_SIZE]; 
    MY_SERIAL.print("Limit:");
    MY_SERIAL.println(limit);
    memset(check_local, limit, sizeof(check_local));
    MY_SERIAL.print("Data:");
    MY_SERIAL.dumpPrint(check_local, sizeof(check_local));
    MY_SERIAL.println("");
    limit--;
    if(limit)
        stacktester(limit);
}
void loop(){
    stacktester(NESTING_LIMIT); 
    delay(1000);
}
Here is a listing example of HardwareFault:

Code: Select all

Limit:5
Data:05 05 05 05 05 05 05 05 05 05
05 05 05 05 05 05 05 05 05 05
05 05 05 05 05 05 05 05 05 05
05 05 05 05 05 05 05 05 05 05
05 05 05 05 05 05 05 05 05 05
05 05 05 05 05 05 05 05 05 05
05 05 05 05 05 05 05 05 05 05
05 05 05 05 05 05 05 05 05 05
05 05 05 05 05 05 05 05 05 05
05 05 05 05 05 05 05 05 05 05
05 05 05 05 05 05 05 05 05 05
05 05 05 05 05 05 05 05 05 05
05 05 05 05 05 05 05 05 
Limit:4
Data:04 04 [ 00000ac8 ]      (!) HARD_FAULT                                    
DUMP
 [ 00000ac8 ]      SCB->HFSR:                                        40000000
 [ 00000ac8 ]      SCB->CFSR:                                        00040000
 [ 00000ac8 ]         R0=                                            00000000
 [ 00000ac8 ]         R1=                                            20002efc
 [ 00000ac8 ]         R2=                                            10000000
 [ 00000ac8 ]         R3=                                            e000e000
 [ 00000ac8 ]         R12=                                           a5a5a5a5
 [ 00000ac8 ]         PC=                                            00000000
 [ 00000ac8 ]         LR=                                            00017f7f
 [ 00000ac8 ]         PSR=                                           2000ac3

With respect,
Alex.
yves
Posts: 50
Joined: 17 Sep 2021 18:05

Re: Z-uno2 Stack size

Post by yves »

Hi Alex,

Here also you were right, end of the day it does not seem to be a stack issue. 2k stack is largely sufficient for what I do with it...

And, if I replace Serial.print() & Serial.println() with Serial1.print() & Serial1.println(), it works 'as required'.
I cant really figure out why?
But, for present time, it suits my needs.

Regards,
Yves
Post Reply