]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_cortex.c
2 ******************************************************************************
3 * @file stm32f4xx_hal_cortex.c
4 * @author MCD Application Team
7 * @brief CORTEX HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the CORTEX:
10 * + Initialization and de-initialization functions
11 * + Peripheral Control functions
14 ==============================================================================
15 ##### How to use this driver #####
16 ==============================================================================
19 *** How to configure Interrupts using CORTEX HAL driver ***
20 ===========================================================
22 This section provides functions allowing to configure the NVIC interrupts (IRQ).
23 The Cortex-M4 exceptions are managed by CMSIS functions.
25 (#) Configure the NVIC Priority Grouping using HAL_NVIC_SetPriorityGrouping()
26 function according to the following table.
27 (#) Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority().
28 (#) Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ().
29 (#) please refer to programing manual for details in how to configure priority.
31 -@- When the NVIC_PRIORITYGROUP_0 is selected, IRQ pre-emption is no more possible.
32 The pending IRQ priority will be managed only by the sub priority.
34 -@- IRQ priority order (sorted by highest to lowest priority):
35 (+@) Lowest pre-emption priority
36 (+@) Lowest sub priority
37 (+@) Lowest hardware priority (IRQ number)
40 *** How to configure Systick using CORTEX HAL driver ***
41 ========================================================
43 Setup SysTick Timer for time base.
45 (+) The HAL_SYSTICK_Config() function calls the SysTick_Config() function which
46 is a CMSIS function that:
47 (++) Configures the SysTick Reload register with value passed as function parameter.
48 (++) Configures the SysTick IRQ priority to the lowest value (0x0F).
49 (++) Resets the SysTick Counter register.
50 (++) Configures the SysTick Counter clock source to be Core Clock Source (HCLK).
51 (++) Enables the SysTick Interrupt.
52 (++) Starts the SysTick Counter.
54 (+) You can change the SysTick Clock source to be HCLK_Div8 by calling the macro
55 __HAL_CORTEX_SYSTICKCLK_CONFIG(SYSTICK_CLKSOURCE_HCLK_DIV8) just after the
56 HAL_SYSTICK_Config() function call. The __HAL_CORTEX_SYSTICKCLK_CONFIG() macro is defined
57 inside the stm32f4xx_hal_cortex.h file.
59 (+) You can change the SysTick IRQ priority by calling the
60 HAL_NVIC_SetPriority(SysTick_IRQn,...) function just after the HAL_SYSTICK_Config() function
61 call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function.
63 (+) To adjust the SysTick time base, use the following formula:
65 Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s)
66 (++) Reload Value is the parameter to be passed for HAL_SYSTICK_Config() function
67 (++) Reload Value should not exceed 0xFFFFFF
70 ******************************************************************************
73 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
75 * Redistribution and use in source and binary forms, with or without modification,
76 * are permitted provided that the following conditions are met:
77 * 1. Redistributions of source code must retain the above copyright notice,
78 * this list of conditions and the following disclaimer.
79 * 2. Redistributions in binary form must reproduce the above copyright notice,
80 * this list of conditions and the following disclaimer in the documentation
81 * and/or other materials provided with the distribution.
82 * 3. Neither the name of STMicroelectronics nor the names of its contributors
83 * may be used to endorse or promote products derived from this software
84 * without specific prior written permission.
86 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
87 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
89 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
90 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
91 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
92 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
93 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
94 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
95 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97 ******************************************************************************
100 /* Includes ------------------------------------------------------------------*/
101 #include "stm32f4xx_hal.h"
103 /** @addtogroup STM32F4xx_HAL_Driver
108 * @brief CORTEX HAL module driver
112 #ifdef HAL_CORTEX_MODULE_ENABLED
114 /* Private typedef -----------------------------------------------------------*/
115 /* Private define ------------------------------------------------------------*/
116 /* Private macro -------------------------------------------------------------*/
117 /* Private variables ---------------------------------------------------------*/
118 /* Private function prototypes -----------------------------------------------*/
119 /* Private functions ---------------------------------------------------------*/
121 /** @defgroup CORTEX_Private_Functions
126 /** @defgroup CORTEX_Group1 Initialization and de-initialization functions
127 * @brief Initialization and Configuration functions
130 ==============================================================================
131 ##### Initialization and de-initialization functions #####
132 ==============================================================================
134 This section provides the CORTEX HAL driver functions allowing to configure Interrupts
135 Systick functionalities
143 * @brief Sets the priority grouping field (pre-emption priority and subpriority)
144 * using the required unlock sequence.
145 * @param PriorityGroup: The priority grouping bits length.
146 * This parameter can be one of the following values:
147 * @arg NVIC_PRIORITYGROUP_0: 0 bits for pre-emption priority
148 * 4 bits for subpriority
149 * @arg NVIC_PRIORITYGROUP_1: 1 bits for pre-emption priority
150 * 3 bits for subpriority
151 * @arg NVIC_PRIORITYGROUP_2: 2 bits for pre-emption priority
152 * 2 bits for subpriority
153 * @arg NVIC_PRIORITYGROUP_3: 3 bits for pre-emption priority
154 * 1 bits for subpriority
155 * @arg NVIC_PRIORITYGROUP_4: 4 bits for pre-emption priority
156 * 0 bits for subpriority
157 * @note When the NVIC_PriorityGroup_0 is selected, IRQ pre-emption is no more possible.
158 * The pending IRQ priority will be managed only by the subpriority.
161 void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup
)
163 /* Check the parameters */
164 assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup
));
166 /* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */
167 NVIC_SetPriorityGrouping(PriorityGroup
);
171 * @brief Sets the priority of an interrupt.
172 * @param IRQn: External interrupt number.
173 * This parameter can be an enumerator of IRQn_Type enumeration
174 * (For the complete STM32 Devices IRQ Channels list, please refer to stm32f4xx.h file)
175 * @param PreemptPriority: The pre-emption priority for the IRQn channel.
176 * This parameter can be a value between 0 and 15
177 * A lower priority value indicates a higher priority
178 * @param SubPriority: the subpriority level for the IRQ channel.
179 * This parameter can be a value between 0 and 15
180 * A lower priority value indicates a higher priority.
183 void HAL_NVIC_SetPriority(IRQn_Type IRQn
, uint32_t PreemptPriority
, uint32_t SubPriority
)
185 uint32_t prioritygroup
= 0x00;
187 /* Check the parameters */
188 assert_param(IS_NVIC_SUB_PRIORITY(SubPriority
));
189 assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority
));
191 prioritygroup
= NVIC_GetPriorityGrouping();
193 NVIC_SetPriority(IRQn
, NVIC_EncodePriority(prioritygroup
, PreemptPriority
, SubPriority
));
197 * @brief Enables a device specific interrupt in the NVIC interrupt controller.
198 * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
199 * function should be called before.
200 * @param IRQn External interrupt number.
201 * This parameter can be an enumerator of IRQn_Type enumeration
202 * (For the complete STM32 Devices IRQ Channels list, please refer to stm32f4xx.h file)
205 void HAL_NVIC_EnableIRQ(IRQn_Type IRQn
)
207 /* Enable interrupt */
208 NVIC_EnableIRQ(IRQn
);
212 * @brief Disables a device specific interrupt in the NVIC interrupt controller.
213 * @param IRQn External interrupt number.
214 * This parameter can be an enumerator of IRQn_Type enumeration
215 * (For the complete STM32 Devices IRQ Channels list, please refer to stm32f4xx.h file)
218 void HAL_NVIC_DisableIRQ(IRQn_Type IRQn
)
220 /* Disable interrupt */
221 NVIC_DisableIRQ(IRQn
);
225 * @brief Initiates a system reset request to reset the MCU.
229 void HAL_NVIC_SystemReset(void)
236 * @brief Initializes the System Timer and its interrupt, and starts the System Tick Timer.
237 * Counter is in free running mode to generate periodic interrupts.
238 * @param TicksNumb: Specifies the ticks Number of ticks between two interrupts.
239 * @retval status: - 0 Function succeeded.
240 * - 1 Function failed.
242 uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb
)
244 return SysTick_Config(TicksNumb
);
250 /** @defgroup CORTEX_Group2 Peripheral Control functions
251 * @brief Cortex control functions
254 ==============================================================================
255 ##### Peripheral Control functions #####
256 ==============================================================================
258 This subsection provides a set of functions allowing to control the CORTEX
259 (NVIC, SYSTICK) functionalities.
267 * @brief Gets the priority grouping field from the NVIC Interrupt Controller.
269 * @retval Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)
271 uint32_t HAL_NVIC_GetPriorityGrouping(void)
273 /* Get the PRIGROUP[10:8] field value */
274 return NVIC_GetPriorityGrouping();
278 * @brief Gets the priority of an interrupt.
279 * @param IRQn: External interrupt number.
280 * This parameter can be an enumerator of IRQn_Type enumeration
281 * (For the complete STM32 Devices IRQ Channels list, please refer to stm32f4xx.h file)
282 * @param PriorityGroup: the priority grouping bits length.
283 * This parameter can be one of the following values:
284 * @arg NVIC_PRIORITYGROUP_0: 0 bits for pre-emption priority
285 * 4 bits for subpriority
286 * @arg NVIC_PRIORITYGROUP_1: 1 bits for pre-emption priority
287 * 3 bits for subpriority
288 * @arg NVIC_PRIORITYGROUP_2: 2 bits for pre-emption priority
289 * 2 bits for subpriority
290 * @arg NVIC_PRIORITYGROUP_3: 3 bits for pre-emption priority
291 * 1 bits for subpriority
292 * @arg NVIC_PRIORITYGROUP_4: 4 bits for pre-emption priority
293 * 0 bits for subpriority
294 * @param pPreemptPriority: Pointer on the Preemptive priority value (starting from 0).
295 * @param pSubPriority: Pointer on the Subpriority value (starting from 0).
298 void HAL_NVIC_GetPriority(IRQn_Type IRQn
, uint32_t PriorityGroup
, uint32_t *pPreemptPriority
, uint32_t *pSubPriority
)
300 /* Check the parameters */
301 assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup
));
302 /* Get priority for Cortex-M system or device specific interrupts */
303 NVIC_DecodePriority(NVIC_GetPriority(IRQn
), PriorityGroup
, pPreemptPriority
, pSubPriority
);
307 * @brief Sets Pending bit of an external interrupt.
308 * @param IRQn External interrupt number
309 * This parameter can be an enumerator of @ref IRQn_Type enumeration
310 * (For the complete STM32 Devices IRQ Channels list, please refer to stm32f4xx.h file)
313 void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn
)
315 /* Set interrupt pending */
316 NVIC_SetPendingIRQ(IRQn
);
320 * @brief Gets Pending Interrupt (reads the pending register in the NVIC
321 * and returns the pending bit for the specified interrupt).
322 * @param IRQn External interrupt number.
323 * This parameter can be an enumerator of IRQn_Type enumeration
324 * (For the complete STM32 Devices IRQ Channels list, please refer to stm32f4xx.h file)
325 * @retval status: - 0 Interrupt status is not pending.
326 * - 1 Interrupt status is pending.
328 uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn
)
330 /* Return 1 if pending else 0 */
331 return NVIC_GetPendingIRQ(IRQn
);
335 * @brief Clears the pending bit of an external interrupt.
336 * @param IRQn External interrupt number.
337 * This parameter can be an enumerator of IRQn_Type enumeration
338 * (For the complete STM32 Devices IRQ Channels list, please refer to stm32f4xx.h file)
341 void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn
)
343 /* Clear pending interrupt */
344 NVIC_ClearPendingIRQ(IRQn
);
348 * @brief Gets active interrupt ( reads the active register in NVIC and returns the active bit).
349 * @param IRQn External interrupt number
350 * This parameter can be an enumerator of IRQn_Type enumeration
351 * (For the complete STM32 Devices IRQ Channels list, please refer to stm32f4xx.h file)
352 * @retval status: - 0 Interrupt status is not pending.
353 * - 1 Interrupt status is pending.
355 uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn
)
357 /* Return 1 if active else 0 */
358 return NVIC_GetActive(IRQn
);
362 * @brief Configures the SysTick clock source.
363 * @param CLKSource: specifies the SysTick clock source.
364 * This parameter can be one of the following values:
365 * @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source.
366 * @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
369 void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource
)
371 /* Check the parameters */
372 assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource
));
373 if (CLKSource
== SYSTICK_CLKSOURCE_HCLK
)
375 SysTick
->CTRL
|= SYSTICK_CLKSOURCE_HCLK
;
379 SysTick
->CTRL
&= ~SYSTICK_CLKSOURCE_HCLK
;
384 * @brief This function handles SYSTICK interrupt request.
388 void HAL_SYSTICK_IRQHandler(void)
390 HAL_SYSTICK_Callback();
394 * @brief SYSTICK callback.
398 __weak
void HAL_SYSTICK_Callback(void)
400 /* NOTE : This function Should not be modified, when the callback is needed,
401 the HAL_SYSTICK_Callback could be implemented in the user file
413 #endif /* HAL_CORTEX_MODULE_ENABLED */
422 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/