Cortex M3: Hard fault, find the origin of the fault.

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Cortex M3: Hard fault, find the origin of the fault.

    Dear all,
    I'm using PowerPac 3.80g / Ewarm 5.40 on STM32F101 Cortex M3 target.
    I want to find where the processor enters the hardfault handler. I wrote a small code to display on LCD:
    R0 0X12345678 Hard
    R1 0X12345678 Fault!
    R2 0X12345678
    R3 0X12345678
    R12 0X12345678
    LR 0X12345678
    PC 0X12345678
    SR 0X12345678
    everything is OK, the values are the same as in the debugger window. That's fine, because the problem arises on EMC perturbations on the field and I can't use the debugger.
    Question:
    When entering in the handler, the displayed values lead to the OS library, where can I find the PC and/or the task running at this time ?
    Regards
    JLuc

    PSP and MSP pointers were swapped in my program. See working code on EWARM 5.40 hereafter (another compiler may push some register before calling save_fault_cpu_state() .
    Regards,
    Jluc

    C Source Code

    1. uint32_t stack[8]; /* uint32_t is unsigned long in S/T libraries */
    2. void save_fault_cpu_state(uint32_t * stack_ptr){
    3. OS_TASK* pRunningTask;
    4. stack[0]= *stack_ptr++; /* R0 */
    5. stack[1]= *stack_ptr++; /* R1 */
    6. stack[2]= *stack_ptr++; /* R2 */
    7. stack[3]= *stack_ptr++; /* R3 */
    8. stack[4]= *stack_ptr++; /* R12 */
    9. stack[5]= *stack_ptr++; /* LR */
    10. stack[6]= *stack_ptr++; /* PC */
    11. stack[7]= *stack_ptr; /* PSR */
    12. // Display or printf
    13. // Get the running task name
    14. pRunningTask = OS_GetpCurrentTask();/* get ptr */
    15. printf("%s",pRunningTask->Name);
    16. }
    17. void HardFault_Handler(void)
    18. {
    19. save_fault_cpu_state((uint32_t *) __get_PSP()); /* It's the IAR's way to get PSP value */
    20. /* Go to infinite loop when Hard Fault exception occurs */
    21. while (1)
    22. {
    23. }
    24. }
    Display All

    The post was edited 1 time, last by JLuc ().