SDAA473 November 2026 MSPM33C321A , MSPM33C321A-Q1
In the project, user can use NS_FUNC_ENTRY to definite the Non Secure Callable function.
The function itself does not reside in NSC region. The function is actually present in secure memory. NS_FUNC_ENTRY is defined as an atribute in the header file. This instructs the compiler to generate a "secure gateway veneer" which is nothing but :
later in the linker,
Veneer$$CMSE: {} > NSC_MEM
is present which will make this veneer go to the NSC region. The actual function implementation will go to secure region, as defined by the linker.
What the SG instruction is doing is changing the security state of the core from NS to S, banks the registers, sets bit[0] of LR register to 0, which indicates that the return will cause a transition back from S to NS
in short, SG is a privileged instruction which must be in NSC. The core understands that this means some NS program is requesting access to a S resource/code. And by design NS should not be able to simply change the core state to S.
In the secure example, NSC function is defined in nsc_example.c. There is also an nsc_example.h in non-secure example, so non-secure application can call the NSC function during runtime.
Figure 3-11 Definition of NSC Function in nsc_example.c of
Secure Application
Figure 3-12 Extern Definition of NSC Function in nsc_example.h
of Non-secure Application