I have implemented a context switching code. For going back to privileged user mode after setting the return value in SP + 0x18 address, I am using BX LR instruction.
But code execution goes to HardFault handler and INVPC bit of USAFAULT register is set.
Following is the status of CPU registers just before executing the BX LR instruction. Address (0x100EFA34) saved at SP+0x18 is a valid address where I want PC to go
In my case, HardFault was triggered from the SV Call context (Case 2). After taking some necessary actions(Loading new context) I have to return from HardFault exception using BX LR. But SYSCALLACT bit in SCB->SHCSR register was still active.Now I am clearing the SYSCALLACT bit in SCB->SHCSR register when HardFault is triggered from an SV Call context. This has solved the issue.