STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_ll_cortex.h
Go to the documentation of this file.
1 
35 /* Define to prevent recursive inclusion -------------------------------------*/
36 #ifndef __STM32L4xx_LL_CORTEX_H
37 #define __STM32L4xx_LL_CORTEX_H
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /* Includes ------------------------------------------------------------------*/
44 #include "stm32l4xx.h"
45 
54 /* Private types -------------------------------------------------------------*/
55 /* Private variables ---------------------------------------------------------*/
56 
57 /* Private constants ---------------------------------------------------------*/
58 
59 /* Private macros ------------------------------------------------------------*/
60 
61 /* Exported types ------------------------------------------------------------*/
62 /* Exported constants --------------------------------------------------------*/
70 #define LL_SYSTICK_CLKSOURCE_HCLK_DIV8 0x00000000U
71 #define LL_SYSTICK_CLKSOURCE_HCLK SysTick_CTRL_CLKSOURCE_Msk
79 #define LL_HANDLER_FAULT_USG SCB_SHCSR_USGFAULTENA_Msk
80 #define LL_HANDLER_FAULT_BUS SCB_SHCSR_BUSFAULTENA_Msk
81 #define LL_HANDLER_FAULT_MEM SCB_SHCSR_MEMFAULTENA_Msk
86 #if __MPU_PRESENT
87 
91 #define LL_MPU_CTRL_HFNMI_PRIVDEF_NONE 0x00000000U
92 #define LL_MPU_CTRL_HARDFAULT_NMI MPU_CTRL_HFNMIENA_Msk
93 #define LL_MPU_CTRL_PRIVILEGED_DEFAULT MPU_CTRL_PRIVDEFENA_Msk
94 #define LL_MPU_CTRL_HFNMI_PRIVDEF (MPU_CTRL_HFNMIENA_Msk | MPU_CTRL_PRIVDEFENA_Msk)
102 #define LL_MPU_REGION_NUMBER0 0x00U
103 #define LL_MPU_REGION_NUMBER1 0x01U
104 #define LL_MPU_REGION_NUMBER2 0x02U
105 #define LL_MPU_REGION_NUMBER3 0x03U
106 #define LL_MPU_REGION_NUMBER4 0x04U
107 #define LL_MPU_REGION_NUMBER5 0x05U
108 #define LL_MPU_REGION_NUMBER6 0x06U
109 #define LL_MPU_REGION_NUMBER7 0x07U
117 #define LL_MPU_REGION_SIZE_32B (0x04U << MPU_RASR_SIZE_Pos)
118 #define LL_MPU_REGION_SIZE_64B (0x05U << MPU_RASR_SIZE_Pos)
119 #define LL_MPU_REGION_SIZE_128B (0x06U << MPU_RASR_SIZE_Pos)
120 #define LL_MPU_REGION_SIZE_256B (0x07U << MPU_RASR_SIZE_Pos)
121 #define LL_MPU_REGION_SIZE_512B (0x08U << MPU_RASR_SIZE_Pos)
122 #define LL_MPU_REGION_SIZE_1KB (0x09U << MPU_RASR_SIZE_Pos)
123 #define LL_MPU_REGION_SIZE_2KB (0x0AU << MPU_RASR_SIZE_Pos)
124 #define LL_MPU_REGION_SIZE_4KB (0x0BU << MPU_RASR_SIZE_Pos)
125 #define LL_MPU_REGION_SIZE_8KB (0x0CU << MPU_RASR_SIZE_Pos)
126 #define LL_MPU_REGION_SIZE_16KB (0x0DU << MPU_RASR_SIZE_Pos)
127 #define LL_MPU_REGION_SIZE_32KB (0x0EU << MPU_RASR_SIZE_Pos)
128 #define LL_MPU_REGION_SIZE_64KB (0x0FU << MPU_RASR_SIZE_Pos)
129 #define LL_MPU_REGION_SIZE_128KB (0x10U << MPU_RASR_SIZE_Pos)
130 #define LL_MPU_REGION_SIZE_256KB (0x11U << MPU_RASR_SIZE_Pos)
131 #define LL_MPU_REGION_SIZE_512KB (0x12U << MPU_RASR_SIZE_Pos)
132 #define LL_MPU_REGION_SIZE_1MB (0x13U << MPU_RASR_SIZE_Pos)
133 #define LL_MPU_REGION_SIZE_2MB (0x14U << MPU_RASR_SIZE_Pos)
134 #define LL_MPU_REGION_SIZE_4MB (0x15U << MPU_RASR_SIZE_Pos)
135 #define LL_MPU_REGION_SIZE_8MB (0x16U << MPU_RASR_SIZE_Pos)
136 #define LL_MPU_REGION_SIZE_16MB (0x17U << MPU_RASR_SIZE_Pos)
137 #define LL_MPU_REGION_SIZE_32MB (0x18U << MPU_RASR_SIZE_Pos)
138 #define LL_MPU_REGION_SIZE_64MB (0x19U << MPU_RASR_SIZE_Pos)
139 #define LL_MPU_REGION_SIZE_128MB (0x1AU << MPU_RASR_SIZE_Pos)
140 #define LL_MPU_REGION_SIZE_256MB (0x1BU << MPU_RASR_SIZE_Pos)
141 #define LL_MPU_REGION_SIZE_512MB (0x1CU << MPU_RASR_SIZE_Pos)
142 #define LL_MPU_REGION_SIZE_1GB (0x1DU << MPU_RASR_SIZE_Pos)
143 #define LL_MPU_REGION_SIZE_2GB (0x1EU << MPU_RASR_SIZE_Pos)
144 #define LL_MPU_REGION_SIZE_4GB (0x1FU << MPU_RASR_SIZE_Pos)
152 #define LL_MPU_REGION_NO_ACCESS (0x00U << MPU_RASR_AP_Pos)
153 #define LL_MPU_REGION_PRIV_RW (0x01U << MPU_RASR_AP_Pos)
154 #define LL_MPU_REGION_PRIV_RW_URO (0x02U << MPU_RASR_AP_Pos)
155 #define LL_MPU_REGION_FULL_ACCESS (0x03U << MPU_RASR_AP_Pos)
156 #define LL_MPU_REGION_PRIV_RO (0x05U << MPU_RASR_AP_Pos)
157 #define LL_MPU_REGION_PRIV_RO_URO (0x06U << MPU_RASR_AP_Pos)
165 #define LL_MPU_TEX_LEVEL0 (0x00U << MPU_RASR_TEX_Pos)
166 #define LL_MPU_TEX_LEVEL1 (0x01U << MPU_RASR_TEX_Pos)
167 #define LL_MPU_TEX_LEVEL2 (0x02U << MPU_RASR_TEX_Pos)
168 #define LL_MPU_TEX_LEVEL4 (0x04U << MPU_RASR_TEX_Pos)
176 #define LL_MPU_INSTRUCTION_ACCESS_ENABLE 0x00U
177 #define LL_MPU_INSTRUCTION_ACCESS_DISABLE MPU_RASR_XN_Msk
185 #define LL_MPU_ACCESS_SHAREABLE MPU_RASR_S_Msk
186 #define LL_MPU_ACCESS_NOT_SHAREABLE 0x00U
194 #define LL_MPU_ACCESS_CACHEABLE MPU_RASR_C_Msk
195 #define LL_MPU_ACCESS_NOT_CACHEABLE 0x00U
203 #define LL_MPU_ACCESS_BUFFERABLE MPU_RASR_B_Msk
204 #define LL_MPU_ACCESS_NOT_BUFFERABLE 0x00U
208 #endif /* __MPU_PRESENT */
209 
213 /* Exported macro ------------------------------------------------------------*/
214 
215 /* Exported functions --------------------------------------------------------*/
230 __STATIC_INLINE uint32_t LL_SYSTICK_IsActiveCounterFlag(void)
231 {
232  return ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == (SysTick_CTRL_COUNTFLAG_Msk));
233 }
234 
243 __STATIC_INLINE void LL_SYSTICK_SetClkSource(uint32_t Source)
244 {
245  if (Source == LL_SYSTICK_CLKSOURCE_HCLK)
246  {
247  SET_BIT(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK);
248  }
249  else
250  {
251  CLEAR_BIT(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK);
252  }
253 }
254 
262 __STATIC_INLINE uint32_t LL_SYSTICK_GetClkSource(void)
263 {
264  return READ_BIT(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK);
265 }
266 
272 __STATIC_INLINE void LL_SYSTICK_EnableIT(void)
273 {
274  SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
275 }
276 
282 __STATIC_INLINE void LL_SYSTICK_DisableIT(void)
283 {
284  CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
285 }
286 
292 __STATIC_INLINE uint32_t LL_SYSTICK_IsEnabledIT(void)
293 {
294  return (READ_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk) == (SysTick_CTRL_TICKINT_Msk));
295 }
296 
310 __STATIC_INLINE void LL_LPM_EnableSleep(void)
311 {
312  /* Clear SLEEPDEEP bit of Cortex System Control Register */
313  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
314 }
315 
321 __STATIC_INLINE void LL_LPM_EnableDeepSleep(void)
322 {
323  /* Set SLEEPDEEP bit of Cortex System Control Register */
324  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
325 }
326 
334 __STATIC_INLINE void LL_LPM_EnableSleepOnExit(void)
335 {
336  /* Set SLEEPONEXIT bit of Cortex System Control Register */
337  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
338 }
339 
345 __STATIC_INLINE void LL_LPM_DisableSleepOnExit(void)
346 {
347  /* Clear SLEEPONEXIT bit of Cortex System Control Register */
348  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
349 }
350 
357 __STATIC_INLINE void LL_LPM_EnableEventOnPend(void)
358 {
359  /* Set SEVEONPEND bit of Cortex System Control Register */
360  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
361 }
362 
369 __STATIC_INLINE void LL_LPM_DisableEventOnPend(void)
370 {
371  /* Clear SEVEONPEND bit of Cortex System Control Register */
372  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
373 }
374 
392 __STATIC_INLINE void LL_HANDLER_EnableFault(uint32_t Fault)
393 {
394  /* Enable the system handler fault */
395  SET_BIT(SCB->SHCSR, Fault);
396 }
397 
407 __STATIC_INLINE void LL_HANDLER_DisableFault(uint32_t Fault)
408 {
409  /* Disable the system handler fault */
410  CLEAR_BIT(SCB->SHCSR, Fault);
411 }
412 
426 __STATIC_INLINE uint32_t LL_CPUID_GetImplementer(void)
427 {
428  return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_IMPLEMENTER_Msk) >> SCB_CPUID_IMPLEMENTER_Pos);
429 }
430 
436 __STATIC_INLINE uint32_t LL_CPUID_GetVariant(void)
437 {
438  return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_VARIANT_Msk) >> SCB_CPUID_VARIANT_Pos);
439 }
440 
446 __STATIC_INLINE uint32_t LL_CPUID_GetConstant(void)
447 {
448  return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_ARCHITECTURE_Msk) >> SCB_CPUID_ARCHITECTURE_Pos);
449 }
450 
456 __STATIC_INLINE uint32_t LL_CPUID_GetParNo(void)
457 {
458  return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_PARTNO_Msk) >> SCB_CPUID_PARTNO_Pos);
459 }
460 
466 __STATIC_INLINE uint32_t LL_CPUID_GetRevision(void)
467 {
468  return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_REVISION_Msk) >> SCB_CPUID_REVISION_Pos);
469 }
470 
475 #if __MPU_PRESENT
476 
490 __STATIC_INLINE void LL_MPU_Enable(uint32_t Options)
491 {
492  /* Enable the MPU*/
493  WRITE_REG(MPU->CTRL, (MPU_CTRL_ENABLE_Msk | Options));
494  /* Ensure MPU settings take effects */
495  __DSB();
496  /* Sequence instruction fetches using update settings */
497  __ISB();
498 }
499 
505 __STATIC_INLINE void LL_MPU_Disable(void)
506 {
507  /* Make sure outstanding transfers are done */
508  __DMB();
509  /* Disable MPU*/
510  WRITE_REG(MPU->CTRL, 0U);
511 }
512 
518 __STATIC_INLINE uint32_t LL_MPU_IsEnabled(void)
519 {
520  return (READ_BIT(MPU->CTRL, MPU_CTRL_ENABLE_Msk) == (MPU_CTRL_ENABLE_Msk));
521 }
522 
537 __STATIC_INLINE void LL_MPU_EnableRegion(uint32_t Region)
538 {
539  /* Set Region number */
540  WRITE_REG(MPU->RNR, Region);
541  /* Enable the MPU region */
542  SET_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
543 }
544 
583 __STATIC_INLINE void LL_MPU_ConfigRegion(uint32_t Region, uint32_t SubRegionDisable, uint32_t Address, uint32_t Attributes)
584 {
585  /* Set Region number */
586  WRITE_REG(MPU->RNR, Region);
587  /* Set base address */
588  WRITE_REG(MPU->RBAR, (Address & 0xFFFFFFE0U));
589  /* Configure MPU */
590  WRITE_REG(MPU->RASR, (MPU_RASR_ENABLE_Msk | Attributes | SubRegionDisable << MPU_RASR_SRD_Pos));
591 }
592 
608 __STATIC_INLINE void LL_MPU_DisableRegion(uint32_t Region)
609 {
610  /* Set Region number */
611  WRITE_REG(MPU->RNR, Region);
612  /* Disable the MPU region */
613  CLEAR_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
614 }
615 
620 #endif /* __MPU_PRESENT */
621 
633 #ifdef __cplusplus
634 }
635 #endif
636 
637 #endif /* __STM32L4xx_LL_CORTEX_H */
638 
639 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
__STATIC_INLINE uint32_t LL_CPUID_GetVariant(void)
Get Variant number (The r value in the rnpn product revision identifier) SCB_CPUID VARIANT LL_CPUID_...
__STATIC_INLINE void LL_SYSTICK_EnableIT(void)
Enable SysTick exception request STK_CTRL TICKINT LL_SYSTICK_EnableIT.
__STATIC_INLINE void LL_MPU_EnableRegion(uint32_t Region)
Enable a MPU region MPU_RASR ENABLE LL_MPU_EnableRegion.
__STATIC_INLINE uint32_t LL_CPUID_GetConstant(void)
Get Constant number SCB_CPUID ARCHITECTURE LL_CPUID_GetConstant.
__STATIC_INLINE uint32_t LL_MPU_IsEnabled(void)
Check if MPU is enabled or not MPU_CTRL ENABLE LL_MPU_IsEnabled.
__STATIC_INLINE void LL_LPM_DisableSleepOnExit(void)
Do not sleep when returning to Thread mode. SCB_SCR SLEEPONEXIT LL_LPM_DisableSleepOnExit.
__STATIC_INLINE void LL_MPU_ConfigRegion(uint32_t Region, uint32_t SubRegionDisable, uint32_t Address, uint32_t Attributes)
Configure and enable a region MPU_RNR REGION LL_MPU_ConfigRegion MPU_RBAR REGION LL_MPU_ConfigRegio...
__STATIC_INLINE void LL_MPU_Enable(uint32_t Options)
Enable MPU with input options MPU_CTRL ENABLE LL_MPU_Enable.
__STATIC_INLINE void LL_SYSTICK_SetClkSource(uint32_t Source)
Configures the SysTick clock source STK_CTRL CLKSOURCE LL_SYSTICK_SetClkSource.
__STATIC_INLINE uint32_t LL_CPUID_GetRevision(void)
Get Revision number (The p value in the rnpn product revision identifier, indicates patch release) S...
__STATIC_INLINE uint32_t LL_CPUID_GetImplementer(void)
Get Implementer code SCB_CPUID IMPLEMENTER LL_CPUID_GetImplementer.
__STATIC_INLINE void LL_LPM_EnableEventOnPend(void)
Enabled events and all interrupts, including disabled interrupts, can wakeup the processor. SCB_SCR SEVEONPEND LL_LPM_EnableEventOnPend.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__STATIC_INLINE void LL_LPM_EnableSleepOnExit(void)
Configures sleep-on-exit when returning from Handler mode to Thread mode.
__STATIC_INLINE void LL_MPU_DisableRegion(uint32_t Region)
Disable a region MPU_RNR REGION LL_MPU_DisableRegion MPU_RASR ENABLE LL_MPU_DisableRegion.
__STATIC_INLINE void LL_HANDLER_DisableFault(uint32_t Fault)
Disable a fault in System handler control register (SHCSR) SCB_SHCSR MEMFAULTENA LL_HANDLER_DisableF...
__STATIC_INLINE void LL_LPM_EnableSleep(void)
Processor uses sleep as its low power mode SCB_SCR SLEEPDEEP LL_LPM_EnableSleep. ...
__STATIC_INLINE void LL_MPU_Disable(void)
Disable MPU MPU_CTRL ENABLE LL_MPU_Disable.
__STATIC_INLINE uint32_t LL_SYSTICK_IsEnabledIT(void)
Checks if the SYSTICK interrupt is enabled or disabled. STK_CTRL TICKINT LL_SYSTICK_IsEnabledIT.
__STATIC_INLINE void LL_SYSTICK_DisableIT(void)
Disable SysTick exception request STK_CTRL TICKINT LL_SYSTICK_DisableIT.
__STATIC_INLINE uint32_t LL_CPUID_GetParNo(void)
Get Part number SCB_CPUID PARTNO LL_CPUID_GetParNo.
__STATIC_INLINE uint32_t LL_SYSTICK_GetClkSource(void)
Get the SysTick clock source STK_CTRL CLKSOURCE LL_SYSTICK_GetClkSource.
__STATIC_INLINE void LL_LPM_EnableDeepSleep(void)
Processor uses deep sleep as its low power mode SCB_SCR SLEEPDEEP LL_LPM_EnableDeepSleep.
__STATIC_INLINE void LL_LPM_DisableEventOnPend(void)
Only enabled interrupts or events can wakeup the processor, disabled interrupts are excluded SCB_SCR...
__STATIC_INLINE uint32_t LL_SYSTICK_IsActiveCounterFlag(void)
This function checks if the Systick counter flag is active or not.
__STATIC_INLINE void LL_HANDLER_EnableFault(uint32_t Fault)
Enable a fault in System handler control register (SHCSR) SCB_SHCSR MEMFAULTENA LL_HANDLER_EnableFau...