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

Nuvoton M2351 Keil RTX5 Hard faults on OS initialization

Hello,

I have a Nuvoton M2351 (Cortex-M23) and I am trying to get RTX5 to run on it. The board initialization, secure main code and switch to non-secure main runs correctly but a hard fault is always triggered whenever osKernelInitialize() is called by the non-secure main function. Specifically, when stepping through the function, it seems to occur when TZ_InitContextSystem_S() is called.

NonSecure.axf:

0x1004323a:    f000ff89    ....    BL       $Ven$TT$L$$TZ_InitContextSystem_S ; 0x10044150

...

$Ven$TT$L$$TZ_InitContextSystem_S
        0x10044150:    b403        ..      PUSH     {r0,r1}
        0x10044152:    4801        .H      LDR      r0,[pc,#4] ; [0x10044158] = 0x8f1
        0x10044154:    9001        ..      STR      r0,[sp,#4]
        0x10044156:    bd01        ..      POP      {r0,pc}

Secure.axf:

TZ_InitContextSystem_S
        0x000008f0:    e97fe97f    ....    SG        ; [0x6f8] = 0x4c1760042406600c
        0x000008f4:    f7ffbe3e    ..>.    B.W      __acle_se_TZ_InitContextSystem_S ; 0x574

The most interesting thing that occurs in my opinion is that the code jumps to the Hard Fault Handler right after the instruction at 0x1004323a is executed. I don't understand why this should occur since it is simply branching to 0x10044150 and should not trigger a hard fault.

Any reason why this is occurring?

Thank you

  • Figured out the solution. The SAU region was not defined for the TZ_InitContextSystem_S and the other functions and marked as "Secure, Non-Secure Callable". Although this doesn't completely answer my question as to why it jumps from a valid non-secure address (0x1004323a) into a hard fault handler and skips the 4 instructions from address 0x10044150, at least I am not stuck anymore.

    Hope this helps anyone who comes across a similar issue in the future.

    Thank you

  • If you are in Non-secure state and call a Secure API, the first instruction in the Secure API must be an SG instruction and it must be in a memory region marks as Non-secure Callable (NSC). Otherwise the processor will block the call and trigger HardFault (to prevent branching into the middle of Secure function).  If the SAU hasn't been initialized, the memory space where the SG is located is unlikely to be configured as NSC. Hence the HardFault is triggered.