2 ******************************************************************************
3 * @file stm32f0xx_hal_cortex.c
4 * @author MCD Application Team
6 * @date 11-December-2014
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-M0 exceptions are managed by CMSIS functions.
24 (#) Enable and Configure the priority of the selected IRQ Channels.
25 The priority can be 0..3.
27 -@- Lower priority values gives higher priority.
30 (#@) Lowest hardware priority (IRQn position).
32 (#) Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority()
34 (#) Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ()
38 *** How to configure Systick using CORTEX HAL driver ***
39 ========================================================
41 Setup SysTick Timer for time base
43 (+) The HAL_SYSTICK_Config()function calls the SysTick_Config() function which
44 is a CMSIS function that:
45 (++) Configures the SysTick Reload register with value passed as function parameter.
46 (++) Configures the SysTick IRQ priority to the lowest value (0x03).
47 (++) Resets the SysTick Counter register.
48 (++) Configures the SysTick Counter clock source to be Core Clock Source (HCLK).
49 (++) Enables the SysTick Interrupt.
50 (++) Starts the SysTick Counter.
52 (+) You can change the SysTick Clock source to be HCLK_Div8 by calling the macro
53 __HAL_CORTEX_SYSTICKCLK_CONFIG(SYSTICK_CLKSOURCE_HCLK_DIV8) just after the
54 HAL_SYSTICK_Config() function call. The __HAL_CORTEX_SYSTICKCLK_CONFIG() macro is defined
55 inside the stm32f0xx_hal_cortex.h file.
57 (+) You can change the SysTick IRQ priority by calling the
58 HAL_NVIC_SetPriority(SysTick_IRQn,...) function just after the HAL_SYSTICK_Config() function
59 call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function.
61 (+) To adjust the SysTick time base, use the following formula:
63 Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s)
64 (++) Reload Value is the parameter to be passed for HAL_SYSTICK_Config() function
65 (++) Reload Value should not exceed 0xFFFFFF
68 ******************************************************************************
71 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
73 * Redistribution and use in source and binary forms, with or without modification,
74 * are permitted provided that the following conditions are met:
75 * 1. Redistributions of source code must retain the above copyright notice,
76 * this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright notice,
78 * this list of conditions and the following disclaimer in the documentation
79 * and/or other materials provided with the distribution.
80 * 3. Neither the name of STMicroelectronics nor the names of its contributors
81 * may be used to endorse or promote products derived from this software
82 * without specific prior written permission.
84 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
85 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
86 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
87 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
88 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
89 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
90 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
91 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
92 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
93 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
95 ******************************************************************************
98 /* Includes ------------------------------------------------------------------*/
99 #include "stm32f0xx_hal.h"
101 /** @addtogroup STM32F0xx_HAL_Driver
105 /** @defgroup CORTEX CORTEX HAL module driver
106 * @brief CORTEX CORTEX HAL module driver
110 #ifdef HAL_CORTEX_MODULE_ENABLED
112 /* Private typedef -----------------------------------------------------------*/
113 /* Private define ------------------------------------------------------------*/
114 /* Private macro -------------------------------------------------------------*/
115 /* Private variables ---------------------------------------------------------*/
116 /* Private function prototypes -----------------------------------------------*/
117 /* Exported functions ---------------------------------------------------------*/
119 /** @defgroup CORTEX_Exported_Functions CORTEX Exported Functions
124 /** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
125 * @brief Initialization and Configuration functions
128 ==============================================================================
129 ##### Initialization and de-initialization functions #####
130 ==============================================================================
132 This section provides the CORTEX HAL driver functions allowing to configure Interrupts
133 Systick functionalities
140 * @brief Sets the priority of an interrupt.
141 * @param IRQn: External interrupt number .
142 * This parameter can be an enumerator of IRQn_Type enumeration
143 * (For the complete STM32 Devices IRQ Channels list, please refer to stm32l0xx.h file)
144 * @param PreemptPriority: The pre-emption priority for the IRQn channel.
145 * This parameter can be a value between 0 and 3.
146 * A lower priority value indicates a higher priority
147 * @param SubPriority: The subpriority level for the IRQ channel.
148 * with stm32f0xx devices, this parameter is a dummy value and it is ignored, because
149 * no subpriority supported in Cortex M0 based products.
152 void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
154 /* Check the parameters */
155 assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority));
156 NVIC_SetPriority(IRQn,PreemptPriority);
160 * @brief Enables a device specific interrupt in the NVIC interrupt controller.
161 * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
162 * function should be called before.
163 * @param IRQn External interrupt number
164 * This parameter can be an enumerator of IRQn_Type enumeration
165 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
168 void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
170 /* Enable interrupt */
171 NVIC_EnableIRQ(IRQn);
175 * @brief Disables a device specific interrupt in the NVIC interrupt controller.
176 * @param IRQn External interrupt number
177 * This parameter can be an enumerator of IRQn_Type enumeration
178 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
181 void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
183 /* Disable interrupt */
184 NVIC_DisableIRQ(IRQn);
188 * @brief Initiates a system reset request to reset the MCU.
191 void HAL_NVIC_SystemReset(void)
198 * @brief Initializes the System Timer and its interrupt, and starts the System Tick Timer.
199 * Counter is in free running mode to generate periodic interrupts.
200 * @param TicksNumb: Specifies the ticks Number of ticks between two interrupts.
201 * @retval status: - 0 Function succeeded.
202 * - 1 Function failed.
204 uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
206 return SysTick_Config(TicksNumb);
212 /** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions
213 * @brief Cortex control functions
216 ==============================================================================
217 ##### Peripheral Control functions #####
218 ==============================================================================
220 This subsection provides a set of functions allowing to control the CORTEX
221 (NVIC, SYSTICK) functionalities.
230 * @brief Gets the priority of an interrupt.
231 * @param IRQn: External interrupt number
232 * This parameter can be an enumerator of IRQn_Type enumeration
233 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
236 uint32_t HAL_NVIC_GetPriority(IRQn_Type IRQn)
238 /* Get priority for Cortex-M system or device specific interrupts */
239 return NVIC_GetPriority(IRQn);
243 * @brief Sets Pending bit of an external interrupt.
244 * @param IRQn External interrupt number
245 * This parameter can be an enumerator of IRQn_Type enumeration
246 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
249 void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
251 /* Set interrupt pending */
252 NVIC_SetPendingIRQ(IRQn);
256 * @brief Gets Pending Interrupt (reads the pending register in the NVIC
257 * and returns the pending bit for the specified interrupt).
258 * @param IRQn External interrupt number
259 * This parameter can be an enumerator of IRQn_Type enumeration
260 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
261 * @retval status: - 0 Interrupt status is not pending.
262 * - 1 Interrupt status is pending.
264 uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
266 /* Return 1 if pending else 0 */
267 return NVIC_GetPendingIRQ(IRQn);
271 * @brief Clears the pending bit of an external interrupt.
272 * @param IRQn External interrupt number
273 * This parameter can be an enumerator of IRQn_Type enumeration
274 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
277 void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
279 /* Clear pending interrupt */
280 NVIC_ClearPendingIRQ(IRQn);
284 * @brief Configures the SysTick clock source.
285 * @param CLKSource: specifies the SysTick clock source.
286 * This parameter can be one of the following values:
287 * @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source.
288 * @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
291 void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
293 /* Check the parameters */
294 assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
295 if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
297 SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
301 SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
306 * @brief This function handles SYSTICK interrupt request.
309 void HAL_SYSTICK_IRQHandler(void)
311 HAL_SYSTICK_Callback();
315 * @brief SYSTICK callback.
318 __weak void HAL_SYSTICK_Callback(void)
320 /* NOTE : This function Should not be modified, when the callback is needed,
321 the HAL_SYSTICK_Callback could be implemented in the user file
333 #endif /* HAL_CORTEX_MODULE_ENABLED */
342 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/