Subversion Repositories DashDisplay

Rev

Rev 50 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 50 Rev 77
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32l1xx_hal_cortex.c
3
  * @file    stm32l1xx_hal_cortex.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @brief   CORTEX HAL module driver.
5
  * @brief   CORTEX HAL module driver.
6
  *
6
  *
7
  *          This file provides firmware functions to manage the following
7
  *          This file provides firmware functions to manage the following
8
  *          functionalities of the CORTEX:
8
  *          functionalities of the CORTEX:
9
  *           + Initialization and de-initialization functions
9
  *           + Initialization and de-initialization functions
10
  *           + Peripheral Control functions
10
  *           + Peripheral Control functions
11
  *          
11
  *          
12
  *  @verbatim    
12
  *  @verbatim    
13
  ==============================================================================
13
  ==============================================================================
14
                        ##### How to use this driver #####
14
                        ##### How to use this driver #####
15
  ==============================================================================
15
  ==============================================================================
16
 
16
 
17
    [..]  
17
    [..]  
18
    *** How to configure Interrupts using Cortex HAL driver ***
18
    *** How to configure Interrupts using Cortex HAL driver ***
19
    ===========================================================
19
    ===========================================================
20
    [..]    
20
    [..]    
21
    This section provide functions allowing to configure the NVIC interrupts (IRQ).
21
    This section provide functions allowing to configure the NVIC interrupts (IRQ).
22
    The Cortex-M3 exceptions are managed by CMSIS functions.
22
    The Cortex-M3 exceptions are managed by CMSIS functions.
23
   
23
   
24
    (#) Configure the NVIC Priority Grouping using HAL_NVIC_SetPriorityGrouping() function
24
    (#) Configure the NVIC Priority Grouping using HAL_NVIC_SetPriorityGrouping() function
25
 
25
 
26
     (#)  Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority()
26
     (#)  Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority()
27
 
27
 
28
     (#)  Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ()
28
     (#)  Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ()
29
     
29
     
30
 
30
 
31
     -@- When the NVIC_PRIORITYGROUP_0 is selected, IRQ pre-emption is no more possible.
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.
32
         The pending IRQ priority will be managed only by the sub priority.
33
   
33
   
34
     -@- IRQ priority order (sorted by highest to lowest priority):
34
     -@- IRQ priority order (sorted by highest to lowest priority):
35
        (+@) Lowest pre-emption priority
35
        (+@) Lowest pre-emption priority
36
        (+@) Lowest sub priority
36
        (+@) Lowest sub priority
37
        (+@) Lowest hardware priority (IRQ number)
37
        (+@) Lowest hardware priority (IRQ number)
38
 
38
 
39
    [..]  
39
    [..]  
40
    *** How to configure Systick using Cortex HAL driver ***
40
    *** How to configure Systick using Cortex HAL driver ***
41
    ========================================================
41
    ========================================================
42
    [..]
42
    [..]
43
    Setup SysTick Timer for 1 msec interrupts.
43
    Setup SysTick Timer for 1 msec interrupts.
44
           
44
           
45
   (+) The HAL_SYSTICK_Config()function calls the SysTick_Config() function which
45
   (+) The HAL_SYSTICK_Config()function calls the SysTick_Config() function which
46
       is a CMSIS function that:
46
       is a CMSIS function that:
47
        (++) Configures the SysTick Reload register with value passed as function parameter.
47
        (++) Configures the SysTick Reload register with value passed as function parameter.
48
        (++) Configures the SysTick IRQ priority to the lowest value (0x0F).
48
        (++) Configures the SysTick IRQ priority to the lowest value (0x0F).
49
        (++) Resets the SysTick Counter register.
49
        (++) Resets the SysTick Counter register.
50
        (++) Configures the SysTick Counter clock source to be Core Clock Source (HCLK).
50
        (++) Configures the SysTick Counter clock source to be Core Clock Source (HCLK).
51
        (++) Enables the SysTick Interrupt.
51
        (++) Enables the SysTick Interrupt.
52
        (++) Starts the SysTick Counter.
52
        (++) Starts the SysTick Counter.
53
   
53
   
54
   (+) You can change the SysTick Clock source to be HCLK_Div8 by calling the macro
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
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
56
       HAL_SYSTICK_Config() function call. The __HAL_CORTEX_SYSTICKCLK_CONFIG() macro is defined
57
       inside the stm32l1xx_hal_cortex.h file.
57
       inside the stm32l1xx_hal_cortex.h file.
58
 
58
 
59
   (+) You can change the SysTick IRQ priority by calling the
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
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.
61
       call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function.
62
 
62
 
63
   (+) To adjust the SysTick time base, use the following formula:
63
   (+) To adjust the SysTick time base, use the following formula:
64
                           
64
                           
65
       Reload Value = SysTick Counter Clock (Hz) x  Desired Time base (s)
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
66
       (++) Reload Value is the parameter to be passed for HAL_SYSTICK_Config() function
67
       (++) Reload Value should not exceed 0xFFFFFF
67
       (++) Reload Value should not exceed 0xFFFFFF
68
   
68
   
69
  @endverbatim
69
  @endverbatim
70
  ******************************************************************************
70
  ******************************************************************************
71
  * @attention
71
  * @attention
72
  *
72
  *
73
  * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
73
  * Copyright (c) 2017 STMicroelectronics.
74
  * All rights reserved.</center></h2>
74
  * All rights reserved.
75
  *
75
  *
76
  * This software component is licensed by ST under BSD 3-Clause license,
76
  * This software is licensed under terms that can be found in the LICENSE file in
77
  * the "License"; You may not use this file except in compliance with the
77
  * the root directory of this software component.
78
  * License. You may obtain a copy of the License at:
78
  * If no LICENSE file comes with this software, it is provided AS-IS.
79
  *                        opensource.org/licenses/BSD-3-Clause
79
  *
80
  *
80
  ******************************************************************************
81
  ******************************************************************************
81
  */
82
  */
82
 
83
 
83
/*
84
/*
84
  Additional Tables: CORTEX_NVIC_Priority_Table
85
  Additional Tables: CORTEX_NVIC_Priority_Table
85
     The table below gives the allowed values of the pre-emption priority and subpriority according
86
     The table below gives the allowed values of the pre-emption priority and subpriority according
86
     to the Priority Grouping configuration performed by HAL_NVIC_SetPriorityGrouping() function.
87
     to the Priority Grouping configuration performed by HAL_NVIC_SetPriorityGrouping() function.
87
       ==========================================================================================================================
88
       ==========================================================================================================================
88
         NVIC_PriorityGroup   | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority  |       Description
89
         NVIC_PriorityGroup   | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority  |       Description
89
       ==========================================================================================================================
90
       ==========================================================================================================================
90
        NVIC_PRIORITYGROUP_0  |                0                  |            0-15             | 0 bits for pre-emption priority
91
        NVIC_PRIORITYGROUP_0  |                0                  |            0-15             | 0 bits for pre-emption priority
91
                              |                                   |                             | 4 bits for subpriority
92
                              |                                   |                             | 4 bits for subpriority
92
       --------------------------------------------------------------------------------------------------------------------------
93
       --------------------------------------------------------------------------------------------------------------------------
93
        NVIC_PRIORITYGROUP_1  |                0-1                |            0-7              | 1 bits for pre-emption priority
94
        NVIC_PRIORITYGROUP_1  |                0-1                |            0-7              | 1 bits for pre-emption priority
94
                              |                                   |                             | 3 bits for subpriority
95
                              |                                   |                             | 3 bits for subpriority
95
       --------------------------------------------------------------------------------------------------------------------------    
96
       --------------------------------------------------------------------------------------------------------------------------    
96
        NVIC_PRIORITYGROUP_2  |                0-3                |            0-3              | 2 bits for pre-emption priority
97
        NVIC_PRIORITYGROUP_2  |                0-3                |            0-3              | 2 bits for pre-emption priority
97
                              |                                   |                             | 2 bits for subpriority
98
                              |                                   |                             | 2 bits for subpriority
98
       --------------------------------------------------------------------------------------------------------------------------    
99
       --------------------------------------------------------------------------------------------------------------------------    
99
        NVIC_PRIORITYGROUP_3  |                0-7                |            0-1              | 3 bits for pre-emption priority
100
        NVIC_PRIORITYGROUP_3  |                0-7                |            0-1              | 3 bits for pre-emption priority
100
                              |                                   |                             | 1 bits for subpriority
101
                              |                                   |                             | 1 bits for subpriority
101
       --------------------------------------------------------------------------------------------------------------------------    
102
       --------------------------------------------------------------------------------------------------------------------------    
102
        NVIC_PRIORITYGROUP_4  |                0-15               |            0                | 4 bits for pre-emption priority
103
        NVIC_PRIORITYGROUP_4  |                0-15               |            0                | 4 bits for pre-emption priority
103
                              |                                   |                             | 0 bits for subpriority                      
104
                              |                                   |                             | 0 bits for subpriority                      
104
       ==========================================================================================================================
105
       ==========================================================================================================================
105
*/
106
*/
106
 
107
 
107
/* Includes ------------------------------------------------------------------*/
108
/* Includes ------------------------------------------------------------------*/
108
#include "stm32l1xx_hal.h"
109
#include "stm32l1xx_hal.h"
109
 
110
 
110
/** @addtogroup STM32L1xx_HAL_Driver
111
/** @addtogroup STM32L1xx_HAL_Driver
111
  * @{
112
  * @{
112
  */
113
  */
113
 
114
 
114
/** @defgroup CORTEX CORTEX
115
/** @defgroup CORTEX CORTEX
115
  * @brief CORTEX HAL module driver
116
  * @brief CORTEX HAL module driver
116
  * @{
117
  * @{
117
  */
118
  */
118
 
119
 
119
#ifdef HAL_CORTEX_MODULE_ENABLED
120
#ifdef HAL_CORTEX_MODULE_ENABLED
120
 
121
 
121
/* Private typedef -----------------------------------------------------------*/
122
/* Private typedef -----------------------------------------------------------*/
122
/* Private define ------------------------------------------------------------*/
123
/* Private define ------------------------------------------------------------*/
123
/* Private macro -------------------------------------------------------------*/
124
/* Private macro -------------------------------------------------------------*/
124
/* Private variables ---------------------------------------------------------*/
125
/* Private variables ---------------------------------------------------------*/
125
/* Private function prototypes -----------------------------------------------*/
126
/* Private function prototypes -----------------------------------------------*/
126
/* Private functions ---------------------------------------------------------*/
127
/* Private functions ---------------------------------------------------------*/
127
 
128
 
128
/** @defgroup CORTEX_Exported_Functions CORTEX Exported Functions
129
/** @defgroup CORTEX_Exported_Functions CORTEX Exported Functions
129
  * @{
130
  * @{
130
  */
131
  */
131
 
132
 
132
 
133
 
133
/** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
134
/** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
134
 *  @brief    Initialization and Configuration functions
135
 *  @brief    Initialization and Configuration functions
135
 *
136
 *
136
@verbatim    
137
@verbatim    
137
  ==============================================================================
138
  ==============================================================================
138
              ##### Initialization and de-initialization functions #####
139
              ##### Initialization and de-initialization functions #####
139
  ==============================================================================
140
  ==============================================================================
140
    [..]
141
    [..]
141
      This section provide the Cortex HAL driver functions allowing to configure Interrupts
142
      This section provide the Cortex HAL driver functions allowing to configure Interrupts
142
      Systick functionalities
143
      Systick functionalities
143
 
144
 
144
@endverbatim
145
@endverbatim
145
  * @{
146
  * @{
146
  */
147
  */
147
 
148
 
148
 
149
 
149
/**
150
/**
150
  * @brief  Sets the priority grouping field (pre-emption priority and subpriority)
151
  * @brief  Sets the priority grouping field (pre-emption priority and subpriority)
151
  *         using the required unlock sequence.
152
  *         using the required unlock sequence.
152
  * @param  PriorityGroup The priority grouping bits length.
153
  * @param  PriorityGroup The priority grouping bits length.
153
  *         This parameter can be one of the following values:
154
  *         This parameter can be one of the following values:
154
  *         @arg NVIC_PRIORITYGROUP_0: 0 bits for pre-emption priority
155
  *         @arg NVIC_PRIORITYGROUP_0: 0 bits for pre-emption priority
155
  *                                    4 bits for subpriority
156
  *                                    4 bits for subpriority
156
  *         @arg NVIC_PRIORITYGROUP_1: 1 bits for pre-emption priority
157
  *         @arg NVIC_PRIORITYGROUP_1: 1 bits for pre-emption priority
157
  *                                    3 bits for subpriority
158
  *                                    3 bits for subpriority
158
  *         @arg NVIC_PRIORITYGROUP_2: 2 bits for pre-emption priority
159
  *         @arg NVIC_PRIORITYGROUP_2: 2 bits for pre-emption priority
159
  *                                    2 bits for subpriority
160
  *                                    2 bits for subpriority
160
  *         @arg NVIC_PRIORITYGROUP_3: 3 bits for pre-emption priority
161
  *         @arg NVIC_PRIORITYGROUP_3: 3 bits for pre-emption priority
161
  *                                    1 bits for subpriority
162
  *                                    1 bits for subpriority
162
  *         @arg NVIC_PRIORITYGROUP_4: 4 bits for pre-emption priority
163
  *         @arg NVIC_PRIORITYGROUP_4: 4 bits for pre-emption priority
163
  *                                    0 bits for subpriority
164
  *                                    0 bits for subpriority
164
  * @note   When the NVIC_PriorityGroup_0 is selected, IRQ pre-emption is no more possible.
165
  * @note   When the NVIC_PriorityGroup_0 is selected, IRQ pre-emption is no more possible.
165
  *         The pending IRQ priority will be managed only by the subpriority.
166
  *         The pending IRQ priority will be managed only by the subpriority.
166
  * @retval None
167
  * @retval None
167
  */
168
  */
168
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
169
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
169
{
170
{
170
  /* Check the parameters */
171
  /* Check the parameters */
171
  assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
172
  assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
172
 
173
 
173
  /* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */
174
  /* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */
174
  NVIC_SetPriorityGrouping(PriorityGroup);
175
  NVIC_SetPriorityGrouping(PriorityGroup);
175
}
176
}
176
 
177
 
177
/**
178
/**
178
  * @brief  Sets the priority of an interrupt.
179
  * @brief  Sets the priority of an interrupt.
179
  * @param  IRQn External interrupt number
180
  * @param  IRQn External interrupt number
180
  *         This parameter can be an enumerator of IRQn_Type enumeration
181
  *         This parameter can be an enumerator of IRQn_Type enumeration
181
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xx.h))
182
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xx.h))
182
  * @param  PreemptPriority The pre-emption priority for the IRQn channel.
183
  * @param  PreemptPriority The pre-emption priority for the IRQn channel.
183
  *         This parameter can be a value between 0 and 15
184
  *         This parameter can be a value between 0 and 15
184
  *         A lower priority value indicates a higher priority
185
  *         A lower priority value indicates a higher priority
185
  * @param  SubPriority the subpriority level for the IRQ channel.
186
  * @param  SubPriority the subpriority level for the IRQ channel.
186
  *         This parameter can be a value between 0 and 15
187
  *         This parameter can be a value between 0 and 15
187
  *         A lower priority value indicates a higher priority.          
188
  *         A lower priority value indicates a higher priority.          
188
  * @retval None
189
  * @retval None
189
  */
190
  */
190
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
191
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
191
{
192
{
192
  uint32_t prioritygroup = 0x00;
193
  uint32_t prioritygroup = 0x00;
193
 
194
 
194
  /* Check the parameters */
195
  /* Check the parameters */
195
  assert_param(IS_NVIC_SUB_PRIORITY(SubPriority));
196
  assert_param(IS_NVIC_SUB_PRIORITY(SubPriority));
196
  assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority));
197
  assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority));
197
 
198
 
198
  prioritygroup = NVIC_GetPriorityGrouping();
199
  prioritygroup = NVIC_GetPriorityGrouping();
199
 
200
 
200
  NVIC_SetPriority(IRQn, NVIC_EncodePriority(prioritygroup, PreemptPriority, SubPriority));
201
  NVIC_SetPriority(IRQn, NVIC_EncodePriority(prioritygroup, PreemptPriority, SubPriority));
201
}
202
}
202
 
203
 
203
/**
204
/**
204
  * @brief  Enables a device specific interrupt in the NVIC interrupt controller.
205
  * @brief  Enables a device specific interrupt in the NVIC interrupt controller.
205
  * @note   To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
206
  * @note   To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
206
  *         function should be called before.
207
  *         function should be called before.
207
  * @param  IRQn External interrupt number
208
  * @param  IRQn External interrupt number
208
  *         This parameter can be an enumerator of IRQn_Type enumeration
209
  *         This parameter can be an enumerator of IRQn_Type enumeration
209
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xx.h))
210
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xx.h))
210
  * @retval None
211
  * @retval None
211
  */
212
  */
212
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
213
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
213
{
214
{
214
  /* Check the parameters */
215
  /* Check the parameters */
215
  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
216
  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
216
 
217
 
217
  /* Enable interrupt */
218
  /* Enable interrupt */
218
  NVIC_EnableIRQ(IRQn);
219
  NVIC_EnableIRQ(IRQn);
219
}
220
}
220
 
221
 
221
/**
222
/**
222
  * @brief  Disables a device specific interrupt in the NVIC interrupt controller.
223
  * @brief  Disables a device specific interrupt in the NVIC interrupt controller.
223
  * @param  IRQn External interrupt number
224
  * @param  IRQn External interrupt number
224
  *         This parameter can be an enumerator of IRQn_Type enumeration
225
  *         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 (stm32l1xxxx.h))  
226
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h))  
226
  * @retval None
227
  * @retval None
227
  */
228
  */
228
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
229
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
229
{
230
{
230
  /* Check the parameters */
231
  /* Check the parameters */
231
  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
232
  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
232
 
233
 
233
  /* Disable interrupt */
234
  /* Disable interrupt */
234
  NVIC_DisableIRQ(IRQn);
235
  NVIC_DisableIRQ(IRQn);
235
}
236
}
236
 
237
 
237
/**
238
/**
238
  * @brief  Initiates a system reset request to reset the MCU.
239
  * @brief  Initiates a system reset request to reset the MCU.
239
  * @retval None
240
  * @retval None
240
  */
241
  */
241
void HAL_NVIC_SystemReset(void)
242
void HAL_NVIC_SystemReset(void)
242
{
243
{
243
  /* System Reset */
244
  /* System Reset */
244
  NVIC_SystemReset();
245
  NVIC_SystemReset();
245
}
246
}
246
 
247
 
247
/**
248
/**
248
  * @brief  Initializes the System Timer and its interrupt, and starts the System Tick Timer.
249
  * @brief  Initializes the System Timer and its interrupt, and starts the System Tick Timer.
249
  *         Counter is in free running mode to generate periodic interrupts.
250
  *         Counter is in free running mode to generate periodic interrupts.
250
  * @param  TicksNumb Specifies the ticks Number of ticks between two interrupts.
251
  * @param  TicksNumb Specifies the ticks Number of ticks between two interrupts.
251
  * @retval status:  - 0  Function succeeded.
252
  * @retval status:  - 0  Function succeeded.
252
  *                  - 1  Function failed.
253
  *                  - 1  Function failed.
253
  */
254
  */
254
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
255
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
255
{
256
{
256
   return SysTick_Config(TicksNumb);
257
   return SysTick_Config(TicksNumb);
257
}
258
}
258
/**
259
/**
259
  * @}
260
  * @}
260
  */
261
  */
261
 
262
 
262
/** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions
263
/** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions
263
 *  @brief    Cortex control functions
264
 *  @brief    Cortex control functions
264
 *
265
 *
265
@verbatim  
266
@verbatim  
266
  ==============================================================================
267
  ==============================================================================
267
                      ##### Peripheral Control functions #####
268
                      ##### Peripheral Control functions #####
268
  ==============================================================================
269
  ==============================================================================
269
    [..]
270
    [..]
270
      This subsection provides a set of functions allowing to control the CORTEX
271
      This subsection provides a set of functions allowing to control the CORTEX
271
      (NVIC, SYSTICK, MPU) functionalities.
272
      (NVIC, SYSTICK, MPU) functionalities.
272
 
273
 
273
     
274
     
274
@endverbatim
275
@endverbatim
275
  * @{
276
  * @{
276
  */
277
  */
277
 
278
 
278
#if (__MPU_PRESENT == 1)
279
#if (__MPU_PRESENT == 1)
279
/**
280
/**
280
  * @brief  Enable the MPU.
281
  * @brief  Enable the MPU.
281
  * @param  MPU_Control Specifies the control mode of the MPU during hard fault,
282
  * @param  MPU_Control Specifies the control mode of the MPU during hard fault,
282
  *          NMI, FAULTMASK and privileged accessto the default memory
283
  *          NMI, FAULTMASK and privileged accessto the default memory
283
  *          This parameter can be one of the following values:
284
  *          This parameter can be one of the following values:
284
  *            @arg MPU_HFNMI_PRIVDEF_NONE
285
  *            @arg MPU_HFNMI_PRIVDEF_NONE
285
  *            @arg MPU_HARDFAULT_NMI
286
  *            @arg MPU_HARDFAULT_NMI
286
  *            @arg MPU_PRIVILEGED_DEFAULT
287
  *            @arg MPU_PRIVILEGED_DEFAULT
287
  *            @arg MPU_HFNMI_PRIVDEF
288
  *            @arg MPU_HFNMI_PRIVDEF
288
  * @retval None
289
  * @retval None
289
  */
290
  */
290
void HAL_MPU_Enable(uint32_t MPU_Control)
291
void HAL_MPU_Enable(uint32_t MPU_Control)
291
{
292
{
292
  /* Enable the MPU */
293
  /* Enable the MPU */
293
  MPU->CTRL = (MPU_Control | MPU_CTRL_ENABLE_Msk);
294
  MPU->CTRL = (MPU_Control | MPU_CTRL_ENABLE_Msk);
294
 
295
 
295
  /* Ensure MPU setting take effects */
296
  /* Ensure MPU setting take effects */
296
  __DSB();
297
  __DSB();
297
  __ISB();
298
  __ISB();
298
}
299
}
299
 
300
 
300
/**
301
/**
301
  * @brief  Disable the MPU.
302
  * @brief  Disable the MPU.
302
  * @retval None
303
  * @retval None
303
  */
304
  */
304
void HAL_MPU_Disable(void)
305
void HAL_MPU_Disable(void)
305
{
306
{
306
  /* Make sure outstanding transfers are done */
307
  /* Make sure outstanding transfers are done */
307
  __DMB();
308
  __DMB();
308
 
309
 
309
  /* Disable the MPU and clear the control register*/
310
  /* Disable the MPU and clear the control register*/
310
  MPU->CTRL  = 0;
311
  MPU->CTRL  = 0;
311
}
312
}
312
 
313
 
313
/**
314
/**
314
  * @brief  Initializes and configures the Region and the memory to be protected.
315
  * @brief  Initializes and configures the Region and the memory to be protected.
315
  * @param  MPU_Init Pointer to a MPU_Region_InitTypeDef structure that contains
316
  * @param  MPU_Init Pointer to a MPU_Region_InitTypeDef structure that contains
316
  *                the initialization and configuration information.
317
  *                the initialization and configuration information.
317
  * @retval None
318
  * @retval None
318
  */
319
  */
319
void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
320
void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
320
{
321
{
321
  /* Check the parameters */
322
  /* Check the parameters */
322
  assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number));
323
  assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number));
323
  assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable));
324
  assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable));
324
 
325
 
325
  /* Set the Region number */
326
  /* Set the Region number */
326
  MPU->RNR = MPU_Init->Number;
327
  MPU->RNR = MPU_Init->Number;
327
 
328
 
328
  if ((MPU_Init->Enable) != RESET)
329
  if ((MPU_Init->Enable) != RESET)
329
  {
330
  {
330
    /* Check the parameters */
331
    /* Check the parameters */
331
    assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec));
332
    assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec));
332
    assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission));
333
    assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission));
333
    assert_param(IS_MPU_TEX_LEVEL(MPU_Init->TypeExtField));
334
    assert_param(IS_MPU_TEX_LEVEL(MPU_Init->TypeExtField));
334
    assert_param(IS_MPU_ACCESS_SHAREABLE(MPU_Init->IsShareable));
335
    assert_param(IS_MPU_ACCESS_SHAREABLE(MPU_Init->IsShareable));
335
    assert_param(IS_MPU_ACCESS_CACHEABLE(MPU_Init->IsCacheable));
336
    assert_param(IS_MPU_ACCESS_CACHEABLE(MPU_Init->IsCacheable));
336
    assert_param(IS_MPU_ACCESS_BUFFERABLE(MPU_Init->IsBufferable));
337
    assert_param(IS_MPU_ACCESS_BUFFERABLE(MPU_Init->IsBufferable));
337
    assert_param(IS_MPU_SUB_REGION_DISABLE(MPU_Init->SubRegionDisable));
338
    assert_param(IS_MPU_SUB_REGION_DISABLE(MPU_Init->SubRegionDisable));
338
    assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size));
339
    assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size));
339
   
340
   
340
    MPU->RBAR = MPU_Init->BaseAddress;
341
    MPU->RBAR = MPU_Init->BaseAddress;
341
    MPU->RASR = ((uint32_t)MPU_Init->DisableExec             << MPU_RASR_XN_Pos)   |
342
    MPU->RASR = ((uint32_t)MPU_Init->DisableExec             << MPU_RASR_XN_Pos)   |
342
                ((uint32_t)MPU_Init->AccessPermission        << MPU_RASR_AP_Pos)   |
343
                ((uint32_t)MPU_Init->AccessPermission        << MPU_RASR_AP_Pos)   |
343
                ((uint32_t)MPU_Init->TypeExtField            << MPU_RASR_TEX_Pos)  |
344
                ((uint32_t)MPU_Init->TypeExtField            << MPU_RASR_TEX_Pos)  |
344
                ((uint32_t)MPU_Init->IsShareable             << MPU_RASR_S_Pos)    |
345
                ((uint32_t)MPU_Init->IsShareable             << MPU_RASR_S_Pos)    |
345
                ((uint32_t)MPU_Init->IsCacheable             << MPU_RASR_C_Pos)    |
346
                ((uint32_t)MPU_Init->IsCacheable             << MPU_RASR_C_Pos)    |
346
                ((uint32_t)MPU_Init->IsBufferable            << MPU_RASR_B_Pos)    |
347
                ((uint32_t)MPU_Init->IsBufferable            << MPU_RASR_B_Pos)    |
347
                ((uint32_t)MPU_Init->SubRegionDisable        << MPU_RASR_SRD_Pos)  |
348
                ((uint32_t)MPU_Init->SubRegionDisable        << MPU_RASR_SRD_Pos)  |
348
                ((uint32_t)MPU_Init->Size                    << MPU_RASR_SIZE_Pos) |
349
                ((uint32_t)MPU_Init->Size                    << MPU_RASR_SIZE_Pos) |
349
                ((uint32_t)MPU_Init->Enable                  << MPU_RASR_ENABLE_Pos);
350
                ((uint32_t)MPU_Init->Enable                  << MPU_RASR_ENABLE_Pos);
350
  }
351
  }
351
  else
352
  else
352
  {
353
  {
353
    MPU->RBAR = 0x00;
354
    MPU->RBAR = 0x00;
354
    MPU->RASR = 0x00;
355
    MPU->RASR = 0x00;
355
  }
356
  }
356
}
357
}
357
#endif /* __MPU_PRESENT */
358
#endif /* __MPU_PRESENT */
358
 
359
 
359
/**
360
/**
360
  * @brief  Gets the priority grouping field from the NVIC Interrupt Controller.
361
  * @brief  Gets the priority grouping field from the NVIC Interrupt Controller.
361
  * @retval Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)
362
  * @retval Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)
362
  */
363
  */
363
uint32_t HAL_NVIC_GetPriorityGrouping(void)
364
uint32_t HAL_NVIC_GetPriorityGrouping(void)
364
{
365
{
365
  /* Get the PRIGROUP[10:8] field value */
366
  /* Get the PRIGROUP[10:8] field value */
366
  return NVIC_GetPriorityGrouping();
367
  return NVIC_GetPriorityGrouping();
367
}
368
}
368
 
369
 
369
/**
370
/**
370
  * @brief  Gets the priority of an interrupt.
371
  * @brief  Gets the priority of an interrupt.
371
  * @param  IRQn External interrupt number
372
  * @param  IRQn External interrupt number
372
  *         This parameter can be an enumerator of IRQn_Type enumeration
373
  *         This parameter can be an enumerator of IRQn_Type enumeration
373
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h))
374
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h))
374
  * @param  PriorityGroup the priority grouping bits length.
375
  * @param  PriorityGroup the priority grouping bits length.
375
  *         This parameter can be one of the following values:
376
  *         This parameter can be one of the following values:
376
  *           @arg NVIC_PRIORITYGROUP_0: 0 bits for pre-emption priority
377
  *           @arg NVIC_PRIORITYGROUP_0: 0 bits for pre-emption priority
377
  *                                      4 bits for subpriority
378
  *                                      4 bits for subpriority
378
  *           @arg NVIC_PRIORITYGROUP_1: 1 bits for pre-emption priority
379
  *           @arg NVIC_PRIORITYGROUP_1: 1 bits for pre-emption priority
379
  *                                      3 bits for subpriority
380
  *                                      3 bits for subpriority
380
  *           @arg NVIC_PRIORITYGROUP_2: 2 bits for pre-emption priority
381
  *           @arg NVIC_PRIORITYGROUP_2: 2 bits for pre-emption priority
381
  *                                      2 bits for subpriority
382
  *                                      2 bits for subpriority
382
  *           @arg NVIC_PRIORITYGROUP_3: 3 bits for pre-emption priority
383
  *           @arg NVIC_PRIORITYGROUP_3: 3 bits for pre-emption priority
383
  *                                      1 bits for subpriority
384
  *                                      1 bits for subpriority
384
  *           @arg NVIC_PRIORITYGROUP_4: 4 bits for pre-emption priority
385
  *           @arg NVIC_PRIORITYGROUP_4: 4 bits for pre-emption priority
385
  *                                      0 bits for subpriority
386
  *                                      0 bits for subpriority
386
  * @param  pPreemptPriority Pointer on the Preemptive priority value (starting from 0).
387
  * @param  pPreemptPriority Pointer on the Preemptive priority value (starting from 0).
387
  * @param  pSubPriority Pointer on the Subpriority value (starting from 0).
388
  * @param  pSubPriority Pointer on the Subpriority value (starting from 0).
388
  * @retval None
389
  * @retval None
389
  */
390
  */
390
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)
391
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)
391
{
392
{
392
  /* Check the parameters */
393
  /* Check the parameters */
393
  assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
394
  assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
394
 /* Get priority for Cortex-M system or device specific interrupts */
395
 /* Get priority for Cortex-M system or device specific interrupts */
395
  NVIC_DecodePriority(NVIC_GetPriority(IRQn), PriorityGroup, pPreemptPriority, pSubPriority);
396
  NVIC_DecodePriority(NVIC_GetPriority(IRQn), PriorityGroup, pPreemptPriority, pSubPriority);
396
}
397
}
397
 
398
 
398
/**
399
/**
399
  * @brief  Sets Pending bit of an external interrupt.
400
  * @brief  Sets Pending bit of an external interrupt.
400
  * @param  IRQn External interrupt number
401
  * @param  IRQn External interrupt number
401
  *         This parameter can be an enumerator of IRQn_Type enumeration
402
  *         This parameter can be an enumerator of IRQn_Type enumeration
402
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h))  
403
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h))  
403
  * @retval None
404
  * @retval None
404
  */
405
  */
405
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
406
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
406
{
407
{
407
  /* Set interrupt pending */
408
  /* Set interrupt pending */
408
  NVIC_SetPendingIRQ(IRQn);
409
  NVIC_SetPendingIRQ(IRQn);
409
}
410
}
410
 
411
 
411
/**
412
/**
412
  * @brief Gets Pending Interrupt (reads the pending register in the NVIC
413
  * @brief Gets Pending Interrupt (reads the pending register in the NVIC
413
  *         and returns the pending bit for the specified interrupt).
414
  *         and returns the pending bit for the specified interrupt).
414
  * @param IRQn External interrupt number
415
  * @param IRQn External interrupt number
415
  *         This parameter can be an enumerator of IRQn_Type enumeration
416
  *         This parameter can be an enumerator of IRQn_Type enumeration
416
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h))  
417
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h))  
417
  * @retval status: - 0  Interrupt status is not pending.
418
  * @retval status: - 0  Interrupt status is not pending.
418
  *                 - 1  Interrupt status is pending.
419
  *                 - 1  Interrupt status is pending.
419
  */
420
  */
420
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
421
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
421
{
422
{
422
  /* Return 1 if pending else 0 */
423
  /* Return 1 if pending else 0 */
423
  return NVIC_GetPendingIRQ(IRQn);
424
  return NVIC_GetPendingIRQ(IRQn);
424
}
425
}
425
 
426
 
426
/**
427
/**
427
  * @brief Clears the pending bit of an external interrupt.
428
  * @brief Clears the pending bit of an external interrupt.
428
  * @param IRQn External interrupt number
429
  * @param IRQn External interrupt number
429
  *         This parameter can be an enumerator of IRQn_Type enumeration
430
  *         This parameter can be an enumerator of IRQn_Type enumeration
430
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h))  
431
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h))  
431
  * @retval None
432
  * @retval None
432
  */
433
  */
433
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
434
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
434
{
435
{
435
  /* Clear pending interrupt */
436
  /* Clear pending interrupt */
436
  NVIC_ClearPendingIRQ(IRQn);
437
  NVIC_ClearPendingIRQ(IRQn);
437
}
438
}
438
 
439
 
439
/**
440
/**
440
  * @brief Gets active interrupt ( reads the active register in NVIC and returns the active bit).
441
  * @brief Gets active interrupt ( reads the active register in NVIC and returns the active bit).
441
  * @param IRQn External interrupt number
442
  * @param IRQn External interrupt number
442
  *         This parameter can be an enumerator of IRQn_Type enumeration
443
  *         This parameter can be an enumerator of IRQn_Type enumeration
443
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h))  
444
  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h))  
444
  * @retval status: - 0  Interrupt status is not pending.
445
  * @retval status: - 0  Interrupt status is not pending.
445
  *                 - 1  Interrupt status is pending.
446
  *                 - 1  Interrupt status is pending.
446
  */
447
  */
447
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
448
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
448
{
449
{
449
  /* Return 1 if active else 0 */
450
  /* Return 1 if active else 0 */
450
  return NVIC_GetActive(IRQn);
451
  return NVIC_GetActive(IRQn);
451
}
452
}
452
 
453
 
453
/**
454
/**
454
  * @brief  Configures the SysTick clock source.
455
  * @brief  Configures the SysTick clock source.
455
  * @param  CLKSource specifies the SysTick clock source.
456
  * @param  CLKSource specifies the SysTick clock source.
456
  *         This parameter can be one of the following values:
457
  *         This parameter can be one of the following values:
457
  *             @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source.
458
  *             @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source.
458
  *             @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
459
  *             @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
459
  * @retval None
460
  * @retval None
460
  */
461
  */
461
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
462
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
462
{
463
{
463
  /* Check the parameters */
464
  /* Check the parameters */
464
  assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
465
  assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
465
  if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
466
  if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
466
  {
467
  {
467
    SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
468
    SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
468
  }
469
  }
469
  else
470
  else
470
  {
471
  {
471
    SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
472
    SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
472
  }
473
  }
473
}
474
}
474
 
475
 
475
/**
476
/**
476
  * @brief  This function handles SYSTICK interrupt request.
477
  * @brief  This function handles SYSTICK interrupt request.
477
  * @retval None
478
  * @retval None
478
  */
479
  */
479
void HAL_SYSTICK_IRQHandler(void)
480
void HAL_SYSTICK_IRQHandler(void)
480
{
481
{
481
  HAL_SYSTICK_Callback();
482
  HAL_SYSTICK_Callback();
482
}
483
}
483
 
484
 
484
/**
485
/**
485
  * @brief  SYSTICK callback.
486
  * @brief  SYSTICK callback.
486
  * @retval None
487
  * @retval None
487
  */
488
  */
488
__weak void HAL_SYSTICK_Callback(void)
489
__weak void HAL_SYSTICK_Callback(void)
489
{
490
{
490
  /* NOTE : This function Should not be modified, when the callback is needed,
491
  /* NOTE : This function Should not be modified, when the callback is needed,
491
            the HAL_SYSTICK_Callback could be implemented in the user file
492
            the HAL_SYSTICK_Callback could be implemented in the user file
492
   */
493
   */
493
}
494
}
494
 
495
 
495
/**
496
/**
496
  * @}
497
  * @}
497
  */
498
  */
498
 
499
 
499
/**
500
/**
500
  * @}
501
  * @}
501
  */
502
  */
502
 
503
 
503
#endif /* HAL_CORTEX_MODULE_ENABLED */
504
#endif /* HAL_CORTEX_MODULE_ENABLED */
504
/**
505
/**
505
  * @}
506
  * @}
506
  */
507
  */
507
 
508
 
508
/**
509
/**
509
  * @}
510
  * @}
510
  */
511
  */
511
 
512
 
-
 
513
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-