If you caught Hard Fault exception and the PC value stacked for the exception points to the next instruction of SVC call, then there may be problem in Base priority(BASEPRI) value or Exception Masking Register (PRIMASK) value. The causes and corresponding solutions can be cosidered as follows:
Cause 1) : SVC priority has been masked by Base Priority Mask Register (BASEPRI) :
If SVC is executed from the context which has higher priority than SVC, Hard Fault Exception will occur. An example is, SVC is executed from a Task where BASEPRI value is set lower or equal to the SVC priority value set by System Handler Priority Register 2. Another example is, SVC is executed from a interrupt service routine of higher priority interrupt than SVC.
To solve this, always initialize the SVC priority to be higher than the executing contexts.
Cause 2) : SVC has been disabled through Exception Masking Register (PRIMASK
= 1) :
When PRIMASK register is set to 1, only NMI and Hard Fault Exceptions are allowed. If SVC is executed when PRIMASK is set to 1, HardFault Exception will occur.
To solve this, instead of using PRIMASK to mask interrupts, use BASEPRI to mask particular interrupts.
Put your comments to improve this post!
embedded techniques for everyone ; solve atleast one problem of the world a day ; provide the world what you do not get ; invent and service the world
Saturday, March 24, 2012
Cortex-M3/M4: Hardfault at SVC instruction
Subscribe to:
Post Comments (Atom)
5 comments:
Just had this exact problem. Your post helped a lot, thanks!
Thanks, solved our problem
Me too. Thanks!
thanks
This just happened to me, your post made figuring it out much faster.
Post a Comment