This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Error in SVC handler in NRF52 SDK 0.9.1 with S132

I am using CMSIS RTOS (RTX) to implement an application for the NRF52 DK. I have found an error in the SVC handler that results in a hard fault when calling a soft device service call function from a thread that uses the FPU.

The hard fault occurs because the wrong stack pointer is selected by the SVC handler preamble. The relevant disassembly of the SVC handler is:

0x00000860:  mvn.w   r0, #2
0x00000864:  cmp     r0, lr
0x00000866:  bne.n   0x86e
0x00000868:  mrs     r1, PSP
0x0000086c:  b.n     0x872
0x0000086e:  mrs     r1, MSP

This code is intended to select the correct stack pointer to use based on the EXC_RETURN value in the link register. In the above implementation this is done by comparing the link register with the value 0xFFFFFFFD to tell if the PSP should be used. This is incorrect for the M4F core as the value 0xFFFFFFED also indicates that the PSP should be used. See Table 2.17 of the CortexTm-M4 Devices Generic User Guide. This case occurs when the processor has executed floating point instructions in the current thread context, indicated by the CONTROL.FPCA bit being set.

A better implementation would be to test for bit 3 in the link register being set to determine which stack pointer to use. See the ARM infocenter for more information.

Related