STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_cortex.c
Go to the documentation of this file.
1 
104 /* Includes ------------------------------------------------------------------*/
105 #include "stm32l4xx_hal.h"
106 
115 #ifdef HAL_CORTEX_MODULE_ENABLED
116 
117 /* Private types -------------------------------------------------------------*/
118 /* Private variables ---------------------------------------------------------*/
119 /* Private constants ---------------------------------------------------------*/
120 /* Private macros ------------------------------------------------------------*/
121 /* Private functions ---------------------------------------------------------*/
122 /* Exported functions --------------------------------------------------------*/
123 
164 void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
165 {
166  /* Check the parameters */
167  assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
168 
169  /* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */
170  NVIC_SetPriorityGrouping(PriorityGroup);
171 }
172 
186 void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
187 {
188  uint32_t prioritygroup = 0x00;
189 
190  /* Check the parameters */
191  assert_param(IS_NVIC_SUB_PRIORITY(SubPriority));
192  assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority));
193 
194  prioritygroup = NVIC_GetPriorityGrouping();
195 
196  NVIC_SetPriority(IRQn, NVIC_EncodePriority(prioritygroup, PreemptPriority, SubPriority));
197 }
198 
208 void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
209 {
210  /* Check the parameters */
211  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
212 
213  /* Enable interrupt */
214  NVIC_EnableIRQ(IRQn);
215 }
216 
224 void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
225 {
226  /* Check the parameters */
227  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
228 
229  /* Disable interrupt */
230  NVIC_DisableIRQ(IRQn);
231 }
232 
238 {
239  /* System Reset */
240  NVIC_SystemReset();
241 }
242 
250 uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
251 {
252  return SysTick_Config(TicksNumb);
253 }
279 {
280  /* Get the PRIGROUP[10:8] field value */
281  return NVIC_GetPriorityGrouping();
282 }
283 
305 void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPreemptPriority, uint32_t *pSubPriority)
306 {
307  /* Check the parameters */
308  assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
309  /* Get priority for Cortex-M system or device specific interrupts */
310  NVIC_DecodePriority(NVIC_GetPriority(IRQn), PriorityGroup, pPreemptPriority, pSubPriority);
311 }
312 
320 void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
321 {
322  /* Check the parameters */
323  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
324 
325  /* Set interrupt pending */
326  NVIC_SetPendingIRQ(IRQn);
327 }
328 
338 uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
339 {
340  /* Check the parameters */
341  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
342 
343  /* Return 1 if pending else 0 */
344  return NVIC_GetPendingIRQ(IRQn);
345 }
346 
354 void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
355 {
356  /* Check the parameters */
357  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
358 
359  /* Clear pending interrupt */
360  NVIC_ClearPendingIRQ(IRQn);
361 }
362 
371 uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
372 {
373  /* Return 1 if active else 0 */
374  return NVIC_GetActive(IRQn);
375 }
376 
385 void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
386 {
387  /* Check the parameters */
388  assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
389  if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
390  {
391  SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
392  }
393  else
394  {
395  SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
396  }
397 }
398 
404 {
406 }
407 
412 __weak void HAL_SYSTICK_Callback(void)
413 {
414  /* NOTE : This function should not be modified, when the callback is needed,
415  the HAL_SYSTICK_Callback could be implemented in the user file
416  */
417 }
418 
419 #if (__MPU_PRESENT == 1)
420 
424 void HAL_MPU_Disable(void)
425 {
426  /* Make sure outstanding transfers are done */
427  __DMB();
428 
429  /* Disable fault exceptions */
430  SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
431 
432  /* Disable the MPU and clear the control register*/
433  MPU->CTRL = 0U;
434 }
435 
447 void HAL_MPU_Enable(uint32_t MPU_Control)
448 {
449  /* Enable the MPU */
450  MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
451 
452  /* Enable fault exceptions */
453  SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
454 
455  /* Ensure MPU settings take effects */
456  __DSB();
457  __ISB();
458 }
459 
466 void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
467 {
468  /* Check the parameters */
469  assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number));
470  assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable));
471 
472  /* Set the Region number */
473  MPU->RNR = MPU_Init->Number;
474 
475  if ((MPU_Init->Enable) != RESET)
476  {
477  /* Check the parameters */
478  assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec));
479  assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission));
480  assert_param(IS_MPU_TEX_LEVEL(MPU_Init->TypeExtField));
481  assert_param(IS_MPU_ACCESS_SHAREABLE(MPU_Init->IsShareable));
482  assert_param(IS_MPU_ACCESS_CACHEABLE(MPU_Init->IsCacheable));
483  assert_param(IS_MPU_ACCESS_BUFFERABLE(MPU_Init->IsBufferable));
484  assert_param(IS_MPU_SUB_REGION_DISABLE(MPU_Init->SubRegionDisable));
485  assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size));
486 
487  MPU->RBAR = MPU_Init->BaseAddress;
488  MPU->RASR = ((uint32_t)MPU_Init->DisableExec << MPU_RASR_XN_Pos) |
489  ((uint32_t)MPU_Init->AccessPermission << MPU_RASR_AP_Pos) |
490  ((uint32_t)MPU_Init->TypeExtField << MPU_RASR_TEX_Pos) |
491  ((uint32_t)MPU_Init->IsShareable << MPU_RASR_S_Pos) |
492  ((uint32_t)MPU_Init->IsCacheable << MPU_RASR_C_Pos) |
493  ((uint32_t)MPU_Init->IsBufferable << MPU_RASR_B_Pos) |
494  ((uint32_t)MPU_Init->SubRegionDisable << MPU_RASR_SRD_Pos) |
495  ((uint32_t)MPU_Init->Size << MPU_RASR_SIZE_Pos) |
496  ((uint32_t)MPU_Init->Enable << MPU_RASR_ENABLE_Pos);
497  }
498  else
499  {
500  MPU->RBAR = 0x00;
501  MPU->RASR = 0x00;
502  }
503 }
504 #endif /* __MPU_PRESENT */
505 
514 #endif /* HAL_CORTEX_MODULE_ENABLED */
515 
523 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void HAL_SYSTICK_IRQHandler(void)
Handle SYSTICK interrupt request.
void HAL_MPU_Disable(void)
Disable the MPU.
void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
Initialize and configure the Region and the memory to be protected.
This file contains all the functions prototypes for the HAL module driver.
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
Initialize the System Timer with interrupt enabled and start the System Tick Timer (SysTick): Counter...
void HAL_NVIC_SystemReset(void)
Initiate a system reset request to reset the MCU.
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
Set Pending bit of an external interrupt.
void HAL_SYSTICK_Callback(void)
SYSTICK callback.
void HAL_MPU_Enable(uint32_t MPU_Control)
Enable the MPU.
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
Enable a device specific interrupt in the NVIC interrupt controller.
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPreemptPriority, uint32_t *pSubPriority)
Get the priority of an interrupt.
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
Configure the SysTick clock source.
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
Get active interrupt (read the active register in NVIC and return the active bit).
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
Set the priority of an interrupt.
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
Disable a device specific interrupt in the NVIC interrupt controller.
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
Get Pending Interrupt (read the pending register in the NVIC and return the pending bit for the speci...
uint32_t HAL_NVIC_GetPriorityGrouping(void)
Get the priority grouping field from the NVIC Interrupt Controller.
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
Set the priority grouping field (pre-emption priority and subpriority) using the required unlock sequ...
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
Clear the pending bit of an external interrupt.