CM33 HardFault when PendSV_Handler return

Sai 45 Reputation points
2023-08-04T09:08:08.6266667+00:00

Hi everyone,

I am new in Azure RTOS. I have linked libthreadx.a with BSP part but have running problems.

HardFault occurs when run the example. The assembly instruction generates HardFault is "bx lr" in _skip_secure_restore() and the function call flow is as followed

_tx_initialize_kernel_enter -> _tx__thread_sheduler -> PendSV_Handler -> __tx_ts_handler -> __tx_ts_new -> __tx_ts_restore ->_skip_secure_restore

When using "BX lr" return from PendSV exception, it enters HardFault.

    /* ports/cortex-m33/gnu/src/tx_thread_schedule.S */
	/* Restore the thread context and PSP.  */
    LDR     r12, [r1, #12]                          // Get stack start
    MSR     PSPLIM, r12                             // Set stack limit
    LDR     r12, [r1, #8]                           // Pickup thread's stack pointer
    LDMIA   r12!, {LR}                              // Pickup LR
#ifdef __ARM_FP
    TST     LR, #0x10                               // Determine if the VFP extended frame is present
    BNE     _skip_vfp_restore                       // If not, skip VFP restore
    VLDMIA  r12!, {s16-s31}                         // Yes, restore additional VFP registers
_skip_vfp_restore:
#endif
    LDMIA   r12!, {r4-r11}                          // Recover thread's registers
    MSR     PSP, r12                                // Setup the thread's stack pointer
	BX      lr                                      // Return to thread!

The cpsr value:

(gdb) x /x 0xE000ED28 0xe000ed28: 0x00040000

The EXC_RETURN value when "BX lr"

(gdb) i r $lr lr 0xffffffbc -68

It is UsageFault escalated to HardFault, the fault status INVPC: Invalid PC flag. Sticky flag indicating whether an integrity check error has occurred.

I have no idea about this error, I hope someone can provide some debugging ideas.

Thank you!

Azure RTOS
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
330 questions
{count} votes

Accepted answer
  1. LeelaRajeshSayana-MSFT 13,966 Reputation points
    2023-08-08T23:46:38.4533333+00:00

    Hi @Sai I'm glad that you were able to resolve your issue and thank you for posting your work around so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer .

    Error Message:

    HardFault occurs when run the example. The assembly instruction generates HardFault is "bx lr" in _skip_secure_restore()

    Solution:

    Bug caused by not booting with secure status. Adding "-DTX_SINGLE_MODE_NON_SECURE" helped to work around the issue.

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.

    I hope this helps!

    If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    0 comments No comments

0 additional answers

Sort by: Most helpful