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 /* Prevent unused argument(s) compilation warning */
142 UNUSED(SubPriority);
143 }
144
145 /**
146 * @brief Enables a device specific interrupt in the NVIC interrupt controller.
147 * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
148 * function should be called before.
149 * @param IRQn External interrupt number.
150 * This parameter can be an enumerator of IRQn_Type enumeration
151 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
152 * @retval None
153 */
HAL_NVIC_EnableIRQ(IRQn_Type IRQn)154 void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
155 {
156 /* Check the parameters */
157 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
158
159 /* Enable interrupt */
160 NVIC_EnableIRQ(IRQn);
161 }
162
163 /**
164 * @brief Disables a device specific interrupt in the NVIC interrupt controller.
165 * @param IRQn External interrupt number.
166 * This parameter can be an enumerator of IRQn_Type enumeration
167 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
168 * @retval None
169 */
HAL_NVIC_DisableIRQ(IRQn_Type IRQn)170 void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
171 {
172 /* Check the parameters */
173 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
174
175 /* Disable interrupt */
176 NVIC_DisableIRQ(IRQn);
177 }
178
179 /**
180 * @brief Initiates a system reset request to reset the MCU.
181 * @retval None
182 */
HAL_NVIC_SystemReset(void)183 void HAL_NVIC_SystemReset(void)
184 {
185 /* System Reset */
186 NVIC_SystemReset();
187 }
188
189 /**
190 * @brief Initializes the System Timer and its interrupt, and starts the System Tick Timer.
191 * Counter is in free running mode to generate periodic interrupts.
192 * @param TicksNumb Specifies the ticks Number of ticks between two interrupts.
193 * @retval status: - 0 Function succeeded.
194 * - 1 Function failed.
195 */
HAL_SYSTICK_Config(uint32_t TicksNumb)196 uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
197 {
198 return SysTick_Config(TicksNumb);
199 }
200 /**
201 * @}
202 */
203
204 /** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions
205 * @brief Cortex control functions
206 *
207 @verbatim
208 ==============================================================================
209 ##### Peripheral Control functions #####
210 ==============================================================================
211 [..]
212 This subsection provides a set of functions allowing to control the CORTEX
213 (NVIC, SYSTICK) functionalities.
214
215
216 @endverbatim
217 * @{
218 */
219
220
221 /**
222 * @brief Gets the priority of an interrupt.
223 * @param IRQn External interrupt number.
224 * This parameter can be an enumerator of IRQn_Type enumeration
225 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
226 * @retval None
227 */
HAL_NVIC_GetPriority(IRQn_Type IRQn)228 uint32_t HAL_NVIC_GetPriority(IRQn_Type IRQn)
229 {
230 /* Get priority for Cortex-M system or device specific interrupts */
231 return NVIC_GetPriority(IRQn);
232 }
233
234 /**
235 * @brief Sets Pending bit of an external interrupt.
236 * @param IRQn External interrupt number
237 * This parameter can be an enumerator of IRQn_Type enumeration
238 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
239 * @retval None
240 */
HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)241 void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
242 {
243 /* Check the parameters */
244 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
245
246 /* Set interrupt pending */
247 NVIC_SetPendingIRQ(IRQn);
248 }
249
250 /**
251 * @brief Gets Pending Interrupt (reads the pending register in the NVIC
252 * and returns the pending bit for the specified interrupt).
253 * @param IRQn External interrupt number.
254 * This parameter can be an enumerator of IRQn_Type enumeration
255 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
256 * @retval status: - 0 Interrupt status is not pending.
257 * - 1 Interrupt status is pending.
258 */
HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)259 uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
260 {
261 /* Check the parameters */
262 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
263
264 /* Return 1 if pending else 0 */
265 return NVIC_GetPendingIRQ(IRQn);
266 }
267
268 /**
269 * @brief Clears the pending bit of an external interrupt.
270 * @param IRQn External interrupt number.
271 * This parameter can be an enumerator of IRQn_Type enumeration
272 * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h))
273 * @retval None
274 */
HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)275 void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
276 {
277 /* Check the parameters */
278 assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
279
280 /* Clear pending interrupt */
281 NVIC_ClearPendingIRQ(IRQn);
282 }
283
284 /**
285 * @brief Configures the SysTick clock source.
286 * @param CLKSource specifies the SysTick clock source.
287 * This parameter can be one of the following values:
288 * @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source.
289 * @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
290 * @retval None
291 */
HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)292 void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
293 {
294 /* Check the parameters */
295 assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
296 if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
297 {
298 SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
299 }
300 else
301 {
302 SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
303 }
304 }
305
306 /**
307 * @brief This function handles SYSTICK interrupt request.
308 * @retval None
309 */
HAL_SYSTICK_IRQHandler(void)310 void HAL_SYSTICK_IRQHandler(void)
311 {
312 HAL_SYSTICK_Callback();
313 }
314
315 /**
316 * @brief SYSTICK callback.
317 * @retval None
318 */
HAL_SYSTICK_Callback(void)319 __weak void HAL_SYSTICK_Callback(void)
320 {
321 /* NOTE : This function Should not be modified, when the callback is needed,
322 the HAL_SYSTICK_Callback could be implemented in the user file
323 */
324 }
325
326 /**
327 * @}
328 */
329
330 /**
331 * @}
332 */
333
334 #endif /* HAL_CORTEX_MODULE_ENABLED */
335 /**
336 * @}
337 */
338
339 /**
340 * @}
341 */
342
343