Skip to content

arch: arm: cortex_m: scb: Consolidate SCB APIs and add backup/restore functions (2nd attempt) #93699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mathieuchopstm
Copy link
Contributor

CMSIS 5 had a different name for the SHP/SHPR registers depending on which Cortex-M was used. This inconsistency is fixed in CMSIS 6, which is the new default for Cortex-M in Zephyr.

Remove the conditional and always use SHPR in the SCB backup/restore code.

Should fix example-application breakage as seen here https://github.com/zephyrproject-rtos/example-application/actions/runs/16510871831

@mathieuchopstm mathieuchopstm added the Hotfix Fix for issues blocking development, i.e. CI issues, tests failing in CI, etc. label Jul 25, 2025
@zephyrbot zephyrbot added the area: ARM ARM (32-bit) Architecture label Jul 25, 2025
@mathieuchopstm
Copy link
Contributor Author

For some reason, CI adds both CMSIS 5 and CMSIS 6 to include path in this order. Because CMSIS 5 comes first, its outdated definitions are taken and build is broken:
image

On the other hand, example-application CI picks up only CMSIS 6 as expected:
image

fabiobaltieri
fabiobaltieri previously approved these changes Jul 25, 2025
@mathieuchopstm
Copy link
Contributor Author

Keeping this open for re-introduction of #93161 when CI issues are fixed.

@mathieuchopstm mathieuchopstm added DNM This PR should not be merged (Do Not Merge) and removed Hotfix Fix for issues blocking development, i.e. CI issues, tests failing in CI, etc. labels Jul 25, 2025
@fabiobaltieri
Copy link
Member

sure just trying to figure why both cmsis path are included, doubt it's intentional, the example application does not checkout cmsis, it only has cmsis_6 in manifest so it works there

@fabiobaltieri
Copy link
Member

fabiobaltieri commented Jul 25, 2025

would be also nice to understand why CI did not catch it, has to be an interaction with something else that got merged in the meantime --- oh I see now, it only works with both cmsis packages

@mathieuchopstm
Copy link
Contributor Author

would be also nice to understand why CI did not catch it, has to be an interaction with something else that got merged in the meantime --- oh I see now, it only works with both cmsis packages

More specifically, CI has both modules/hal/cmsis and modules/hal/cmsis_6 in include path and - more critically - cmsis (CMSIS 5) comes first in include order.

@msmttchr's PR was written with CMSIS 5 in mind so CI was all but happy 🙂

@wearyzen
Copy link
Contributor

For some reason, CI adds both CMSIS 5 and CMSIS 6 to include path in this order. Because CMSIS 5 comes first, its outdated definitions are taken and build is broken: image

On the other hand, example-application CI picks up only CMSIS 6 as expected: image

Sorry about this, its my fault for suggesting to use SHP and SHPR. Initially when the PR was just using SHPR, I think CI reported an error and I too ran the PR locally to see the SHPR error but I missed that it was specific from CMSIS and not CMSIS_6.

@fabiobaltieri
Copy link
Member

Sorry about this, its my fault for suggesting to use SHP and SHPR. Initially when the PR was just using SHPR, I think CI reported an error and I too ran the PR locally to see the SHPR error but I missed that it was specific from CMSIS and not CMSIS_6.

Nah don't worry about it, it's really a CI setup shortcoming let's make sure to fix that, opened #93715 for it

Add new API to save and restore SCB context. This is typically useful when
entering and exiting suspend-to-RAM low-power modes.

The scb_context_t and the backup/restore functions are designed to only
handle SCB registers that are:
- Mutable: Their values can be changed by software.
- Configurable: They control system behavior or features.
- Stateful: Their values represent a specific configuration that an
            application might want to preserve and restore.

Registers excluded from backup/restore are:
1. CPU/feature identification registers
	Motivation: These registers are fixed in hardware and read-only.
2. ICSR (Interrupt Control and State Register)
	Motivation: Most bits of ICSR bits are read-only or write-only
	and represent volatile system state. STTNS is the only read-write
	field and could be considered part of the system state, but it is
	only present on certain ARMv8-M CPUs, and Zephyr does not use it.
3. CFSR (Configurable Fault Status Register)
   HFSR (HardFault Status Register)
   DFSR (Debug Fault Status Register)
   AFSR (Auxiliary Fault Status Register)
   MMFAR (MemManage Fault Address Register)
   BFAR (BusFault Address Register)
	Motivation: These registers are read/write-one-to-clear and
	contain only fault-related information (which is volatile).

Signed-off-by: Mathieu Choplain <[email protected]>
Co-authored-by: Michele Sardo <[email protected]>
@mathieuchopstm mathieuchopstm force-pushed the hotfix_arm_scb_bkp_restore branch from 6d9f2b4 to 608a5ec Compare July 25, 2025 14:44
@mathieuchopstm mathieuchopstm changed the title arch: arm: cortex_m: scb: use SHPR name for all Cortex-M arch: arm: cortex_m: scb: Consolidate SCB APIs and add backup/restore functions (2nd attempt) Jul 25, 2025
@zephyrbot zephyrbot requested review from dcpleung and nashif July 25, 2025 14:45
@mathieuchopstm
Copy link
Contributor Author

Pushed cleaned-up code from #93161 that should be OK for integration once CI uses CMSIS 6.

Copy link

@msmttchr
Copy link
Contributor

@mathieuchopstm, thanks for this PR!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Architectures area: ARM ARM (32-bit) Architecture DNM This PR should not be merged (Do Not Merge)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants