This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Usage fault with PSP = 0x00000020

Hello,

I have a project with RTX with 3 threads (main + 2 declared by me) + of course the idle one. The main thread enters wait state after starting the two threads so i have just two threads running. The RTX has round robin disabled. What the application does is talk to a a Bluetooth module over SPI.

My problem is that sometimes, during the SPI transfer (initiated by one thread and done in the other)the MCU crashes into the UsageFault_Handler and one of the threads (not always the same) is shown to overflow. Now I have read about how to debug the hardfaults and what nots but the problem is that all of the methods rely on MSP/PSP addresses and for me the PSP is 0x00000020.

Anyone ever confronted with something similar? Any ideas on what might be wrong?

Thank you,
Sebastian

  • Most likely after the context of one of your tasks is saved, the "saved" USP is overwritten.

    You may want to look at the UsageFault Status Register (UFSR). It might be helpful.

    Since the PSP is the value 0x00000020, my first thought is that the saved USP is overwritten with a 0.

    When this is recovered, 1/2 of the register restore can happen because it is in Handler Mode, and the actual values restored to {R4..R11} will not cause any fault. If you notice that R4..R11 contains the same data as your Vector Base, you will know it was rewritten with a 0.

    After recovering the 0, restoring 8 registers, the recovered PSP + 0x00000020 will be up into the actual PSP. Then a return from interrupt is executed to go back to thread mode. This part likely fails (UFSR should tell you why it failed, maybe Invalid state or Invalid PC)