1 /**
2 ******************************************************************************
3 * @file stm32f0xx_hal_cortex.c
4 * @author MCD Application Team
5 * @brief CORTEX HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the CORTEX:
8 * + Initialization and de-initialization functions
9 * + Peripheral Control functions
10 *
11 * @verbatim
12 ==============================================================================
13 ##### How to use this driver #####
14 ==============================================================================
15
16 [..]
17 *** How to configure Interrupts using CORTEX HAL driver ***
18 ===========================================================
19 [..]
20 This section provides functions allowing to configure the NVIC interrupts (IRQ).
21 The Cortex-M0 exceptions are managed by CMSIS functions.
22 (#) Enable and Configure the priority of the selected IRQ Channels.
23 The priority can be 0..3.
24
25 -@- Lower priority values gives higher priority.
26 -@- Priority Order:
27 (#@) Lowest priority.
28 (#@) Lowest hardware priority (IRQn position).
29
30 (#) Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority()
31
32 (#) Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ()
33
34 -@- Negative value of IRQn_Type are not allowed.
35
36
37 [..]
38 *** How to configure Systick using CORTEX HAL driver ***
39 ========================================================
40 [..]
41 Setup SysTick Timer for time base.
42
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.
51
52 (+) You can change the SysTick Clock source to be HCLK_Div8 by calling the macro
53 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK_DIV8) just after the
54 HAL_SYSTICK_Config() function call. The HAL_SYSTICK_CLKSourceConfig() macro is defined
55 inside the stm32f0xx_hal_cortex.h file.
56
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.
60
61 (+) To adjust the SysTick time base, use the following formula:
62
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
66
67 @endverbatim
68 ******************************************************************************
69 * @attention
70 *
71 * Copyright (c) 2016 STMicroelectronics.
72 * All rights reserved.
73 *
74 * This software is licensed under terms that can be found in the LICENSE file in
75 * the root directory of this software component.
76 * If no LICENSE file comes with this software, it is provided AS-IS.
77 *
78 ******************************************************************************
79 */
80
81 /* Includes ------------------------------------------------------------------*/
82 #include "stm32f0xx_hal.h"
83
84 /** @addtogroup STM32F0xx_HAL_Driver
85 * @{
86 */
87
88 /** @defgroup CORTEX CORTEX
89 * @brief CORTEX CORTEX HAL module driver
90 * @{
91 */
92
93 #ifdef HAL_CORTEX_MODULE_ENABLED
94
95 /* Private typedef -----------------------------------------------------------*/
96 /* Private define ------------------------------------------------------------*/
97 /* Private macro -------------------------------------------------------------*/
98 /* Private variables ---------------------------------------------------------*/
99 /* Private function prototypes -----------------------------------------------*/
100 /* Exported functions ---------------------------------------------------------*/
101
102 /** @defgroup CORTEX_Exported_Functions CORTEX Exported Functions
103 * @{
104 */
105
106
107 /** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
108 * @brief Initialization and Configuration functions
109 *
110 @verbatim
111 ==============================================================================
112 ##### Initialization and de-initialization functions #####
113 ==============================================================================
114 [..]
115 This section provides the CORTEX HAL driver functions allowing to configure Interrupts
116 Systick functionalities
117
118 @endverbatim
119 * @{
120 */
121
122 /**
123 * @brief Sets the priority of an interrupt.
124 * @param IRQn External interrupt number .
125 * This parameter can be an enumerator of IRQn_Type enumeration
126 * (For the complete STM32 Devices IRQ Channels list, please refer to stm32f0xx.h file)
127 * @param PreemptPriority The preemption priority for the IRQn channel.
128 * This parameter can be a value between 0 and 3.
129 * A lower priority value indicates a higher priority
130 * @param SubPriority the subpriority level for the IRQ channel.
131 * with stm32f0xx devices, this parameter is a dummy value and it is ignored, because
132 * no subpriority supported in Cortex M0 based products.
133 * @retval None
134 */
HAL_NVIC_SetPriority(IRQn_Type IRQn,uint32_t PreemptPriority,uint32_t SubPriority)135 void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
136 {
137 /* Check the parameters */
138 assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority));
139 NVIC_SetPriority(IRQn,PreemptPriority);
140 }
141
142 /**
143 * @brief Enables a device specific interrupt in the NVIC interrupt controller.
144 * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
145 * function should be called before.
146 * @param IRQn External interrupt number.
147 * This parameter can be an enumerator of IRQn_Type enumeration
148 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
149 * @retval None
150 */
HAL_NVIC_EnableIRQ(IRQn_Type IRQn)151 void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
152 {
153 /* Check the parameters */
154 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
155
156 /* Enable interrupt */
157 NVIC_EnableIRQ(IRQn);
158 }
159
160 /**
161 * @brief Disables a device specific interrupt in the NVIC interrupt controller.
162 * @param IRQn External interrupt number.
163 * This parameter can be an enumerator of IRQn_Type enumeration
164 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
165 * @retval None
166 */
HAL_NVIC_DisableIRQ(IRQn_Type IRQn)167 void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
168 {
169 /* Check the parameters */
170 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
171
172 /* Disable interrupt */
173 NVIC_DisableIRQ(IRQn);
174 }
175
176 /**
177 * @brief Initiates a system reset request to reset the MCU.
178 * @retval None
179 */
HAL_NVIC_SystemReset(void)180 void HAL_NVIC_SystemReset(void)
181 {
182 /* System Reset */
183 NVIC_SystemReset();
184 }
185
186 /**
187 * @brief Initializes the System Timer and its interrupt, and starts the System Tick Timer.
188 * Counter is in free running mode to generate periodic interrupts.
189 * @param TicksNumb Specifies the ticks Number of ticks between two interrupts.
190 * @retval status: - 0 Function succeeded.
191 * - 1 Function failed.
192 */
HAL_SYSTICK_Config(uint32_t TicksNumb)193 uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
194 {
195 return SysTick_Config(TicksNumb);
196 }
197 /**
198 * @}
199 */
200
201 /** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions
202 * @brief Cortex control functions
203 *
204 @verbatim
205 ==============================================================================
206 ##### Peripheral Control functions #####
207 ==============================================================================
208 [..]
209 This subsection provides a set of functions allowing to control the CORTEX
210 (NVIC, SYSTICK) functionalities.
211
212
213 @endverbatim
214 * @{
215 */
216
217
218 /**
219 * @brief Gets the priority of an interrupt.
220 * @param IRQn External interrupt number.
221 * This parameter can be an enumerator of IRQn_Type enumeration
222 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
223 * @retval None
224 */
HAL_NVIC_GetPriority(IRQn_Type IRQn)225 uint32_t HAL_NVIC_GetPriority(IRQn_Type IRQn)
226 {
227 /* Get priority for Cortex-M system or device specific interrupts */
228 return NVIC_GetPriority(IRQn);
229 }
230
231 /**
232 * @brief Sets Pending bit of an external interrupt.
233 * @param IRQn External interrupt number
234 * This parameter can be an enumerator of IRQn_Type enumeration
235 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
236 * @retval None
237 */
HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)238 void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
239 {
240 /* Check the parameters */
241 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
242
243 /* Set interrupt pending */
244 NVIC_SetPendingIRQ(IRQn);
245 }
246
247 /**
248 * @brief Gets Pending Interrupt (reads the pending register in the NVIC
249 * and returns the pending bit for the specified interrupt).
250 * @param IRQn External interrupt number.
251 * This parameter can be an enumerator of IRQn_Type enumeration
252 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
253 * @retval status: - 0 Interrupt status is not pending.
254 * - 1 Interrupt status is pending.
255 */
HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)256 uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
257 {
258 /* Check the parameters */
259 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
260
261 /* Return 1 if pending else 0 */
262 return NVIC_GetPendingIRQ(IRQn);
263 }
264
265 /**
266 * @brief Clears the pending bit of an external interrupt.
267 * @param IRQn External interrupt number.
268 * This parameter can be an enumerator of IRQn_Type enumeration
269 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
270 * @retval None
271 */
HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)272 void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
273 {
274 /* Check the parameters */
275 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
276
277 /* Clear pending interrupt */
278 NVIC_ClearPendingIRQ(IRQn);
279 }
280
281 /**
282 * @brief Configures the SysTick clock source.
283 * @param CLKSource specifies the SysTick clock source.
284 * This parameter can be one of the following values:
285 * @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source.
286 * @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
287 * @retval None
288 */
HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)289 void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
290 {
291 /* Check the parameters */
292 assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
293 if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
294 {
295 SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
296 }
297 else
298 {
299 SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
300 }
301 }
302
303 /**
304 * @brief This function handles SYSTICK interrupt request.
305 * @retval None
306 */
HAL_SYSTICK_IRQHandler(void)307 void HAL_SYSTICK_IRQHandler(void)
308 {
309 HAL_SYSTICK_Callback();
310 }
311
312 /**
313 * @brief SYSTICK callback.
314 * @retval None
315 */
HAL_SYSTICK_Callback(void)316 __weak void HAL_SYSTICK_Callback(void)
317 {
318 /* NOTE : This function Should not be modified, when the callback is needed,
319 the HAL_SYSTICK_Callback could be implemented in the user file
320 */
321 }
322
323 /**
324 * @}
325 */
326
327 /**
328 * @}
329 */
330
331 #endif /* HAL_CORTEX_MODULE_ENABLED */
332 /**
333 * @}
334 */
335
336 /**
337 * @}
338 */
339
340