Subversion Repositories DashDisplay

Rev

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

Rev 61 Rev 77
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32l1xx_hal.c
3
  * @file    stm32l1xx_hal.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @brief   HAL module driver.
5
  * @brief   HAL module driver.
6
  *          This is the common part of the HAL initialization
6
  *          This is the common part of the HAL initialization
7
  *
7
  *
8
  @verbatim
8
  ******************************************************************************
9
  ==============================================================================
9
  * @attention
10
                     ##### How to use this driver #####
10
  *
11
  ==============================================================================
11
  * Copyright (c) 2017 STMicroelectronics.
12
    [..]
12
  * All rights reserved.
13
    The common HAL driver contains a set of generic and common APIs that can be
13
  *
14
    used by the PPP peripheral drivers and the user to start using the HAL.
14
  * This software is licensed under terms that can be found in the LICENSE file
15
    [..]
15
  * in the root directory of this software component.
16
    The HAL contains two APIs categories:
16
  * If no LICENSE file comes with this software, it is provided AS-IS.
17
         (+) Common HAL APIs
17
  *
18
         (+) Services HAL APIs
18
  ******************************************************************************
19
 
19
  @verbatim
20
  @endverbatim
20
  ==============================================================================
21
  ******************************************************************************
21
                     ##### How to use this driver #####
22
  * @attention
22
  ==============================================================================
23
  *
23
    [..]
24
  * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
24
    The common HAL driver contains a set of generic and common APIs that can be
25
  * All rights reserved.</center></h2>
25
    used by the PPP peripheral drivers and the user to start using the HAL.
26
  *
26
    [..]
27
  * This software component is licensed by ST under BSD 3-Clause license,
27
    The HAL contains two APIs categories:
28
  * the "License"; You may not use this file except in compliance with the
28
         (+) Common HAL APIs
29
  * License. You may obtain a copy of the License at:
29
         (+) Services HAL APIs
30
  *                        opensource.org/licenses/BSD-3-Clause
30
 
31
  *
31
  @endverbatim
32
  ******************************************************************************
32
  ******************************************************************************
33
  */
33
  */
34
 
34
 
35
/* Includes ------------------------------------------------------------------*/
35
/* Includes ------------------------------------------------------------------*/
36
#include "stm32l1xx_hal.h"
36
#include "stm32l1xx_hal.h"
37
 
37
 
38
/** @addtogroup STM32L1xx_HAL_Driver
38
/** @addtogroup STM32L1xx_HAL_Driver
39
  * @{
39
  * @{
40
  */
40
  */
41
 
41
 
42
/** @defgroup HAL HAL
42
/** @defgroup HAL HAL
43
  * @brief HAL module driver.
43
  * @brief HAL module driver.
44
  * @{
44
  * @{
45
  */
45
  */
46
 
46
 
47
#ifdef HAL_MODULE_ENABLED
47
#ifdef HAL_MODULE_ENABLED
48
 
48
 
49
/* Private typedef -----------------------------------------------------------*/
49
/* Private typedef -----------------------------------------------------------*/
50
/* Private define ------------------------------------------------------------*/
50
/* Private define ------------------------------------------------------------*/
51
 
51
 
52
/** @defgroup HAL_Private_Defines HAL Private Defines
52
/** @defgroup HAL_Private_Defines HAL Private Defines
53
  * @{
53
  * @{
54
  */
54
  */
55
 
55
 
56
/**
56
/**
57
 * @brief STM32L1xx HAL Driver version number V1.4.4
57
 * @brief STM32L1xx HAL Driver version number
58
   */
58
   */
59
#define __STM32L1xx_HAL_VERSION_MAIN   (0x01) /*!< [31:24] main version */
59
#define __STM32L1xx_HAL_VERSION_MAIN   (0x01) /*!< [31:24] main version */
60
#define __STM32L1xx_HAL_VERSION_SUB1   (0x04) /*!< [23:16] sub1 version */
60
#define __STM32L1xx_HAL_VERSION_SUB1   (0x04) /*!< [23:16] sub1 version */
61
#define __STM32L1xx_HAL_VERSION_SUB2   (0x04) /*!< [15:8]  sub2 version */
61
#define __STM32L1xx_HAL_VERSION_SUB2   (0x05) /*!< [15:8]  sub2 version */
62
#define __STM32L1xx_HAL_VERSION_RC     (0x00) /*!< [7:0]  release candidate */
62
#define __STM32L1xx_HAL_VERSION_RC     (0x00) /*!< [7:0]  release candidate */
63
#define __STM32L1xx_HAL_VERSION         ((__STM32L1xx_HAL_VERSION_MAIN << 24)\
63
#define __STM32L1xx_HAL_VERSION         ((__STM32L1xx_HAL_VERSION_MAIN << 24)\
64
                                        |(__STM32L1xx_HAL_VERSION_SUB1 << 16)\
64
                                        |(__STM32L1xx_HAL_VERSION_SUB1 << 16)\
65
                                        |(__STM32L1xx_HAL_VERSION_SUB2 << 8 )\
65
                                        |(__STM32L1xx_HAL_VERSION_SUB2 << 8 )\
66
                                        |(__STM32L1xx_HAL_VERSION_RC))
66
                                        |(__STM32L1xx_HAL_VERSION_RC))
67
 
67
 
68
#define IDCODE_DEVID_MASK    (0x00000FFFU)
68
#define IDCODE_DEVID_MASK    (0x00000FFFU)
69
 
69
 
70
/**
70
/**
71
  * @}
71
  * @}
72
  */
72
  */
73
 
73
 
74
/* Private macro -------------------------------------------------------------*/
74
/* Private macro -------------------------------------------------------------*/
75
/* Private variables ---------------------------------------------------------*/
75
/* Private variables ---------------------------------------------------------*/
76
/* Private function prototypes -----------------------------------------------*/
76
/* Private function prototypes -----------------------------------------------*/
77
/* Private functions ---------------------------------------------------------*/
77
/* Private functions ---------------------------------------------------------*/
78
 
78
 
79
/* Exported variables --------------------------------------------------------*/
79
/* Exported variables --------------------------------------------------------*/
80
/** @addtogroup HAL_Exported_Variables
80
/** @addtogroup HAL_Exported_Variables
81
  * @{
81
  * @{
82
  */
82
  */
83
__IO uint32_t uwTick;
83
__IO uint32_t uwTick;
84
uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid priority */
84
uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid priority */
85
uint32_t uwTickFreq = HAL_TICK_FREQ_DEFAULT;  /* 1KHz */
85
uint32_t uwTickFreq = HAL_TICK_FREQ_DEFAULT;  /* 1KHz */
86
/**
86
/**
87
  * @}
87
  * @}
88
  */
88
  */
89
 
89
 
90
/* Exported functions --------------------------------------------------------*/
90
/* Exported functions --------------------------------------------------------*/
91
/** @defgroup HAL_Exported_Functions HAL Exported Functions
91
/** @defgroup HAL_Exported_Functions HAL Exported Functions
92
  * @{
92
  * @{
93
  */
93
  */
94
 
94
 
95
/** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions
95
/** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions
96
 *  @brief    Initialization and de-initialization functions
96
 *  @brief    Initialization and de-initialization functions
97
 *
97
 *
98
@verbatim
98
@verbatim
99
 ===============================================================================
99
 ===============================================================================
100
              ##### Initialization and de-initialization functions #####
100
              ##### Initialization and de-initialization functions #####
101
 ===============================================================================
101
 ===============================================================================
102
   [..]  This section provides functions allowing to:
102
   [..]  This section provides functions allowing to:
103
      (+) Initialize the Flash interface, the NVIC allocation and initial clock
103
      (+) Initialize the Flash interface, the NVIC allocation and initial clock
104
          configuration. It initializes the source of time base also when timeout
104
          configuration. It initializes the source of time base also when timeout
105
          is needed and the backup domain when enabled.
105
          is needed and the backup domain when enabled.
106
      (+) De-initialize common part of the HAL.
106
      (+) De-initialize common part of the HAL.
107
      (+) Configure the time base source to have 1ms time base with a dedicated
107
      (+) Configure the time base source to have 1ms time base with a dedicated
108
          Tick interrupt priority.
108
          Tick interrupt priority.
109
        (++) SysTick timer is used by default as source of time base, but user
109
        (++) SysTick timer is used by default as source of time base, but user
110
             can eventually implement his proper time base source (a general purpose
110
             can eventually implement his proper time base source (a general purpose
111
             timer for example or other time source), keeping in mind that Time base
111
             timer for example or other time source), keeping in mind that Time base
112
             duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
112
             duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
113
             handled in milliseconds basis.
113
             handled in milliseconds basis.
114
        (++) Time base configuration function (HAL_InitTick ()) is called automatically
114
        (++) Time base configuration function (HAL_InitTick ()) is called automatically
115
             at the beginning of the program after reset by HAL_Init() or at any time
115
             at the beginning of the program after reset by HAL_Init() or at any time
116
             when clock is configured, by HAL_RCC_ClockConfig().
116
             when clock is configured, by HAL_RCC_ClockConfig().
117
        (++) Source of time base is configured  to generate interrupts at regular
117
        (++) Source of time base is configured  to generate interrupts at regular
118
             time intervals. Care must be taken if HAL_Delay() is called from a
118
             time intervals. Care must be taken if HAL_Delay() is called from a
119
             peripheral ISR process, the Tick interrupt line must have higher priority
119
             peripheral ISR process, the Tick interrupt line must have higher priority
120
            (numerically lower) than the peripheral interrupt. Otherwise the caller
120
            (numerically lower) than the peripheral interrupt. Otherwise the caller
121
            ISR process will be blocked.
121
            ISR process will be blocked.
122
       (++) functions affecting time base configurations are declared as __weak
122
       (++) functions affecting time base configurations are declared as __weak
123
             to make  override possible  in case of other  implementations in user file.
123
             to make  override possible  in case of other  implementations in user file.
124
 
124
 
125
@endverbatim
125
@endverbatim
126
  * @{
126
  * @{
127
  */
127
  */
128
 
128
 
129
/**
129
/**
130
  * @brief This function configures the Flash prefetch,
130
  * @brief This function configures the Flash prefetch,
131
  *        configures time base source, NVIC and Low level hardware
131
  *        configures time base source, NVIC and Low level hardware
132
  * @note This function is called at the beginning of program after reset and before
132
  * @note This function is called at the beginning of program after reset and before
133
  *       the clock configuration
133
  *       the clock configuration
134
  * @note The time base configuration is based on MSI clock when exiting from Reset.
134
  * @note The time base configuration is based on MSI clock when exiting from Reset.
135
  *       Once done, time base tick start incrementing.
135
  *       Once done, time base tick start incrementing.
136
  *        In the default implementation,Systick is used as source of time base.
136
  *        In the default implementation,Systick is used as source of time base.
137
  *        the tick variable is incremented each 1ms in its ISR.
137
  *        the tick variable is incremented each 1ms in its ISR.
138
  * @retval HAL status
138
  * @retval HAL status
139
  */
139
  */
140
HAL_StatusTypeDef HAL_Init(void)
140
HAL_StatusTypeDef HAL_Init(void)
141
{
141
{
142
  HAL_StatusTypeDef  status = HAL_OK;
142
  HAL_StatusTypeDef  status = HAL_OK;
143
 
143
 
144
  /* Configure Flash prefetch */
144
  /* Configure Flash prefetch */
145
#if (PREFETCH_ENABLE != 0)
145
#if (PREFETCH_ENABLE != 0)
146
  __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
146
  __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
147
#endif /* PREFETCH_ENABLE */
147
#endif /* PREFETCH_ENABLE */
148
 
148
 
149
  /* Set Interrupt Group Priority */
149
  /* Set Interrupt Group Priority */
150
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
150
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
151
 
151
 
152
  /* Use systick as time base source and configure 1ms tick (default clock after Reset is MSI) */
152
  /* Use systick as time base source and configure 1ms tick (default clock after Reset is MSI) */
153
  if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
153
  if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
154
  {
154
  {
155
    status = HAL_ERROR;
155
    status = HAL_ERROR;
156
  }
156
  }
157
  else
157
  else
158
  {
158
  {
159
    /* Init the low level hardware */
159
    /* Init the low level hardware */
160
    HAL_MspInit();
160
    HAL_MspInit();
161
  }
161
  }
162
 
162
 
163
  /* Return function status */
163
  /* Return function status */
164
  return status;
164
  return status;
165
}
165
}
166
 
166
 
167
/**
167
/**
168
  * @brief This function de-initializes common part of the HAL and stops the source
168
  * @brief This function de-initializes common part of the HAL and stops the source
169
  *        of time base.
169
  *        of time base.
170
  * @note This function is optional.
170
  * @note This function is optional.
171
  * @retval HAL status
171
  * @retval HAL status
172
  */
172
  */
173
HAL_StatusTypeDef HAL_DeInit(void)
173
HAL_StatusTypeDef HAL_DeInit(void)
174
{
174
{
175
  /* Reset of all peripherals */
175
  /* Reset of all peripherals */
176
  __HAL_RCC_APB1_FORCE_RESET();
176
  __HAL_RCC_APB1_FORCE_RESET();
177
  __HAL_RCC_APB1_RELEASE_RESET();
177
  __HAL_RCC_APB1_RELEASE_RESET();
178
 
178
 
179
  __HAL_RCC_APB2_FORCE_RESET();
179
  __HAL_RCC_APB2_FORCE_RESET();
180
  __HAL_RCC_APB2_RELEASE_RESET();
180
  __HAL_RCC_APB2_RELEASE_RESET();
181
 
181
 
182
  __HAL_RCC_AHB_FORCE_RESET();
182
  __HAL_RCC_AHB_FORCE_RESET();
183
  __HAL_RCC_AHB_RELEASE_RESET();
183
  __HAL_RCC_AHB_RELEASE_RESET();
184
 
184
 
185
  /* De-Init the low level hardware */
185
  /* De-Init the low level hardware */
186
  HAL_MspDeInit();
186
  HAL_MspDeInit();
187
 
187
 
188
  /* Return function status */
188
  /* Return function status */
189
  return HAL_OK;
189
  return HAL_OK;
190
}
190
}
191
 
191
 
192
/**
192
/**
193
  * @brief  Initialize the MSP.
193
  * @brief  Initialize the MSP.
194
  * @retval None
194
  * @retval None
195
  */
195
  */
196
__weak void HAL_MspInit(void)
196
__weak void HAL_MspInit(void)
197
{
197
{
198
  /* NOTE : This function should not be modified, when the callback is needed,
198
  /* NOTE : This function should not be modified, when the callback is needed,
199
            the HAL_MspInit could be implemented in the user file
199
            the HAL_MspInit could be implemented in the user file
200
   */
200
   */
201
}
201
}
202
 
202
 
203
/**
203
/**
204
  * @brief  DeInitialize the MSP.
204
  * @brief  DeInitialize the MSP.
205
  * @retval None
205
  * @retval None
206
  */
206
  */
207
__weak void HAL_MspDeInit(void)
207
__weak void HAL_MspDeInit(void)
208
{
208
{
209
  /* NOTE : This function should not be modified, when the callback is needed,
209
  /* NOTE : This function should not be modified, when the callback is needed,
210
            the HAL_MspDeInit could be implemented in the user file
210
            the HAL_MspDeInit could be implemented in the user file
211
   */
211
   */
212
}
212
}
213
 
213
 
214
/**
214
/**
215
  * @brief This function configures the source of the time base:
215
  * @brief This function configures the source of the time base:
216
  *        The time source is configured to have 1ms time base with a dedicated
216
  *        The time source is configured to have 1ms time base with a dedicated
217
  *        Tick interrupt priority.
217
  *        Tick interrupt priority.
218
  * @note This function is called  automatically at the beginning of program after
218
  * @note This function is called  automatically at the beginning of program after
219
  *       reset by HAL_Init() or at any time when clock is reconfigured  by HAL_RCC_ClockConfig().
219
  *       reset by HAL_Init() or at any time when clock is reconfigured  by HAL_RCC_ClockConfig().
220
  * @note In the default implementation, SysTick timer is the source of time base.
220
  * @note In the default implementation, SysTick timer is the source of time base.
221
  *       It is used to generate interrupts at regular time intervals.
221
  *       It is used to generate interrupts at regular time intervals.
222
  *       Care must be taken if HAL_Delay() is called from a peripheral ISR process,
222
  *       Care must be taken if HAL_Delay() is called from a peripheral ISR process,
223
  *       The SysTick interrupt must have higher priority (numerically lower)
223
  *       The SysTick interrupt must have higher priority (numerically lower)
224
  *       than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
224
  *       than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
225
  *       The function is declared as __weak  to be overwritten  in case of other
225
  *       The function is declared as __weak  to be overwritten  in case of other
226
  *       implementation  in user file.
226
  *       implementation  in user file.
227
  * @param TickPriority Tick interrupt priority.
227
  * @param TickPriority Tick interrupt priority.
228
  * @retval HAL status
228
  * @retval HAL status
229
  */
229
  */
230
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
230
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
231
{
231
{
232
  HAL_StatusTypeDef  status = HAL_OK;
232
  HAL_StatusTypeDef  status = HAL_OK;
233
 
233
 
234
  if (uwTickFreq != 0U)
234
  if (uwTickFreq != 0U)
235
  {
235
  {
236
    /*Configure the SysTick to have interrupt in 1ms time basis*/
236
    /*Configure the SysTick to have interrupt in 1ms time basis*/
237
    if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) == 0U)
237
    if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) == 0U)
238
    {
238
    {
239
      /* Configure the SysTick IRQ priority */
239
      /* Configure the SysTick IRQ priority */
240
      if (TickPriority < (1UL << __NVIC_PRIO_BITS))
240
      if (TickPriority < (1UL << __NVIC_PRIO_BITS))
241
      {
241
      {
242
        HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
242
        HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
243
        uwTickPrio = TickPriority;
243
        uwTickPrio = TickPriority;
244
      }
244
      }
245
      else
245
      else
246
      {
246
      {
247
        status = HAL_ERROR;
247
        status = HAL_ERROR;
248
      }
248
      }
249
    }
249
    }
250
    else
250
    else
251
    {
251
    {
252
      status = HAL_ERROR;
252
      status = HAL_ERROR;
253
    }
253
    }
254
  }
254
  }
255
  else
255
  else
256
  {
256
  {
257
    status = HAL_ERROR;
257
    status = HAL_ERROR;
258
  }
258
  }
259
 
259
 
260
  /* Return function status */
260
  /* Return function status */
261
  return status;
261
  return status;
262
}
262
}
263
 
263
 
264
/**
264
/**
265
  * @}
265
  * @}
266
  */
266
  */
267
 
267
 
268
/** @defgroup HAL_Exported_Functions_Group2 HAL Control functions
268
/** @defgroup HAL_Exported_Functions_Group2 HAL Control functions
269
 *  @brief    HAL Control functions
269
 *  @brief    HAL Control functions
270
 *
270
 *
271
@verbatim
271
@verbatim
272
 ===============================================================================
272
 ===============================================================================
273
                      ##### HAL Control functions #####
273
                      ##### HAL Control functions #####
274
 ===============================================================================
274
 ===============================================================================
275
    [..]  This section provides functions allowing to:
275
    [..]  This section provides functions allowing to:
276
      (+) Provide a tick value in millisecond
276
      (+) Provide a tick value in millisecond
277
      (+) Provide a blocking delay in millisecond
277
      (+) Provide a blocking delay in millisecond
278
      (+) Suspend the time base source interrupt
278
      (+) Suspend the time base source interrupt
279
      (+) Resume the time base source interrupt
279
      (+) Resume the time base source interrupt
280
      (+) Get the HAL API driver version
280
      (+) Get the HAL API driver version
281
      (+) Get the device identifier
281
      (+) Get the device identifier
282
      (+) Get the device revision identifier
282
      (+) Get the device revision identifier
283
      (+) Get the unique device identifier
283
      (+) Get the unique device identifier
284
 
284
 
285
@endverbatim
285
@endverbatim
286
  * @{
286
  * @{
287
  */
287
  */
288
 
288
 
289
/**
289
/**
290
  * @brief This function is called to increment a global variable "uwTick"
290
  * @brief This function is called to increment a global variable "uwTick"
291
  *        used as application time base.
291
  *        used as application time base.
292
  * @note In the default implementation, this variable is incremented each 1ms
292
  * @note In the default implementation, this variable is incremented each 1ms
293
  *       in SysTick ISR.
293
  *       in SysTick ISR.
294
 * @note This function is declared as __weak to be overwritten in case of other
294
 * @note This function is declared as __weak to be overwritten in case of other
295
  *      implementations in user file.
295
  *      implementations in user file.
296
  * @retval None
296
  * @retval None
297
  */
297
  */
298
__weak void HAL_IncTick(void)
298
__weak void HAL_IncTick(void)
299
{
299
{
300
  uwTick += uwTickFreq;
300
  uwTick += uwTickFreq;
301
}
301
}
302
 
302
 
303
/**
303
/**
304
  * @brief Provide a tick value in millisecond.
304
  * @brief Provide a tick value in millisecond.
305
  * @note This function is declared as __weak to be overwritten in case of other
305
  * @note This function is declared as __weak to be overwritten in case of other
306
  *       implementations in user file.
306
  *       implementations in user file.
307
  * @retval tick value
307
  * @retval tick value
308
  */
308
  */
309
__weak uint32_t HAL_GetTick(void)
309
__weak uint32_t HAL_GetTick(void)
310
{
310
{
311
  return uwTick;
311
  return uwTick;
312
}
312
}
313
 
313
 
314
/**
314
/**
315
  * @brief This function returns a tick priority.
315
  * @brief This function returns a tick priority.
316
  * @retval tick priority
316
  * @retval tick priority
317
  */
317
  */
318
uint32_t HAL_GetTickPrio(void)
318
uint32_t HAL_GetTickPrio(void)
319
{
319
{
320
  return uwTickPrio;
320
  return uwTickPrio;
321
}
321
}
322
 
322
 
323
/**
323
/**
324
  * @brief Set new tick Freq.
324
  * @brief Set new tick Freq.
325
  * @param Freq tick frequency
325
  * @param Freq tick frequency
326
  * @retval HAL status
326
  * @retval HAL status
327
  */
327
  */
328
HAL_StatusTypeDef HAL_SetTickFreq(uint32_t Freq)
328
HAL_StatusTypeDef HAL_SetTickFreq(uint32_t Freq)
329
{
329
{
330
  HAL_StatusTypeDef status  = HAL_OK;
330
  HAL_StatusTypeDef status  = HAL_OK;
331
  uint32_t prevTickFreq;
331
  uint32_t prevTickFreq;
332
 
332
 
333
  assert_param(IS_TICKFREQ(Freq));
333
  assert_param(IS_TICKFREQ(Freq));
334
 
334
 
335
  if (uwTickFreq != Freq)
335
  if (uwTickFreq != Freq)
336
  {
336
  {
337
    /* Back up uwTickFreq frequency */
337
    /* Back up uwTickFreq frequency */
338
    prevTickFreq = uwTickFreq;
338
    prevTickFreq = uwTickFreq;
339
 
339
 
340
    /* Update uwTickFreq global variable used by HAL_InitTick() */
340
    /* Update uwTickFreq global variable used by HAL_InitTick() */
341
    uwTickFreq = Freq;
341
    uwTickFreq = Freq;
342
 
342
 
343
   /* Apply the new tick Freq  */
343
   /* Apply the new tick Freq  */
344
    status = HAL_InitTick(uwTickPrio);
344
    status = HAL_InitTick(uwTickPrio);
345
 
345
 
346
    if (status != HAL_OK)
346
    if (status != HAL_OK)
347
    {
347
    {
348
      /* Restore previous tick frequency */
348
      /* Restore previous tick frequency */
349
      uwTickFreq = prevTickFreq;
349
      uwTickFreq = prevTickFreq;
350
    }
350
    }
351
  }
351
  }
352
 
352
 
353
  return status;
353
  return status;
354
}
354
}
355
 
355
 
356
/**
356
/**
357
  * @brief Return tick frequency.
357
  * @brief Return tick frequency.
358
  * @retval tick period in Hz
358
  * @retval Tick frequency.
359
  */
359
  *         Value of @ref HAL_TickFreqTypeDef.
360
uint32_t HAL_GetTickFreq(void)
360
  */
361
{
361
uint32_t HAL_GetTickFreq(void)
362
  return uwTickFreq;
362
{
363
}
363
  return uwTickFreq;
364
 
364
}
365
/**
365
 
366
  * @brief This function provides minimum delay (in milliseconds) based
366
/**
367
  *        on variable incremented.
367
  * @brief This function provides minimum delay (in milliseconds) based
368
  * @note In the default implementation , SysTick timer is the source of time base.
368
  *        on variable incremented.
369
  *       It is used to generate interrupts at regular time intervals where uwTick
369
  * @note In the default implementation , SysTick timer is the source of time base.
370
  *       is incremented.
370
  *       It is used to generate interrupts at regular time intervals where uwTick
371
  * @note This function is declared as __weak to be overwritten in case of other
371
  *       is incremented.
372
  *       implementations in user file.
372
  * @note This function is declared as __weak to be overwritten in case of other
373
  * @param Delay specifies the delay time length, in milliseconds.
373
  *       implementations in user file.
374
  * @retval None
374
  * @param Delay specifies the delay time length, in milliseconds.
375
  */
375
  * @retval None
376
__weak void HAL_Delay(uint32_t Delay)
376
  */
377
{
377
__weak void HAL_Delay(uint32_t Delay)
378
  uint32_t tickstart = HAL_GetTick();
378
{
379
  uint32_t wait = Delay;
379
  uint32_t tickstart = HAL_GetTick();
380
 
380
  uint32_t wait = Delay;
381
  /* Add a period to guaranty minimum wait */
381
 
382
  if (wait < HAL_MAX_DELAY)
382
  /* Add a period to guaranty minimum wait */
383
  {
383
  if (wait < HAL_MAX_DELAY)
384
    wait += (uint32_t)(uwTickFreq);
384
  {
385
  }
385
    wait += (uint32_t)(uwTickFreq);
386
 
386
  }
387
  while((HAL_GetTick() - tickstart) < wait)
387
 
388
  {
388
  while((HAL_GetTick() - tickstart) < wait)
389
  }
389
  {
390
}
390
  }
391
 
391
}
392
/**
392
 
393
  * @brief Suspend the Tick increment.
393
/**
394
  * @note In the default implementation , SysTick timer is the source of time base. It is
394
  * @brief Suspend the Tick increment.
395
  *       used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
395
  * @note In the default implementation , SysTick timer is the source of time base. It is
396
  *       is called, the SysTick interrupt will be disabled and so Tick increment
396
  *       used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
397
  *       is suspended.
397
  *       is called, the SysTick interrupt will be disabled and so Tick increment
398
  * @note This function is declared as __weak to be overwritten in case of other
398
  *       is suspended.
399
  *       implementations in user file.
399
  * @note This function is declared as __weak to be overwritten in case of other
400
  * @retval None
400
  *       implementations in user file.
401
  */
401
  * @retval None
402
__weak void HAL_SuspendTick(void)
402
  */
403
{
403
__weak void HAL_SuspendTick(void)
404
  /* Disable SysTick Interrupt */
404
{
405
  CLEAR_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk);
405
  /* Disable SysTick Interrupt */
406
}
406
  CLEAR_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk);
407
 
407
}
408
/**
408
 
409
  * @brief Resume the Tick increment.
409
/**
410
  * @note In the default implementation , SysTick timer is the source of time base. It is
410
  * @brief Resume the Tick increment.
411
  *       used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
411
  * @note In the default implementation , SysTick timer is the source of time base. It is
412
  *       is called, the SysTick interrupt will be enabled and so Tick increment
412
  *       used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
413
  *       is resumed.
413
  *       is called, the SysTick interrupt will be enabled and so Tick increment
414
  * @note This function is declared as __weak to be overwritten in case of other
414
  *       is resumed.
415
  *       implementations in user file.
415
  * @note This function is declared as __weak to be overwritten in case of other
416
  * @retval None
416
  *       implementations in user file.
417
  */
417
  * @retval None
418
__weak void HAL_ResumeTick(void)
418
  */
419
{
419
__weak void HAL_ResumeTick(void)
420
  /* Enable SysTick Interrupt */
420
{
421
  SET_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk);
421
  /* Enable SysTick Interrupt */
422
}
422
  SET_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk);
423
 
423
}
424
/**
424
 
425
  * @brief Return the HAL revision
425
/**
426
  * @retval version: 0xXYZR (8bits for each decimal, R for RC)
426
  * @brief Return the HAL revision
427
  */
427
  * @retval version: 0xXYZR (8bits for each decimal, R for RC)
428
uint32_t HAL_GetHalVersion(void)
428
  */
429
{
429
uint32_t HAL_GetHalVersion(void)
430
  return __STM32L1xx_HAL_VERSION;
430
{
431
}
431
  return __STM32L1xx_HAL_VERSION;
432
 
432
}
433
/**
433
 
434
  * @brief Return the device revision identifier.
434
/**
435
  * @retval Device revision identifier
435
  * @brief Return the device revision identifier.
436
  */
436
  * @retval Device revision identifier
437
uint32_t HAL_GetREVID(void)
437
  */
438
{
438
uint32_t HAL_GetREVID(void)
439
  return((DBGMCU->IDCODE) >> 16U);
439
{
440
}
440
  return((DBGMCU->IDCODE) >> 16U);
441
 
441
}
442
/**
442
 
443
  * @brief  Return the device identifier.
443
/**
444
  * @retval Device identifier
444
  * @brief  Return the device identifier.
445
  */
445
  * @retval Device identifier
446
uint32_t HAL_GetDEVID(void)
446
  */
447
{
447
uint32_t HAL_GetDEVID(void)
448
   return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
448
{
449
}
449
   return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
450
 
450
}
451
/**
451
 
452
  * @brief  Return the first word of the unique device identifier (UID based on 96 bits)
452
/**
453
  * @retval Device identifier 31:0 bits
453
  * @brief  Return the first word of the unique device identifier (UID based on 96 bits)
454
  */
454
  * @retval Device identifier 31:0 bits
455
uint32_t HAL_GetUIDw0(void)
455
  */
456
{
456
uint32_t HAL_GetUIDw0(void)
457
  return(READ_REG(*((uint32_t *)UID_BASE)));
457
{
458
}
458
  return(READ_REG(*((uint32_t *)UID_BASE)));
459
 
459
}
460
/**
460
 
461
  * @brief  Return the second word of the unique device identifier (UID based on 96 bits)
461
/**
462
  * @retval Device identifier 63:32 bits
462
  * @brief  Return the second word of the unique device identifier (UID based on 96 bits)
463
  */
463
  * @retval Device identifier 63:32 bits
464
uint32_t HAL_GetUIDw1(void)
464
  */
465
{
465
uint32_t HAL_GetUIDw1(void)
466
  return(READ_REG(*((uint32_t *)(UID_BASE + 0x4U))));
466
{
467
}
467
  return(READ_REG(*((uint32_t *)(UID_BASE + 0x4U))));
468
 
468
}
469
/**
469
 
470
  * @brief  Return the third word of the unique device identifier (UID based on 96 bits)
470
/**
471
  * @retval Device identifier 95:64 bits
471
  * @brief  Return the third word of the unique device identifier (UID based on 96 bits)
472
  */
472
  * @retval Device identifier 95:64 bits
473
uint32_t HAL_GetUIDw2(void)
473
  */
474
{
474
uint32_t HAL_GetUIDw2(void)
475
  return(READ_REG(*((uint32_t *)(UID_BASE + 0x14U))));
475
{
476
}
476
  return(READ_REG(*((uint32_t *)(UID_BASE + 0x14U))));
477
 
477
}
478
/**
478
 
479
  * @}
479
/**
480
  */
480
  * @}
481
 
481
  */
482
/** @defgroup HAL_Exported_Functions_Group3 DBGMCU Peripheral Control functions
482
 
483
 *  @brief    DBGMCU Peripheral Control functions
483
/** @defgroup HAL_Exported_Functions_Group3 DBGMCU Peripheral Control functions
484
 *
484
 *  @brief    DBGMCU Peripheral Control functions
485
@verbatim
485
 *
486
 ===============================================================================
486
@verbatim
487
                      ##### DBGMCU Peripheral Control functions #####
487
 ===============================================================================
488
 ===============================================================================
488
                      ##### DBGMCU Peripheral Control functions #####
489
    [..]  This section provides functions allowing to:
489
 ===============================================================================
490
      (+) Enable/Disable Debug module during SLEEP mode
490
    [..]  This section provides functions allowing to:
491
      (+) Enable/Disable Debug module during STOP mode
491
      (+) Enable/Disable Debug module during SLEEP mode
492
      (+) Enable/Disable Debug module during STANDBY mode
492
      (+) Enable/Disable Debug module during STOP mode
493
 
493
      (+) Enable/Disable Debug module during STANDBY mode
494
@endverbatim
494
 
495
  * @{
495
@endverbatim
496
  */
496
  * @{
497
 
497
  */
498
/**
498
 
499
  * @brief  Enable the Debug Module during SLEEP mode
499
/**
500
  * @retval None
500
  * @brief  Enable the Debug Module during SLEEP mode
501
  */
501
  * @retval None
502
void HAL_DBGMCU_EnableDBGSleepMode(void)
502
  */
503
{
503
void HAL_DBGMCU_EnableDBGSleepMode(void)
504
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
504
{
505
}
505
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
506
 
506
}
507
/**
507
 
508
  * @brief  Disable the Debug Module during SLEEP mode
508
/**
509
  * @retval None
509
  * @brief  Disable the Debug Module during SLEEP mode
510
  */
510
  * @retval None
511
void HAL_DBGMCU_DisableDBGSleepMode(void)
511
  */
512
{
512
void HAL_DBGMCU_DisableDBGSleepMode(void)
513
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
513
{
514
}
514
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
515
 
515
}
516
/**
516
 
517
  * @brief  Enable the Debug Module during STOP mode
517
/**
518
  * @retval None
518
  * @brief  Enable the Debug Module during STOP mode
519
  */
519
  * @retval None
520
void HAL_DBGMCU_EnableDBGStopMode(void)
520
  */
521
{
521
void HAL_DBGMCU_EnableDBGStopMode(void)
522
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
522
{
523
}
523
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
524
 
524
}
525
/**
525
 
526
  * @brief  Disable the Debug Module during STOP mode
526
/**
527
  * @retval None
527
  * @brief  Disable the Debug Module during STOP mode
528
  */
528
  * @retval None
529
void HAL_DBGMCU_DisableDBGStopMode(void)
529
  */
530
{
530
void HAL_DBGMCU_DisableDBGStopMode(void)
531
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
531
{
532
}
532
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
533
 
533
}
534
/**
534
 
535
  * @brief  Enable the Debug Module during STANDBY mode
535
/**
536
  * @retval None
536
  * @brief  Enable the Debug Module during STANDBY mode
537
  */
537
  * @retval None
538
void HAL_DBGMCU_EnableDBGStandbyMode(void)
538
  */
539
{
539
void HAL_DBGMCU_EnableDBGStandbyMode(void)
540
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
540
{
541
}
541
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
542
 
542
}
543
/**
543
 
544
  * @brief  Disable the Debug Module during STANDBY mode
544
/**
545
  * @retval None
545
  * @brief  Disable the Debug Module during STANDBY mode
546
  */
546
  * @retval None
547
void HAL_DBGMCU_DisableDBGStandbyMode(void)
547
  */
548
{
548
void HAL_DBGMCU_DisableDBGStandbyMode(void)
549
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
549
{
550
}
550
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
551
 
551
}
552
/**
552
 
553
  * @}
553
/**
554
  */
554
  * @}
555
 
555
  */
556
/**
556
 
557
  * @}
557
/**
558
  */
558
  * @}
559
 
559
  */
560
#endif /* HAL_MODULE_ENABLED */
560
 
561
/**
561
#endif /* HAL_MODULE_ENABLED */
562
  * @}
562
/**
563
  */
563
  * @}
564
 
564
  */
565
/**
565
 
566
  * @}
566
/**
567
  */
567
  * @}
568
 
568
  */
569
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
569
 
-
 
570