Subversion Repositories canSerial

Rev

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

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