]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL/ST_Library/stm32f7xx_hal_cortex.c
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL / ST_Library / stm32f7xx_hal_cortex.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32f7xx_hal_cortex.c\r
4   * @author  MCD Application Team\r
5   * @version V0.3.0\r
6   * @date    06-March-2015\r
7   * @brief   CORTEX HAL module driver.\r
8   *          This file provides firmware functions to manage the following \r
9   *          functionalities of the CORTEX:\r
10   *           + Initialization and de-initialization functions\r
11   *           + Peripheral Control functions \r
12   *\r
13   @verbatim  \r
14   ==============================================================================\r
15                         ##### How to use this driver #####\r
16   ==============================================================================\r
17 \r
18     [..]  \r
19     *** How to configure Interrupts using CORTEX HAL driver ***\r
20     ===========================================================\r
21     [..]     \r
22     This section provides functions allowing to configure the NVIC interrupts (IRQ).\r
23     The Cortex-M4 exceptions are managed by CMSIS functions.\r
24    \r
25     (#) Configure the NVIC Priority Grouping using HAL_NVIC_SetPriorityGrouping()\r
26         function according to the following table.\r
27     (#) Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority(). \r
28     (#) Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ().\r
29     (#) please refer to programing manual for details in how to configure priority. \r
30       \r
31      -@- When the NVIC_PRIORITYGROUP_0 is selected, IRQ preemption is no more possible. \r
32          The pending IRQ priority will be managed only by the sub priority.\r
33    \r
34      -@- IRQ priority order (sorted by highest to lowest priority):\r
35         (+@) Lowest preemption priority\r
36         (+@) Lowest sub priority\r
37         (+@) Lowest hardware priority (IRQ number)\r
38  \r
39     [..]  \r
40     *** How to configure Systick using CORTEX HAL driver ***\r
41     ========================================================\r
42     [..]\r
43     Setup SysTick Timer for time base.\r
44            \r
45    (+) The HAL_SYSTICK_Config() function calls the SysTick_Config() function which\r
46        is a CMSIS function that:\r
47         (++) Configures the SysTick Reload register with value passed as function parameter.\r
48         (++) Configures the SysTick IRQ priority to the lowest value (0x0F).\r
49         (++) Resets the SysTick Counter register.\r
50         (++) Configures the SysTick Counter clock source to be Core Clock Source (HCLK).\r
51         (++) Enables the SysTick Interrupt.\r
52         (++) Starts the SysTick Counter.\r
53     \r
54    (+) You can change the SysTick Clock source to be HCLK_Div8 by calling the macro\r
55        __HAL_CORTEX_SYSTICKCLK_CONFIG(SYSTICK_CLKSOURCE_HCLK_DIV8) just after the\r
56        HAL_SYSTICK_Config() function call. The __HAL_CORTEX_SYSTICKCLK_CONFIG() macro is defined\r
57        inside the stm32f7xx_hal_cortex.h file.\r
58 \r
59    (+) You can change the SysTick IRQ priority by calling the\r
60        HAL_NVIC_SetPriority(SysTick_IRQn,...) function just after the HAL_SYSTICK_Config() function \r
61        call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function.\r
62 \r
63    (+) To adjust the SysTick time base, use the following formula:\r
64                             \r
65        Reload Value = SysTick Counter Clock (Hz) x  Desired Time base (s)\r
66        (++) Reload Value is the parameter to be passed for HAL_SYSTICK_Config() function\r
67        (++) Reload Value should not exceed 0xFFFFFF\r
68    \r
69   @endverbatim\r
70   ******************************************************************************\r
71   * @attention\r
72   *\r
73   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>\r
74   *\r
75   * Redistribution and use in source and binary forms, with or without modification,\r
76   * are permitted provided that the following conditions are met:\r
77   *   1. Redistributions of source code must retain the above copyright notice,\r
78   *      this list of conditions and the following disclaimer.\r
79   *   2. Redistributions in binary form must reproduce the above copyright notice,\r
80   *      this list of conditions and the following disclaimer in the documentation\r
81   *      and/or other materials provided with the distribution.\r
82   *   3. Neither the name of STMicroelectronics nor the names of its contributors\r
83   *      may be used to endorse or promote products derived from this software\r
84   *      without specific prior written permission.\r
85   *\r
86   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
87   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
88   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
89   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
90   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
91   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
92   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
93   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
94   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
95   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
96   *\r
97   ******************************************************************************\r
98   */\r
99 \r
100 /* Includes ------------------------------------------------------------------*/\r
101 #include "stm32f7xx_hal.h"\r
102 \r
103 /** @addtogroup STM32F7xx_HAL_Driver\r
104   * @{\r
105   */\r
106 \r
107 /** @defgroup CORTEX CORTEX\r
108   * @brief CORTEX HAL module driver\r
109   * @{\r
110   */\r
111 \r
112 #ifdef HAL_CORTEX_MODULE_ENABLED\r
113 \r
114 /* Private types -------------------------------------------------------------*/\r
115 /* Private variables ---------------------------------------------------------*/\r
116 /* Private constants ---------------------------------------------------------*/\r
117 /* Private macros ------------------------------------------------------------*/\r
118 /* Private functions ---------------------------------------------------------*/\r
119 /* Exported functions --------------------------------------------------------*/\r
120 \r
121 /** @defgroup CORTEX_Exported_Functions CORTEX Exported Functions\r
122   * @{\r
123   */\r
124 \r
125 \r
126 /** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions\r
127  *  @brief    Initialization and Configuration functions \r
128  *\r
129 @verbatim    \r
130   ==============================================================================\r
131               ##### Initialization and de-initialization functions #####\r
132   ==============================================================================\r
133     [..]\r
134       This section provides the CORTEX HAL driver functions allowing to configure Interrupts\r
135       Systick functionalities \r
136 \r
137 @endverbatim\r
138   * @{\r
139   */\r
140 \r
141 \r
142 /**\r
143   * @brief  Sets the priority grouping field (preemption priority and subpriority)\r
144   *         using the required unlock sequence.\r
145   * @param  PriorityGroup: The priority grouping bits length. \r
146   *         This parameter can be one of the following values:\r
147   *         @arg NVIC_PRIORITYGROUP_0: 0 bits for preemption priority\r
148   *                                    4 bits for subpriority\r
149   *         @arg NVIC_PRIORITYGROUP_1: 1 bits for preemption priority\r
150   *                                    3 bits for subpriority\r
151   *         @arg NVIC_PRIORITYGROUP_2: 2 bits for preemption priority\r
152   *                                    2 bits for subpriority\r
153   *         @arg NVIC_PRIORITYGROUP_3: 3 bits for preemption priority\r
154   *                                    1 bits for subpriority\r
155   *         @arg NVIC_PRIORITYGROUP_4: 4 bits for preemption priority\r
156   *                                    0 bits for subpriority\r
157   * @note   When the NVIC_PriorityGroup_0 is selected, IRQ preemption is no more possible. \r
158   *         The pending IRQ priority will be managed only by the subpriority. \r
159   * @retval None\r
160   */\r
161 void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)\r
162 {\r
163   /* Check the parameters */\r
164   assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));\r
165   \r
166   /* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */\r
167   NVIC_SetPriorityGrouping(PriorityGroup);\r
168 }\r
169 \r
170 /**\r
171   * @brief  Sets the priority of an interrupt.\r
172   * @param  IRQn: External interrupt number.\r
173   *         This parameter can be an enumerator of IRQn_Type enumeration\r
174   *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))\r
175   * @param  PreemptPriority: The preemption priority for the IRQn channel.\r
176   *         This parameter can be a value between 0 and 15\r
177   *         A lower priority value indicates a higher priority \r
178   * @param  SubPriority: the subpriority level for the IRQ channel.\r
179   *         This parameter can be a value between 0 and 15\r
180   *         A lower priority value indicates a higher priority.          \r
181   * @retval None\r
182   */\r
183 void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)\r
184\r
185   uint32_t prioritygroup = 0x00;\r
186   \r
187   /* Check the parameters */\r
188   assert_param(IS_NVIC_SUB_PRIORITY(SubPriority));\r
189   assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority));\r
190   \r
191   prioritygroup = NVIC_GetPriorityGrouping();\r
192   \r
193   NVIC_SetPriority(IRQn, NVIC_EncodePriority(prioritygroup, PreemptPriority, SubPriority));\r
194 }\r
195 \r
196 /**\r
197   * @brief  Enables a device specific interrupt in the NVIC interrupt controller.\r
198   * @note   To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()\r
199   *         function should be called before. \r
200   * @param  IRQn External interrupt number.\r
201   *         This parameter can be an enumerator of IRQn_Type enumeration\r
202   *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))\r
203   * @retval None\r
204   */\r
205 void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)\r
206 {\r
207   /* Check the parameters */\r
208   assert_param(IS_NVIC_DEVICE_IRQ(IRQn));\r
209   \r
210   /* Enable interrupt */\r
211   NVIC_EnableIRQ(IRQn);\r
212 }\r
213 \r
214 /**\r
215   * @brief  Disables a device specific interrupt in the NVIC interrupt controller.\r
216   * @param  IRQn External interrupt number.\r
217   *         This parameter can be an enumerator of IRQn_Type enumeration\r
218   *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))\r
219   * @retval None\r
220   */\r
221 void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)\r
222 {\r
223   /* Check the parameters */\r
224   assert_param(IS_NVIC_DEVICE_IRQ(IRQn));\r
225   \r
226   /* Disable interrupt */\r
227   NVIC_DisableIRQ(IRQn);\r
228 }\r
229 \r
230 /**\r
231   * @brief  Initiates a system reset request to reset the MCU.\r
232   * @retval None\r
233   */\r
234 void HAL_NVIC_SystemReset(void)\r
235 {\r
236   /* System Reset */\r
237   NVIC_SystemReset();\r
238 }\r
239 \r
240 /**\r
241   * @brief  Initializes the System Timer and its interrupt, and starts the System Tick Timer.\r
242   *         Counter is in free running mode to generate periodic interrupts.\r
243   * @param  TicksNumb: Specifies the ticks Number of ticks between two interrupts.\r
244   * @retval status:  - 0  Function succeeded.\r
245   *                  - 1  Function failed.\r
246   */\r
247 uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)\r
248 {\r
249    return SysTick_Config(TicksNumb);\r
250 }\r
251 /**\r
252   * @}\r
253   */\r
254 \r
255 /** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions\r
256  *  @brief   Cortex control functions \r
257  *\r
258 @verbatim   \r
259   ==============================================================================\r
260                       ##### Peripheral Control functions #####\r
261   ==============================================================================  \r
262     [..]\r
263       This subsection provides a set of functions allowing to control the CORTEX\r
264       (NVIC, SYSTICK, MPU) functionalities. \r
265  \r
266       \r
267 @endverbatim\r
268   * @{\r
269   */\r
270 \r
271 #if (__MPU_PRESENT == 1)\r
272 /**\r
273   * @brief  Initializes and configures the Region and the memory to be protected.\r
274   * @param  MPU_Init: Pointer to a MPU_Region_InitTypeDef structure that contains\r
275   *                the initialization and configuration information.\r
276   * @retval None\r
277   */\r
278 void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)\r
279 {\r
280   /* Check the parameters */\r
281   assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number));\r
282   assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable));\r
283 \r
284   /* Set the Region number */\r
285   MPU->RNR = MPU_Init->Number;\r
286 \r
287   if ((MPU_Init->Enable) != RESET)\r
288   {\r
289     /* Check the parameters */\r
290     assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec));\r
291     assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission));\r
292     assert_param(IS_MPU_TEX_LEVEL(MPU_Init->TypeExtField));\r
293     assert_param(IS_MPU_ACCESS_SHAREABLE(MPU_Init->IsShareable));\r
294     assert_param(IS_MPU_ACCESS_CACHEABLE(MPU_Init->IsCacheable));\r
295     assert_param(IS_MPU_ACCESS_BUFFERABLE(MPU_Init->IsBufferable));\r
296     assert_param(IS_MPU_SUB_REGION_DISABLE(MPU_Init->SubRegionDisable));\r
297     assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size));\r
298     \r
299     MPU->RBAR = MPU_Init->BaseAddress;\r
300     MPU->RASR = (MPU_Init->DisableExec             << MPU_RASR_XN_Pos)   |\r
301                 (MPU_Init->AccessPermission        << MPU_RASR_AP_Pos)   |\r
302                 (MPU_Init->TypeExtField            << MPU_RASR_TEX_Pos)  |\r
303                 (MPU_Init->IsShareable             << MPU_RASR_S_Pos)    |\r
304                 (MPU_Init->IsCacheable             << MPU_RASR_C_Pos)    |\r
305                 (MPU_Init->IsBufferable            << MPU_RASR_B_Pos)    |\r
306                 (MPU_Init->SubRegionDisable        << MPU_RASR_SRD_Pos)  |\r
307                 (MPU_Init->Size                    << MPU_RASR_SIZE_Pos) |\r
308                 (MPU_Init->Enable                  << MPU_RASR_ENABLE_Pos);\r
309   }\r
310   else\r
311   {\r
312     MPU->RBAR = 0x00;\r
313     MPU->RASR = 0x00;\r
314   }\r
315 }\r
316 #endif /* __MPU_PRESENT */\r
317 \r
318 /**\r
319   * @brief  Gets the priority grouping field from the NVIC Interrupt Controller.\r
320   * @retval Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)\r
321   */\r
322 uint32_t HAL_NVIC_GetPriorityGrouping(void)\r
323 {\r
324   /* Get the PRIGROUP[10:8] field value */\r
325   return NVIC_GetPriorityGrouping();\r
326 }\r
327 \r
328 /**\r
329   * @brief  Gets the priority of an interrupt.\r
330   * @param  IRQn: External interrupt number.\r
331   *         This parameter can be an enumerator of IRQn_Type enumeration\r
332   *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))\r
333   * @param   PriorityGroup: the priority grouping bits length.\r
334   *         This parameter can be one of the following values:\r
335   *           @arg NVIC_PRIORITYGROUP_0: 0 bits for preemption priority\r
336   *                                      4 bits for subpriority\r
337   *           @arg NVIC_PRIORITYGROUP_1: 1 bits for preemption priority\r
338   *                                      3 bits for subpriority\r
339   *           @arg NVIC_PRIORITYGROUP_2: 2 bits for preemption priority\r
340   *                                      2 bits for subpriority\r
341   *           @arg NVIC_PRIORITYGROUP_3: 3 bits for preemption priority\r
342   *                                      1 bits for subpriority\r
343   *           @arg NVIC_PRIORITYGROUP_4: 4 bits for preemption priority\r
344   *                                      0 bits for subpriority\r
345   * @param  pPreemptPriority: Pointer on the Preemptive priority value (starting from 0).\r
346   * @param  pSubPriority: Pointer on the Subpriority value (starting from 0).\r
347   * @retval None\r
348   */\r
349 void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPreemptPriority, uint32_t *pSubPriority)\r
350 {\r
351   /* Check the parameters */\r
352   assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));\r
353  /* Get priority for Cortex-M system or device specific interrupts */\r
354   NVIC_DecodePriority(NVIC_GetPriority(IRQn), PriorityGroup, pPreemptPriority, pSubPriority);\r
355 }\r
356 \r
357 /**\r
358   * @brief  Sets Pending bit of an external interrupt.\r
359   * @param  IRQn External interrupt number\r
360   *         This parameter can be an enumerator of IRQn_Type enumeration\r
361   *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))\r
362   * @retval None\r
363   */\r
364 void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)\r
365 {\r
366   /* Check the parameters */\r
367   assert_param(IS_NVIC_DEVICE_IRQ(IRQn));\r
368   \r
369   /* Set interrupt pending */\r
370   NVIC_SetPendingIRQ(IRQn);\r
371 }\r
372 \r
373 /**\r
374   * @brief  Gets Pending Interrupt (reads the pending register in the NVIC \r
375   *         and returns the pending bit for the specified interrupt).\r
376   * @param  IRQn External interrupt number.\r
377   *          This parameter can be an enumerator of IRQn_Type enumeration\r
378   *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))\r
379   * @retval status: - 0  Interrupt status is not pending.\r
380   *                 - 1  Interrupt status is pending.\r
381   */\r
382 uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)\r
383 {\r
384   /* Check the parameters */\r
385   assert_param(IS_NVIC_DEVICE_IRQ(IRQn));\r
386   \r
387   /* Return 1 if pending else 0 */\r
388   return NVIC_GetPendingIRQ(IRQn);\r
389 }\r
390 \r
391 /**\r
392   * @brief  Clears the pending bit of an external interrupt.\r
393   * @param  IRQn External interrupt number.\r
394   *         This parameter can be an enumerator of IRQn_Type enumeration\r
395   *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))\r
396   * @retval None\r
397   */\r
398 void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)\r
399 {\r
400   /* Check the parameters */\r
401   assert_param(IS_NVIC_DEVICE_IRQ(IRQn));\r
402   \r
403   /* Clear pending interrupt */\r
404   NVIC_ClearPendingIRQ(IRQn);\r
405 }\r
406 \r
407 /**\r
408   * @brief Gets active interrupt ( reads the active register in NVIC and returns the active bit).\r
409   * @param IRQn External interrupt number\r
410   *         This parameter can be an enumerator of IRQn_Type enumeration\r
411   *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f7xxxx.h))\r
412   * @retval status: - 0  Interrupt status is not pending.\r
413   *                 - 1  Interrupt status is pending.\r
414   */\r
415 uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)\r
416 {\r
417   /* Check the parameters */\r
418   assert_param(IS_NVIC_DEVICE_IRQ(IRQn));\r
419   \r
420   /* Return 1 if active else 0 */\r
421   return NVIC_GetActive(IRQn);\r
422 }\r
423 \r
424 /**\r
425   * @brief  Configures the SysTick clock source.\r
426   * @param  CLKSource: specifies the SysTick clock source.\r
427   *          This parameter can be one of the following values:\r
428   *             @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source.\r
429   *             @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.\r
430   * @retval None\r
431   */\r
432 void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)\r
433 {\r
434   /* Check the parameters */\r
435   assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));\r
436   if (CLKSource == SYSTICK_CLKSOURCE_HCLK)\r
437   {\r
438     SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;\r
439   }\r
440   else\r
441   {\r
442     SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;\r
443   }\r
444 }\r
445 \r
446 /**\r
447   * @brief  This function handles SYSTICK interrupt request.\r
448   * @retval None\r
449   */\r
450 void HAL_SYSTICK_IRQHandler(void)\r
451 {\r
452   HAL_SYSTICK_Callback();\r
453 }\r
454 \r
455 /**\r
456   * @brief  SYSTICK callback.\r
457   * @retval None\r
458   */\r
459 __weak void HAL_SYSTICK_Callback(void)\r
460 {\r
461   /* NOTE : This function Should not be modified, when the callback is needed,\r
462             the HAL_SYSTICK_Callback could be implemented in the user file\r
463    */\r
464 }\r
465 \r
466 /**\r
467   * @}\r
468   */\r
469 \r
470 /**\r
471   * @}\r
472   */\r
473 \r
474 #endif /* HAL_CORTEX_MODULE_ENABLED */\r
475 /**\r
476   * @}\r
477   */\r
478 \r
479 /**\r
480   * @}\r
481   */\r
482 \r
483 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r