2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_cortex.c
\r
4 * @author MCD Application Team
\r
5 * @brief CORTEX HAL module driver.
\r
6 * This file provides firmware functions to manage the following
\r
7 * functionalities of the CORTEX:
\r
8 * + Initialization and de-initialization functions
\r
9 * + Peripheral Control functions
\r
12 ==============================================================================
\r
13 ##### How to use this driver #####
\r
14 ==============================================================================
\r
17 *** How to configure Interrupts using CORTEX HAL driver ***
\r
18 ===========================================================
\r
20 This section provides functions allowing to configure the NVIC interrupts (IRQ).
\r
21 The Cortex-M4 exceptions are managed by CMSIS functions.
\r
23 (#) Configure the NVIC Priority Grouping using HAL_NVIC_SetPriorityGrouping()
\r
24 function according to the following table.
\r
25 (#) Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority().
\r
26 (#) Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ().
\r
27 (#) please refer to programming manual for details in how to configure priority.
\r
29 -@- When the NVIC_PRIORITYGROUP_0 is selected, IRQ preemption is no more possible.
\r
30 The pending IRQ priority will be managed only by the sub priority.
\r
32 -@- IRQ priority order (sorted by highest to lowest priority):
\r
33 (+@) Lowest preemption priority
\r
34 (+@) Lowest sub priority
\r
35 (+@) Lowest hardware priority (IRQ number)
\r
38 *** How to configure Systick using CORTEX HAL driver ***
\r
39 ========================================================
\r
41 Setup SysTick Timer for time base.
\r
43 (+) The HAL_SYSTICK_Config() function calls the SysTick_Config() function which
\r
44 is a CMSIS function that:
\r
45 (++) Configures the SysTick Reload register with value passed as function parameter.
\r
46 (++) Configures the SysTick IRQ priority to the lowest value (0x0F).
\r
47 (++) Resets the SysTick Counter register.
\r
48 (++) Configures the SysTick Counter clock source to be Core Clock Source (HCLK).
\r
49 (++) Enables the SysTick Interrupt.
\r
50 (++) Starts the SysTick Counter.
\r
52 (+) You can change the SysTick Clock source to be HCLK_Div8 by calling the macro
\r
53 __HAL_CORTEX_SYSTICKCLK_CONFIG(SYSTICK_CLKSOURCE_HCLK_DIV8) just after the
\r
54 HAL_SYSTICK_Config() function call. The __HAL_CORTEX_SYSTICKCLK_CONFIG() macro is defined
\r
55 inside the stm32f7xx_hal_cortex.h file.
\r
57 (+) You can change the SysTick IRQ priority by calling the
\r
58 HAL_NVIC_SetPriority(SysTick_IRQn,...) function just after the HAL_SYSTICK_Config() function
\r
59 call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function.
\r
61 (+) To adjust the SysTick time base, use the following formula:
\r
63 Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s)
\r
64 (++) Reload Value is the parameter to be passed for HAL_SYSTICK_Config() function
\r
65 (++) Reload Value should not exceed 0xFFFFFF
\r
68 ******************************************************************************
\r
71 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
72 * All rights reserved.</center></h2>
\r
74 * This software component is licensed by ST under BSD 3-Clause license,
\r
75 * the "License"; You may not use this file except in compliance with the
\r
76 * License. You may obtain a copy of the License at:
\r
77 * opensource.org/licenses/BSD-3-Clause
\r
79 ******************************************************************************
\r
82 /* Includes ------------------------------------------------------------------*/
\r
83 #include "stm32f7xx_hal.h"
\r
85 /** @addtogroup STM32F7xx_HAL_Driver
\r
89 /** @defgroup CORTEX CORTEX
\r
90 * @brief CORTEX HAL module driver
\r
94 #ifdef HAL_CORTEX_MODULE_ENABLED
\r
96 /* Private types -------------------------------------------------------------*/
\r
97 /* Private variables ---------------------------------------------------------*/
\r
98 /* Private constants ---------------------------------------------------------*/
\r
99 /* Private macros ------------------------------------------------------------*/
\r
100 /* Private functions ---------------------------------------------------------*/
\r
101 /* Exported functions --------------------------------------------------------*/
\r
103 /** @defgroup CORTEX_Exported_Functions CORTEX Exported Functions
\r
108 /** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
\r
109 * @brief Initialization and Configuration functions
\r
112 ==============================================================================
\r
113 ##### Initialization and de-initialization functions #####
\r
114 ==============================================================================
\r
116 This section provides the CORTEX HAL driver functions allowing to configure Interrupts
\r
117 Systick functionalities
\r
125 * @brief Sets the priority grouping field (preemption priority and subpriority)
\r
126 * using the required unlock sequence.
\r
127 * @param PriorityGroup The priority grouping bits length.
\r
128 * This parameter can be one of the following values:
\r
129 * @arg NVIC_PRIORITYGROUP_0: 0 bits for preemption priority
\r
130 * 4 bits for subpriority
\r
131 * @arg NVIC_PRIORITYGROUP_1: 1 bits for preemption priority
\r
132 * 3 bits for subpriority
\r
133 * @arg NVIC_PRIORITYGROUP_2: 2 bits for preemption priority
\r
134 * 2 bits for subpriority
\r
135 * @arg NVIC_PRIORITYGROUP_3: 3 bits for preemption priority
\r
136 * 1 bits for subpriority
\r
137 * @arg NVIC_PRIORITYGROUP_4: 4 bits for preemption priority
\r
138 * 0 bits for subpriority
\r
139 * @note When the NVIC_PriorityGroup_0 is selected, IRQ preemption is no more possible.
\r
140 * The pending IRQ priority will be managed only by the subpriority.
\r
143 void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
\r
145 /* Check the parameters */
\r
146 assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
\r
148 /* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */
\r
149 NVIC_SetPriorityGrouping(PriorityGroup);
\r
153 * @brief Sets the priority of an interrupt.
\r
154 * @param IRQn External interrupt number.
\r
155 * This parameter can be an enumerator of IRQn_Type enumeration
\r
156 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))
\r
157 * @param PreemptPriority The preemption priority for the IRQn channel.
\r
158 * This parameter can be a value between 0 and 15
\r
159 * A lower priority value indicates a higher priority
\r
160 * @param SubPriority the subpriority level for the IRQ channel.
\r
161 * This parameter can be a value between 0 and 15
\r
162 * A lower priority value indicates a higher priority.
\r
165 void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
\r
167 uint32_t prioritygroup = 0x00;
\r
169 /* Check the parameters */
\r
170 assert_param(IS_NVIC_SUB_PRIORITY(SubPriority));
\r
171 assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority));
\r
173 prioritygroup = NVIC_GetPriorityGrouping();
\r
175 NVIC_SetPriority(IRQn, NVIC_EncodePriority(prioritygroup, PreemptPriority, SubPriority));
\r
179 * @brief Enables a device specific interrupt in the NVIC interrupt controller.
\r
180 * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
\r
181 * function should be called before.
\r
182 * @param IRQn External interrupt number.
\r
183 * This parameter can be an enumerator of IRQn_Type enumeration
\r
184 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))
\r
187 void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
\r
189 /* Check the parameters */
\r
190 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
\r
192 /* Enable interrupt */
\r
193 NVIC_EnableIRQ(IRQn);
\r
197 * @brief Disables a device specific interrupt in the NVIC interrupt controller.
\r
198 * @param IRQn External interrupt number.
\r
199 * This parameter can be an enumerator of IRQn_Type enumeration
\r
200 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))
\r
203 void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
\r
205 /* Check the parameters */
\r
206 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
\r
208 /* Disable interrupt */
\r
209 NVIC_DisableIRQ(IRQn);
\r
213 * @brief Initiates a system reset request to reset the MCU.
\r
216 void HAL_NVIC_SystemReset(void)
\r
219 NVIC_SystemReset();
\r
223 * @brief Initializes the System Timer and its interrupt, and starts the System Tick Timer.
\r
224 * Counter is in free running mode to generate periodic interrupts.
\r
225 * @param TicksNumb Specifies the ticks Number of ticks between two interrupts.
\r
226 * @retval status: - 0 Function succeeded.
\r
227 * - 1 Function failed.
\r
229 uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
\r
231 return SysTick_Config(TicksNumb);
\r
237 /** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions
\r
238 * @brief Cortex control functions
\r
241 ==============================================================================
\r
242 ##### Peripheral Control functions #####
\r
243 ==============================================================================
\r
245 This subsection provides a set of functions allowing to control the CORTEX
\r
246 (NVIC, SYSTICK, MPU) functionalities.
\r
253 #if (__MPU_PRESENT == 1)
\r
255 * @brief Disables the MPU
\r
258 void HAL_MPU_Disable(void)
\r
260 /* Make sure outstanding transfers are done */
\r
263 /* Disable fault exceptions */
\r
264 SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
\r
266 /* Disable the MPU and clear the control register*/
\r
271 * @brief Enables the MPU
\r
272 * @param MPU_Control Specifies the control mode of the MPU during hard fault,
\r
273 * NMI, FAULTMASK and privileged access to the default memory
\r
274 * This parameter can be one of the following values:
\r
275 * @arg MPU_HFNMI_PRIVDEF_NONE
\r
276 * @arg MPU_HARDFAULT_NMI
\r
277 * @arg MPU_PRIVILEGED_DEFAULT
\r
278 * @arg MPU_HFNMI_PRIVDEF
\r
281 void HAL_MPU_Enable(uint32_t MPU_Control)
\r
283 /* Enable the MPU */
\r
284 MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
\r
286 /* Enable fault exceptions */
\r
287 SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
\r
289 /* Ensure MPU setting take effects */
\r
295 * @brief Initializes and configures the Region and the memory to be protected.
\r
296 * @param MPU_Init Pointer to a MPU_Region_InitTypeDef structure that contains
\r
297 * the initialization and configuration information.
\r
300 void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
\r
302 /* Check the parameters */
\r
303 assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number));
\r
304 assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable));
\r
306 /* Set the Region number */
\r
307 MPU->RNR = MPU_Init->Number;
\r
309 if ((MPU_Init->Enable) != RESET)
\r
311 /* Check the parameters */
\r
312 assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec));
\r
313 assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission));
\r
314 assert_param(IS_MPU_TEX_LEVEL(MPU_Init->TypeExtField));
\r
315 assert_param(IS_MPU_ACCESS_SHAREABLE(MPU_Init->IsShareable));
\r
316 assert_param(IS_MPU_ACCESS_CACHEABLE(MPU_Init->IsCacheable));
\r
317 assert_param(IS_MPU_ACCESS_BUFFERABLE(MPU_Init->IsBufferable));
\r
318 assert_param(IS_MPU_SUB_REGION_DISABLE(MPU_Init->SubRegionDisable));
\r
319 assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size));
\r
321 MPU->RBAR = MPU_Init->BaseAddress;
\r
322 MPU->RASR = ((uint32_t)MPU_Init->DisableExec << MPU_RASR_XN_Pos) |
\r
323 ((uint32_t)MPU_Init->AccessPermission << MPU_RASR_AP_Pos) |
\r
324 ((uint32_t)MPU_Init->TypeExtField << MPU_RASR_TEX_Pos) |
\r
325 ((uint32_t)MPU_Init->IsShareable << MPU_RASR_S_Pos) |
\r
326 ((uint32_t)MPU_Init->IsCacheable << MPU_RASR_C_Pos) |
\r
327 ((uint32_t)MPU_Init->IsBufferable << MPU_RASR_B_Pos) |
\r
328 ((uint32_t)MPU_Init->SubRegionDisable << MPU_RASR_SRD_Pos) |
\r
329 ((uint32_t)MPU_Init->Size << MPU_RASR_SIZE_Pos) |
\r
330 ((uint32_t)MPU_Init->Enable << MPU_RASR_ENABLE_Pos);
\r
338 #endif /* __MPU_PRESENT */
\r
341 * @brief Gets the priority grouping field from the NVIC Interrupt Controller.
\r
342 * @retval Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)
\r
344 uint32_t HAL_NVIC_GetPriorityGrouping(void)
\r
346 /* Get the PRIGROUP[10:8] field value */
\r
347 return NVIC_GetPriorityGrouping();
\r
351 * @brief Gets the priority of an interrupt.
\r
352 * @param IRQn External interrupt number.
\r
353 * This parameter can be an enumerator of IRQn_Type enumeration
\r
354 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))
\r
355 * @param PriorityGroup the priority grouping bits length.
\r
356 * This parameter can be one of the following values:
\r
357 * @arg NVIC_PRIORITYGROUP_0: 0 bits for preemption priority
\r
358 * 4 bits for subpriority
\r
359 * @arg NVIC_PRIORITYGROUP_1: 1 bits for preemption priority
\r
360 * 3 bits for subpriority
\r
361 * @arg NVIC_PRIORITYGROUP_2: 2 bits for preemption priority
\r
362 * 2 bits for subpriority
\r
363 * @arg NVIC_PRIORITYGROUP_3: 3 bits for preemption priority
\r
364 * 1 bits for subpriority
\r
365 * @arg NVIC_PRIORITYGROUP_4: 4 bits for preemption priority
\r
366 * 0 bits for subpriority
\r
367 * @param pPreemptPriority Pointer on the Preemptive priority value (starting from 0).
\r
368 * @param pSubPriority Pointer on the Subpriority value (starting from 0).
\r
371 void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPreemptPriority, uint32_t *pSubPriority)
\r
373 /* Check the parameters */
\r
374 assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
\r
375 /* Get priority for Cortex-M system or device specific interrupts */
\r
376 NVIC_DecodePriority(NVIC_GetPriority(IRQn), PriorityGroup, pPreemptPriority, pSubPriority);
\r
380 * @brief Sets Pending bit of an external interrupt.
\r
381 * @param IRQn External interrupt number
\r
382 * This parameter can be an enumerator of IRQn_Type enumeration
\r
383 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))
\r
386 void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
\r
388 /* Check the parameters */
\r
389 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
\r
391 /* Set interrupt pending */
\r
392 NVIC_SetPendingIRQ(IRQn);
\r
396 * @brief Gets Pending Interrupt (reads the pending register in the NVIC
\r
397 * and returns the pending bit for the specified interrupt).
\r
398 * @param IRQn External interrupt number.
\r
399 * This parameter can be an enumerator of IRQn_Type enumeration
\r
400 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))
\r
401 * @retval status: - 0 Interrupt status is not pending.
\r
402 * - 1 Interrupt status is pending.
\r
404 uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
\r
406 /* Check the parameters */
\r
407 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
\r
409 /* Return 1 if pending else 0 */
\r
410 return NVIC_GetPendingIRQ(IRQn);
\r
414 * @brief Clears the pending bit of an external interrupt.
\r
415 * @param IRQn External interrupt number.
\r
416 * This parameter can be an enumerator of IRQn_Type enumeration
\r
417 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))
\r
420 void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
\r
422 /* Check the parameters */
\r
423 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
\r
425 /* Clear pending interrupt */
\r
426 NVIC_ClearPendingIRQ(IRQn);
\r
430 * @brief Gets active interrupt ( reads the active register in NVIC and returns the active bit).
\r
431 * @param IRQn External interrupt number
\r
432 * This parameter can be an enumerator of IRQn_Type enumeration
\r
433 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))
\r
434 * @retval status: - 0 Interrupt status is not pending.
\r
435 * - 1 Interrupt status is pending.
\r
437 uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
\r
439 /* Check the parameters */
\r
440 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
\r
442 /* Return 1 if active else 0 */
\r
443 return NVIC_GetActive(IRQn);
\r
447 * @brief Configures the SysTick clock source.
\r
448 * @param CLKSource specifies the SysTick clock source.
\r
449 * This parameter can be one of the following values:
\r
450 * @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source.
\r
451 * @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
\r
454 void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
\r
456 /* Check the parameters */
\r
457 assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
\r
458 if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
\r
460 SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
\r
464 SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
\r
469 * @brief This function handles SYSTICK interrupt request.
\r
472 void HAL_SYSTICK_IRQHandler(void)
\r
474 HAL_SYSTICK_Callback();
\r
478 * @brief SYSTICK callback.
\r
481 __weak void HAL_SYSTICK_Callback(void)
\r
483 /* NOTE : This function Should not be modified, when the callback is needed,
\r
484 the HAL_SYSTICK_Callback could be implemented in the user file
\r
496 #endif /* HAL_CORTEX_MODULE_ENABLED */
\r
505 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r