-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Merged
kartben
merged 2 commits into
zephyrproject-rtos:main
from
mathieuchopstm:hotfix_arm_scb_bkp_restore
Aug 16, 2025
+192
−0
Merged
arch: arm: cortex_m: scb: Consolidate SCB APIs and add backup/restore functions (2nd attempt) #93699
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (c) 2025 STMicroelectronics | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* @file | ||
* @brief System control block context helpers for Cortex-M CPUs | ||
* | ||
* System control block context helpers for backup and restore | ||
*/ | ||
|
||
#ifndef ARM_CORTEX_M_SCB_H_ | ||
#define ARM_CORTEX_M_SCB_H_ | ||
|
||
#include <stdint.h> | ||
#include <cmsis_core.h> | ||
|
||
/* Define macros for CPU-conditional features */ | ||
#if defined(CONFIG_CPU_CORTEX_M0) || \ | ||
defined(CONFIG_CPU_CORTEX_M0PLUS) || \ | ||
defined(CONFIG_CPU_CORTEX_M1) || \ | ||
defined(CONFIG_CPU_CORTEX_M23) | ||
#define SHPR_SIZE_W 2 | ||
#else | ||
#define SHPR_SIZE_W 3 | ||
#define CPACR_PRESENT 1 | ||
#endif | ||
|
||
/** | ||
* @brief Structure to store essential, mutable SCB register values for backup/restore. | ||
* | ||
* This structure only contains SCB registers that are safe and meaningful to backup | ||
* and restore. In particular, registers that are read-only (such as CPUID) or contain | ||
* volatile information (ICSR / CFSR) are ignored, since their value is tied to the | ||
* system state or fixed in hardware, rather than related to a configuration option. | ||
*/ | ||
struct scb_context { | ||
#if defined(CONFIG_CPU_CORTEX_M_HAS_VTOR) | ||
uint32_t vtor; /*!< Vector Table Offset Register */ | ||
#endif | ||
uint32_t aircr; /*!< Application Interrupt and Reset Control Register */ | ||
uint32_t scr; /*!< System Control Register */ | ||
uint32_t ccr; /*!< Configuration Control Register */ | ||
uint32_t shpr[SHPR_SIZE_W]; /*!< System Handler Priority Registers */ | ||
uint32_t shcsr; /*!< System Handler Control and State Register */ | ||
#if defined(CPACR_PRESENT) | ||
uint32_t cpacr; /*!< Coprocessor Access Control Register */ | ||
#endif /* CPACR_PRESENT */ | ||
}; | ||
|
||
/** | ||
* @name SCB Register Backup/Restore Functions | ||
* @brief Functions for saving and restoring mutable SCB register state. | ||
* @{ | ||
*/ | ||
|
||
/** | ||
* @brief Save essential SCB registers into a provided context structure. | ||
* | ||
* This function reads the current values of critical System Control Block (SCB) | ||
* registers that are safe to backup and stores them into the `context` structure. | ||
* | ||
* @param context Pointer to an `scb_context` structure where the register | ||
* values will be stored. Must not be NULL. | ||
*/ | ||
void z_arm_save_scb_context(struct scb_context *context); | ||
|
||
/** | ||
* @brief Restores essential SCB registers from a provided context structure. | ||
* | ||
* This function writes the values from the `context` structure back to the | ||
* respective System Control Block (SCB) registers. | ||
* | ||
* @warning Extreme caution is advised when restoring SCB registers. Only | ||
* mutable registers are restored. Specifically, the ICSR register | ||
* is NOT restored directly due to its volatile nature and read-only/ | ||
* write-only bits. | ||
* | ||
* @param context Pointer to a `scb_context` structure containing the | ||
* register values to be restored. Must not be NULL. | ||
*/ | ||
void z_arm_restore_scb_context(const struct scb_context *context); | ||
|
||
/** @} */ | ||
|
||
#endif /* ARM_CORTEX_M_SCB_H_ */ |
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.
Uh oh!
There was an error while loading. Please reload this page.