Skip to content

Conversation

@sumitbatra-nxp
Copy link
Contributor

@sumitbatra-nxp sumitbatra-nxp commented Oct 11, 2025

Title: mcux: C40 flash (S32K3x): run mutating ops from SRAM for XIP; add S32K344 array geometry header

Summary

This PR adds features header describing the C40 array geometry.

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.

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 sumit.batra@nxp.com

@sumitbatra-nxp sumitbatra-nxp changed the title C40 flash hal nxp 1 mcux: C40 flash (S32K3x): run mutating ops from SRAM for XIP; add S32K344 array geometry header Oct 11, 2025
@mmahadevan108
Copy link
Collaborator

@sumitbatra-nxp Please submit this change to the SDK team. I have provided you details on where to submit the PR via our chat channel.

@mmahadevan108
Copy link
Collaborator

Let us know once this is accepted by the SDK team and update this PR if needed.

@sumitbatra-nxp
Copy link
Contributor Author

Sure..

@sumitbatra-nxp
Copy link
Contributor Author

@manuargue @mmahadevan108 .. I have corrected all the comments from the SDK team and ones made by Manuel here.
I'll initiate an internal chat to decide if we should wait till the SDK code is merged or can we go ahead as is.

@sumitbatra-nxp
Copy link
Contributor Author

@mmahadevan108 .. All changes are complete and mcusdk PR is also marked as fixed

@mmahadevan108
Copy link
Collaborator

Awaiting approval from @manuargue before merging this.

@ZhaoxiangJin
Copy link
Collaborator

Hi @sumitbatra-nxp, could you please help to update README to record the patch, for examples: https://github.com/zephyrproject-rtos/hal_nxp/pull/597/files#diff-d76b726c36140769d6ad0c555299f9442e47a435a0758efde38d56c2ca775313R243? Thanks a lot.

- fsl_c40_flash.c: Initialize `ret` in FLASH_Erase() to
  `kStatus_FLASH_Success` to avoid potential use-before-set warnings on some
  toolchains/static analyzers (no functional change).

- S32K344_features.h: Define C40 array geometry for S32K344 using unsigned
  constants:
    * FSL_FEATURE_FLASH_C40_BLOCK_SIZE_CODE (1 MiB)
    * FSL_FEATURE_FLASH_C40_BLOCK_COUNT_CODE (4)
    * FSL_FEATURE_FLASH_C40_BLOCK_SIZE_DATA (256 KiB)
  Note: erase/program granularities are controller-level and handled by driver.

- S32K344_glue_mcux.h: Provide conditional aliases mapping FLASH↔IP_FLASH and
  PFLASH↔IP_PFLASH to harmonize SDK naming and improve build portability.

Signed-off-by: Sumit Batra <sumit.batra@nxp.com>
@sumitbatra-nxp
Copy link
Contributor Author

Hi @sumitbatra-nxp, could you please help to update README to record the patch, for examples: https://github.com/zephyrproject-rtos/hal_nxp/pull/597/files#diff-d76b726c36140769d6ad0c555299f9442e47a435a0758efde38d56c2ca775313R243? Thanks a lot.

@ZhaoxiangJin .. I tried adding something as per my understanding in the mcux/README, but I am not sure if that is what was required.

@sumitbatra-nxp sumitbatra-nxp changed the title mcux: C40 flash (S32K3x): run mutating ops from SRAM for XIP; add S32K344 array geometry header mcux: C40 flash (S32K3x): add S32K344 array geometry header, IP Aliases and Cleanup Oct 22, 2025
@ZhaoxiangJin
Copy link
Collaborator

Hi @sumitbatra-nxp, could you please help to update README to record the patch, for examples: https://github.com/zephyrproject-rtos/hal_nxp/pull/597/files#diff-d76b726c36140769d6ad0c555299f9442e47a435a0758efde38d56c2ca775313R243? Thanks a lot.

@ZhaoxiangJin .. I tried adding something as per my understanding in the mcux/README, but I am not sure if that is what was required.

The information is ok, thanks.

@mmahadevan108
Copy link
Collaborator

@manuargue , please revisit this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants