Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Debugging NuttX reveals that it stores an incorrect SP at regs[0] during context switching.
Right before the context switch via SVC call:
0x08014410 in sys_call2 (nbr=2, parm2=537382140, parm1=537028520) at /home/alex/PX4-Autopilot/platforms/nuttx/NuttX/nuttx/arch/arm/include/syscall.h:186 186 __asm__ __volatile__ => 0x08014410 <arm_switchcontext+10>: 00 df svc 0
sp is as follows:
sp 0x20036d4c 0x20036d4c
In the exception entry (due to SVC)
After the SVC happens, NuttX calculates the previous sp (before exc) and stores it to r2
157 add r2, #HW_XCPT_SIZE /* R2=MSP/PSP before the interrupt was taken */ => 0x0800821a <exception_common+17>: 02 f1 68 02 add.w r2, r2, #104 ; 0x68
r2 is as follows:
r2 0x20036d48 537095496
Workaround
The workaround below solves the problem by adding the offset to the sp stored by NuttX. Afterwards the bt works again. A complete solution is to discuss the topic with the NuttX guys.