From 12d442e8ddf9e3d13b99a15d662f4ac8dcd1d287 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Thu, 28 Feb 2019 12:04:56 -0800 Subject: [PATCH] px4_fmuv5:Stack Check build Increase to 2624 The cause of the stack detection fault is because of the level of nesting in the start up script. We need to determine the worst case configuration and set the bar there. This fault occurred some 42 calls deep due to script calling script (repeat). The HW stack check requires as a margin of 204 bytes. That is ISR HW stacking of CPU(8) FPU(18) registers and SW stacking of CPU(11) and FPU(16) registers. Total CPU(19) registers is 68 bytes and the total FPU(34) registers is 136 bytes. On a system with a separate ISR stack This only needs to be 104 so there is 100 bytes of headroom. But as coded the detection will give a false positive detection and fault. This does not mean that the stack will be corrupted. Adjustments to that stack can have no effect due to rounding. A stack size of 2608 and 2616 can yield the exact same size stack. So even when the failure is due to a 4 byte overflow, it can take greater than a 16 bytes increase to fix it. Because the final stack size is calculated with an 8 byte alignment after a 4 byte decrease. So 2624 becomes 2620 at runtime and will boot with SYS_AUTOSTART=4001. --- boards/px4/fmu-v5/nuttx-config/stackcheck/defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/px4/fmu-v5/nuttx-config/stackcheck/defconfig b/boards/px4/fmu-v5/nuttx-config/stackcheck/defconfig index 0aa357e750..fc119c5305 100644 --- a/boards/px4/fmu-v5/nuttx-config/stackcheck/defconfig +++ b/boards/px4/fmu-v5/nuttx-config/stackcheck/defconfig @@ -735,7 +735,7 @@ CONFIG_SCHED_LPWORKSTACKSIZE=1800 # Stack and heap information # CONFIG_IDLETHREAD_STACKSIZE=750 -CONFIG_USERMAIN_STACKSIZE=2500 +CONFIG_USERMAIN_STACKSIZE=2624 CONFIG_PTHREAD_STACK_MIN=512 CONFIG_PTHREAD_STACK_DEFAULT=2048 # CONFIG_LIB_SYSCALL is not set