Subversion Repositories DashDisplay

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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