mcux: C40 flash (S32K3x): run mutating ops from SRAM for XIP; add S32K344 array geometry header #618
+40
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title: mcux: C40 flash (S32K3x): run mutating ops from SRAM for XIP; add S32K344 array geometry header
Summary
This PR improves reliability of the MCUX C40 flash driver on XIP systems (e.g. S32K344) and adds a small features header describing the C40 array geometry.
What’s included
flash_c40: execute mutating ops from SRAM on XIP
Mark FLASH_Program(), FLASH_Erase(), and FLASH_SetSectorProtection() as __ramfunc so they run from SRAM when the code executes in place from internal flash.
Prevents stalls/faults caused by issuing flash commands while fetching instructions from the same flash array.
No behavior change on non-XIP builds.
flash_c40: add SoC features header
Introduces fsl_c40_flash_features.h with S32K344 C40 geometry (block sizes/counts).
Purely additive; intended for consumers (e.g., Zephyr internal-flash glue) that need compile-time array parameters.
Rationale
On Cortex-M XIP systems, flash program/erase/lock sequences must not execute from the same flash array they modify. Relocating these critical routines to SRAM is a standard mitigation that avoids bus contention and hard faults, especially under bootloader + application scenarios.
Compatibility
No public API changes.
__ramfunc (or the MCUX equivalent) is used; toolchains map it to an SRAM code section. On non-XIP builds, the attribute is effectively neutral.
Testing
Hardware: NXP S32K344 (MR-CANHUBK3).
Verified program/erase and sector protection operations via Zephyr flash_shell and MCUboot chain-load.
Confirmed stable execution with functions relocated to SRAM.
Follow-ups / Consumers
Zephyr driver glue for C40 uses this update; following Zephyr PR bumps west.yml to this HAL revision.
This PR is created to support Zephyr PR - zephyrproject-rtos/zephyr#97401
Signed-off-by: Sumit Batra [email protected]