|
STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
|
SCB and FPU context-control registers (PM0214, SCB and FPU chapters). More...
#include <stdint.h>Go to the source code of this file.
Data Structures | |
| struct | ScbRegisters_t |
| SCB register block. More... | |
| struct | FpuRegisters_t |
| FPU context-control register block. More... | |
Macros | |
| #define | SCB_BASE (0xE000ED00UL) |
| SCB base address (System Control Space). | |
| #define | FPU_BASE (0xE000EF34UL) |
| FPU context-control base address (System Control Space). | |
| #define | SCB ((ScbRegisters_t *)SCB_BASE) |
| The SCB instance. | |
| #define | FPU ((FpuRegisters_t *)FPU_BASE) |
| The FPU context-control instance. | |
AIRCR - application interrupt and reset control (0x0C) | |
Every write must carry SCB_AIRCR_VECTKEY_WRITE or it is ignored. | |
| #define | SCB_AIRCR_VECTRESET_Pos (0U) |
| Bit 0. | |
| #define | SCB_AIRCR_VECTRESET ((uint32_t)1U << SCB_AIRCR_VECTRESET_Pos) |
| wo Local reset; for debug use only. | |
| #define | SCB_AIRCR_SYSRESETREQ_Pos (2U) |
| Bit 2. | |
| #define | SCB_AIRCR_SYSRESETREQ ((uint32_t)1U << SCB_AIRCR_SYSRESETREQ_Pos) |
| wo Request a system reset. | |
| #define | SCB_AIRCR_PRIGROUP_Pos (8U) |
| Bits 10:8. | |
| #define | SCB_AIRCR_PRIGROUP_Msk ((uint32_t)0x7U << SCB_AIRCR_PRIGROUP_Pos) |
| rw Priority grouping; Reset_Handler sets 3 (all 4 bits preempt). | |
| #define | SCB_AIRCR_VECTKEY_Pos (16U) |
| Bits 31:16. | |
| #define | SCB_AIRCR_VECTKEY_Msk ((uint32_t)0xFFFFU << SCB_AIRCR_VECTKEY_Pos) |
| rw Write key; reads back 0xFA05. | |
| #define | SCB_AIRCR_VECTKEY_WRITE ((uint32_t)0x5FAU << SCB_AIRCR_VECTKEY_Pos) |
| Key value that makes an AIRCR write take effect. | |
ICSR - interrupt control and state (0x04) | |
| #define | SCB_ICSR_VECTACTIVE_Pos (0U) |
| Bits 8:0. | |
| #define | SCB_ICSR_VECTACTIVE_Msk ((uint32_t)0x1FFU << SCB_ICSR_VECTACTIVE_Pos) |
| ro Number of the active exception (0 in Thread mode). | |
| #define | SCB_ICSR_PENDSTCLR_Pos (25U) |
| Bit 25. | |
| #define | SCB_ICSR_PENDSTCLR ((uint32_t)1U << SCB_ICSR_PENDSTCLR_Pos) |
| wo Clear a pending SysTick. | |
| #define | SCB_ICSR_PENDSTSET_Pos (26U) |
| Bit 26. | |
| #define | SCB_ICSR_PENDSTSET ((uint32_t)1U << SCB_ICSR_PENDSTSET_Pos) |
| rw Pend SysTick; reads 1 while pending. | |
| #define | SCB_ICSR_PENDSVCLR_Pos (27U) |
| Bit 27. | |
| #define | SCB_ICSR_PENDSVCLR ((uint32_t)1U << SCB_ICSR_PENDSVCLR_Pos) |
| wo Clear a pending PendSV. | |
| #define | SCB_ICSR_PENDSVSET_Pos (28U) |
| Bit 28. | |
| #define | SCB_ICSR_PENDSVSET ((uint32_t)1U << SCB_ICSR_PENDSVSET_Pos) |
| rw Pend PendSV (requests a context switch); reads 1 while pending. | |
SCR - system control (0x10) | |
Every bit is rw. | |
| #define | SCB_SCR_SLEEPONEXIT_Pos (1U) |
| Bit 1. | |
| #define | SCB_SCR_SLEEPONEXIT ((uint32_t)1U << SCB_SCR_SLEEPONEXIT_Pos) |
| Sleep on return from an exception to Thread mode. | |
| #define | SCB_SCR_SLEEPDEEP_Pos (2U) |
| Bit 2. | |
| #define | SCB_SCR_SLEEPDEEP ((uint32_t)1U << SCB_SCR_SLEEPDEEP_Pos) |
| WFI/WFE enters deep sleep. | |
| #define | SCB_SCR_SEVONPEND_Pos (4U) |
| Bit 4. | |
| #define | SCB_SCR_SEVONPEND ((uint32_t)1U << SCB_SCR_SEVONPEND_Pos) |
| A pended interrupt wakes WFE. | |
CCR - configuration and control (0x14) | |
Every bit is rw. | |
| #define | SCB_CCR_NONBASETHRDENA_Pos (0U) |
| Bit 0. | |
| #define | SCB_CCR_NONBASETHRDENA ((uint32_t)1U << SCB_CCR_NONBASETHRDENA_Pos) |
| Allow Thread mode entry from any exception level. | |
| #define | SCB_CCR_USERSETMPEND_Pos (1U) |
| Bit 1. | |
| #define | SCB_CCR_USERSETMPEND ((uint32_t)1U << SCB_CCR_USERSETMPEND_Pos) |
| Allow unprivileged code to write STIR. | |
| #define | SCB_CCR_UNALIGN_TRP_Pos (3U) |
| Bit 3. | |
| #define | SCB_CCR_UNALIGN_TRP ((uint32_t)1U << SCB_CCR_UNALIGN_TRP_Pos) |
| Trap unaligned accesses. | |
| #define | SCB_CCR_DIV_0_TRP_Pos (4U) |
| Bit 4. | |
| #define | SCB_CCR_DIV_0_TRP ((uint32_t)1U << SCB_CCR_DIV_0_TRP_Pos) |
| Trap divide by zero. | |
| #define | SCB_CCR_BFHFNMIGN_Pos (8U) |
| Bit 8. | |
| #define | SCB_CCR_BFHFNMIGN ((uint32_t)1U << SCB_CCR_BFHFNMIGN_Pos) |
| Ignore data bus faults in HardFault, NMI and FAULTMASK handlers. | |
| #define | SCB_CCR_STKALIGN_Pos (9U) |
| Bit 9. | |
| #define | SCB_CCR_STKALIGN ((uint32_t)1U << SCB_CCR_STKALIGN_Pos) |
| Align the stack to 8 bytes on exception entry. | |
SHCSR - system handler control and state (0x24) | |
Every bit is rw: ACT = active, PENDED = pending, ENA = enabled. | |
| #define | SCB_SHCSR_MEMFAULTACT_Pos (0U) |
| Bit 0. | |
| #define | SCB_SHCSR_MEMFAULTACT ((uint32_t)1U << SCB_SHCSR_MEMFAULTACT_Pos) |
| MemManage active. | |
| #define | SCB_SHCSR_BUSFAULTACT_Pos (1U) |
| Bit 1. | |
| #define | SCB_SHCSR_BUSFAULTACT ((uint32_t)1U << SCB_SHCSR_BUSFAULTACT_Pos) |
| BusFault active. | |
| #define | SCB_SHCSR_USGFAULTACT_Pos (3U) |
| Bit 3. | |
| #define | SCB_SHCSR_USGFAULTACT ((uint32_t)1U << SCB_SHCSR_USGFAULTACT_Pos) |
| UsageFault active. | |
| #define | SCB_SHCSR_SVCALLACT_Pos (7U) |
| Bit 7. | |
| #define | SCB_SHCSR_SVCALLACT ((uint32_t)1U << SCB_SHCSR_SVCALLACT_Pos) |
| SVCall active. | |
| #define | SCB_SHCSR_PENDSVACT_Pos (10U) |
| Bit 10. | |
| #define | SCB_SHCSR_PENDSVACT ((uint32_t)1U << SCB_SHCSR_PENDSVACT_Pos) |
| PendSV active. | |
| #define | SCB_SHCSR_SYSTICKACT_Pos (11U) |
| Bit 11. | |
| #define | SCB_SHCSR_SYSTICKACT ((uint32_t)1U << SCB_SHCSR_SYSTICKACT_Pos) |
| SysTick active. | |
| #define | SCB_SHCSR_USGFAULTPENDED_Pos (12U) |
| Bit 12. | |
| #define | SCB_SHCSR_USGFAULTPENDED ((uint32_t)1U << SCB_SHCSR_USGFAULTPENDED_Pos) |
| UsageFault pending. | |
| #define | SCB_SHCSR_MEMFAULTPENDED_Pos (13U) |
| Bit 13. | |
| #define | SCB_SHCSR_MEMFAULTPENDED ((uint32_t)1U << SCB_SHCSR_MEMFAULTPENDED_Pos) |
| MemManage pending. | |
| #define | SCB_SHCSR_BUSFAULTPENDED_Pos (14U) |
| Bit 14. | |
| #define | SCB_SHCSR_BUSFAULTPENDED ((uint32_t)1U << SCB_SHCSR_BUSFAULTPENDED_Pos) |
| BusFault pending. | |
| #define | SCB_SHCSR_SVCALLPENDED_Pos (15U) |
| Bit 15. | |
| #define | SCB_SHCSR_SVCALLPENDED ((uint32_t)1U << SCB_SHCSR_SVCALLPENDED_Pos) |
| SVCall pending. | |
| #define | SCB_SHCSR_MEMFAULTENA_Pos (16U) |
| Bit 16. | |
| #define | SCB_SHCSR_MEMFAULTENA ((uint32_t)1U << SCB_SHCSR_MEMFAULTENA_Pos) |
| Enable MemManage (otherwise it escalates to HardFault). | |
| #define | SCB_SHCSR_BUSFAULTENA_Pos (17U) |
| Bit 17. | |
| #define | SCB_SHCSR_BUSFAULTENA ((uint32_t)1U << SCB_SHCSR_BUSFAULTENA_Pos) |
| Enable BusFault (otherwise it escalates to HardFault). | |
| #define | SCB_SHCSR_USGFAULTENA_Pos (18U) |
| Bit 18. | |
| #define | SCB_SHCSR_USGFAULTENA ((uint32_t)1U << SCB_SHCSR_USGFAULTENA_Pos) |
| Enable UsageFault (otherwise it escalates to HardFault). | |
CFSR - configurable fault status (0x28) | |
Bits 7:0 are MMFSR, 15:8 BFSR, 31:16 UFSR. Every bit is rc_w1. | |
| #define | SCB_CFSR_IACCVIOL_Pos (0U) |
| Bit 0. | |
| #define | SCB_CFSR_IACCVIOL ((uint32_t)1U << SCB_CFSR_IACCVIOL_Pos) |
| MemManage: instruction access violation. | |
| #define | SCB_CFSR_DACCVIOL_Pos (1U) |
| Bit 1. | |
| #define | SCB_CFSR_DACCVIOL ((uint32_t)1U << SCB_CFSR_DACCVIOL_Pos) |
| MemManage: data access violation; MMFAR holds the address if MMARVALID. | |
| #define | SCB_CFSR_MUNSTKERR_Pos (3U) |
| Bit 3. | |
| #define | SCB_CFSR_MUNSTKERR ((uint32_t)1U << SCB_CFSR_MUNSTKERR_Pos) |
| MemManage: fault while unstacking on exception return. | |
| #define | SCB_CFSR_MSTKERR_Pos (4U) |
| Bit 4. | |
| #define | SCB_CFSR_MSTKERR ((uint32_t)1U << SCB_CFSR_MSTKERR_Pos) |
| MemManage: fault while stacking on exception entry. | |
| #define | SCB_CFSR_MLSPERR_Pos (5U) |
| Bit 5. | |
| #define | SCB_CFSR_MLSPERR ((uint32_t)1U << SCB_CFSR_MLSPERR_Pos) |
| MemManage: fault during lazy FP state preservation. | |
| #define | SCB_CFSR_MMARVALID_Pos (7U) |
| Bit 7. | |
| #define | SCB_CFSR_MMARVALID ((uint32_t)1U << SCB_CFSR_MMARVALID_Pos) |
| MMFAR holds a valid fault address. | |
| #define | SCB_CFSR_IBUSERR_Pos (8U) |
| Bit 8. | |
| #define | SCB_CFSR_IBUSERR ((uint32_t)1U << SCB_CFSR_IBUSERR_Pos) |
| BusFault: instruction fetch. | |
| #define | SCB_CFSR_PRECISERR_Pos (9U) |
| Bit 9. | |
| #define | SCB_CFSR_PRECISERR ((uint32_t)1U << SCB_CFSR_PRECISERR_Pos) |
| BusFault: precise data access; BFAR holds the address if BFARVALID. | |
| #define | SCB_CFSR_IMPRECISERR_Pos (10U) |
| Bit 10. | |
| #define | SCB_CFSR_IMPRECISERR ((uint32_t)1U << SCB_CFSR_IMPRECISERR_Pos) |
| BusFault: imprecise data access (no address). | |
| #define | SCB_CFSR_UNSTKERR_Pos (11U) |
| Bit 11. | |
| #define | SCB_CFSR_UNSTKERR ((uint32_t)1U << SCB_CFSR_UNSTKERR_Pos) |
| BusFault: fault while unstacking on exception return. | |
| #define | SCB_CFSR_STKERR_Pos (12U) |
| Bit 12. | |
| #define | SCB_CFSR_STKERR ((uint32_t)1U << SCB_CFSR_STKERR_Pos) |
| BusFault: fault while stacking on exception entry. | |
| #define | SCB_CFSR_LSPERR_Pos (13U) |
| Bit 13. | |
| #define | SCB_CFSR_LSPERR ((uint32_t)1U << SCB_CFSR_LSPERR_Pos) |
| BusFault: fault during lazy FP state preservation. | |
| #define | SCB_CFSR_BFARVALID_Pos (15U) |
| Bit 15. | |
| #define | SCB_CFSR_BFARVALID ((uint32_t)1U << SCB_CFSR_BFARVALID_Pos) |
| BFAR holds a valid fault address. | |
| #define | SCB_CFSR_UNDEFINSTR_Pos (16U) |
| Bit 16. | |
| #define | SCB_CFSR_UNDEFINSTR ((uint32_t)1U << SCB_CFSR_UNDEFINSTR_Pos) |
| UsageFault: undefined instruction. | |
| #define | SCB_CFSR_INVSTATE_Pos (17U) |
| Bit 17. | |
| #define | SCB_CFSR_INVSTATE ((uint32_t)1U << SCB_CFSR_INVSTATE_Pos) |
| UsageFault: invalid EPSR state (for example a Thumb bit of 0). | |
| #define | SCB_CFSR_INVPC_Pos (18U) |
| Bit 18. | |
| #define | SCB_CFSR_INVPC ((uint32_t)1U << SCB_CFSR_INVPC_Pos) |
| UsageFault: invalid PC load or EXC_RETURN. | |
| #define | SCB_CFSR_NOCP_Pos (19U) |
| Bit 19. | |
| #define | SCB_CFSR_NOCP ((uint32_t)1U << SCB_CFSR_NOCP_Pos) |
| UsageFault: coprocessor (FPU) access while disabled in CPACR. | |
| #define | SCB_CFSR_UNALIGNED_Pos (24U) |
| Bit 24. | |
| #define | SCB_CFSR_UNALIGNED ((uint32_t)1U << SCB_CFSR_UNALIGNED_Pos) |
| UsageFault: unaligned access with CCR.UNALIGN_TRP set. | |
| #define | SCB_CFSR_DIVBYZERO_Pos (25U) |
| Bit 25. | |
| #define | SCB_CFSR_DIVBYZERO ((uint32_t)1U << SCB_CFSR_DIVBYZERO_Pos) |
| UsageFault: divide by zero with CCR.DIV_0_TRP set. | |
HFSR - HardFault status (0x2C) | |
Every bit is rc_w1. | |
| #define | SCB_HFSR_VECTTBL_Pos (1U) |
| Bit 1. | |
| #define | SCB_HFSR_VECTTBL ((uint32_t)1U << SCB_HFSR_VECTTBL_Pos) |
| Bus fault while reading the vector table. | |
| #define | SCB_HFSR_FORCED_Pos (30U) |
| Bit 30. | |
| #define | SCB_HFSR_FORCED ((uint32_t)1U << SCB_HFSR_FORCED_Pos) |
| A configurable fault escalated to HardFault; see CFSR. | |
| #define | SCB_HFSR_DEBUGEVT_Pos (31U) |
| Bit 31. | |
| #define | SCB_HFSR_DEBUGEVT ((uint32_t)1U << SCB_HFSR_DEBUGEVT_Pos) |
| Debug event. | |
SHPR1-3 - system handler priorities (0x18-0x20) | |
One rw byte per handler; only the top 4 bits are implemented. | |
| #define | SCB_SHPR1_PRI_4_Pos (0U) |
| Bits 7:0. | |
| #define | SCB_SHPR1_PRI_4_Msk ((uint32_t)0xFFU << SCB_SHPR1_PRI_4_Pos) |
| MemManage priority. | |
| #define | SCB_SHPR1_PRI_5_Pos (8U) |
| Bits 15:8. | |
| #define | SCB_SHPR1_PRI_5_Msk ((uint32_t)0xFFU << SCB_SHPR1_PRI_5_Pos) |
| BusFault priority. | |
| #define | SCB_SHPR1_PRI_6_Pos (16U) |
| Bits 23:16. | |
| #define | SCB_SHPR1_PRI_6_Msk ((uint32_t)0xFFU << SCB_SHPR1_PRI_6_Pos) |
| UsageFault priority. | |
| #define | SCB_SHPR2_PRI_11_Pos (24U) |
| Bits 31:24. | |
| #define | SCB_SHPR2_PRI_11_Msk ((uint32_t)0xFFU << SCB_SHPR2_PRI_11_Pos) |
| SVCall priority. | |
| #define | SCB_SHPR3_PRI_14_Pos (16U) |
| Bits 23:16. | |
| #define | SCB_SHPR3_PRI_14_Msk ((uint32_t)0xFFU << SCB_SHPR3_PRI_14_Pos) |
| PendSV priority. | |
| #define | SCB_SHPR3_PRI_15_Pos (24U) |
| Bits 31:24. | |
| #define | SCB_SHPR3_PRI_15_Msk ((uint32_t)0xFFU << SCB_SHPR3_PRI_15_Pos) |
| SysTick priority. | |
CPACR - coprocessor access control (0x88) | |
| #define | SCB_CPACR_CP10_Pos (20U) |
| Bits 21:20. | |
| #define | SCB_CPACR_CP10_Msk ((uint32_t)0x3U << SCB_CPACR_CP10_Pos) |
| rw FPU access (CP10); 0b11 = full. | |
| #define | SCB_CPACR_CP11_Pos (22U) |
| Bits 23:22. | |
| #define | SCB_CPACR_CP11_Msk ((uint32_t)0x3U << SCB_CPACR_CP11_Pos) |
| rw FPU access (CP11); must match CP10. | |
EXC_RETURN values | |
The LR value on exception entry; branching to it returns (PM0214 Table 2-17). The _FPU variants pop an extended frame with FPU state. | |
| #define | EXC_RETURN_HANDLER (0xFFFFFFF1UL) |
| Handler mode, MSP, basic frame. | |
| #define | EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) |
| Thread mode, MSP, basic frame. | |
| #define | EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) |
| Thread mode, PSP, basic frame. | |
| #define | EXC_RETURN_HANDLER_FPU (0xFFFFFFE1UL) |
| Handler mode, MSP, extended frame. | |
| #define | EXC_RETURN_THREAD_MSP_FPU (0xFFFFFFE9UL) |
| Thread mode, MSP, extended frame. | |
| #define | EXC_RETURN_THREAD_PSP_FPU (0xFFFFFFEDUL) |
| Thread mode, PSP, extended frame. | |
FPCCR - FP context control (0xE000EF34) | |
| #define | FPU_FPCCR_LSPACT_Pos (0U) |
| Bit 0. | |
| #define | FPU_FPCCR_LSPACT ((uint32_t)1U << FPU_FPCCR_LSPACT_Pos) |
| rw Lazy state preservation is active: space is reserved but FP state not saved. | |
| #define | FPU_FPCCR_LSPEN_Pos (30U) |
| Bit 30. | |
| #define | FPU_FPCCR_LSPEN ((uint32_t)1U << FPU_FPCCR_LSPEN_Pos) |
| rw Enable lazy FP context stacking (reset value 1). | |
| #define | FPU_FPCCR_ASPEN_Pos (31U) |
| Bit 31. | |
| #define | FPU_FPCCR_ASPEN ((uint32_t)1U << FPU_FPCCR_ASPEN_Pos) |
| rw Save FP state automatically on exception entry (reset value 1). | |
Typedefs | |
| typedef struct ScbRegisters_t | ScbRegisters_t |
| SCB register block. | |
| typedef struct FpuRegisters_t | FpuRegisters_t |
| FPU context-control register block. | |
SCB and FPU context-control registers (PM0214, SCB and FPU chapters).
Covers what fault handling and a PendSV context switch need: exception control and status, fault status, handler priorities, EXC_RETURN values and FPU enable/lazy stacking. The CPU feature registers (0x40-0x84) are not modelled. FPCCR/FPCAR/FPDSCR live at 0xE000EF34, past the MPU, so they have their own block.
Definition in file scb_reg.h.