Functional self-test for the CPUSS SMPU (shared memory protection unit) programmed through the PDL Cy_Prot_*SmpuSlaveStruct() API.
The SMPU denied write is reported by two independent mechanisms that the self-test relies on:
CPUSS_MPU_VIO SysFault latched in a FAULT_STRUCT (STATUS carries the source and DATA0 the violating address), which the self-test reads back by polling the fault structure directly - this proves the SMPU detected the violation, andBusFault_Handler forwards to SelfTest_SMPU_HandleBusFault so execution recovers in place instead of escalating to a HardFault.The self-test borrows one low, disabled SMPU slave struct and temporarily configures it over an application-provided 256-byte scratch block so that only a protection context different from the one the accessing bus master currently runs at is allowed. It then attempts a privileged write to the first word of that block and verifies that:
CPUSS_MPU_VIO SysFault source is observed, andFault model: the SMPU fails to deny a write it is configured to deny, or fails to report the violation. One call checks one path end to end at startup:
ENABLED, and the PC_MASK check that denies the calling core's active protection context while one other context is allowed.DATA0 equal to the accessed address, and the bus error returned to the CPU as a BusFault.Other cases are not covered, in particular: denial by the permission attributes (user/privileged read, write, execute), the secure attribute, pcMatch, subregions, other region sizes, the application's own SMPU slave structs and their priority, SMPU master structs, and accesses by other bus masters. Call SelfTest_SMPU() once per safety-related memory area, with a scratch block in that area and the matching stl_smpu_entry_t::expectedFault.
The self-test verifies the SMPU at startup only. Faults that occur after startup are not detected by this self-test.
BusFault_Handler. This module does not install a strong BusFault_Handler and does not override the application's vector table. The application must provide a small assembly-level trampoline that uses EXC_RETURN to pick the active exception stack (MSP or PSP) and forwards the frame pointer to a C dispatcher that calls SelfTest_SMPU_HandleBusFault():SelfTest_SMPU_HandleBusFault returns true only for the deliberate denied write driven by SelfTest_SMPU. For every other BusFault it returns false with CFSR and BFAR untouched, so the application's normal fault policy can inspect and handle it.
noinline / inline=never on both the trampoline and its C dispatcher.used (GCC / ARM) or __root (IAR) on the trampoline so the linker keeps it even when the vector-table reference is a pure data relocation that LTO does not see as a code reference.#pragma required=<dispatcher-name> (IAR only) to keep the C dispatcher from being dead-code-eliminated when nothing but the naked trampoline references it. API Reference | |
| Macros | |
| Data Structures | |
| Functions | |