Subversion Repositories EDIS_Ignition

Rev

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

Rev 2 Rev 18
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32f1xx_hal.c
3
  * @file    stm32f1xx_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) 2016 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) 2016 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 "stm32f1xx_hal.h"
36
#include "stm32f1xx_hal.h"
37
 
37
 
38
/** @addtogroup STM32F1xx_HAL_Driver
38
/** @addtogroup STM32F1xx_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_Constants HAL Private Constants
52
/** @defgroup HAL_Private_Constants HAL Private Constants
53
  * @{
53
  * @{
54
  */
54
  */
55
/**
55
/**
56
 * @brief STM32F1xx HAL Driver version number V1.1.8
56
 * @brief STM32F1xx HAL Driver version number
57
   */
57
   */
58
#define __STM32F1xx_HAL_VERSION_MAIN   (0x01U) /*!< [31:24] main version */
58
#define __STM32F1xx_HAL_VERSION_MAIN   (0x01U) /*!< [31:24] main version */
59
#define __STM32F1xx_HAL_VERSION_SUB1   (0x01U) /*!< [23:16] sub1 version */
59
#define __STM32F1xx_HAL_VERSION_SUB1   (0x01U) /*!< [23:16] sub1 version */
60
#define __STM32F1xx_HAL_VERSION_SUB2   (0x08U) /*!< [15:8]  sub2 version */
60
#define __STM32F1xx_HAL_VERSION_SUB2   (0x09U) /*!< [15:8]  sub2 version */
61
#define __STM32F1xx_HAL_VERSION_RC     (0x00U) /*!< [7:0]  release candidate */
61
#define __STM32F1xx_HAL_VERSION_RC     (0x00U) /*!< [7:0]  release candidate */
62
#define __STM32F1xx_HAL_VERSION         ((__STM32F1xx_HAL_VERSION_MAIN << 24)\
62
#define __STM32F1xx_HAL_VERSION         ((__STM32F1xx_HAL_VERSION_MAIN << 24)\
63
                                        |(__STM32F1xx_HAL_VERSION_SUB1 << 16)\
63
                                        |(__STM32F1xx_HAL_VERSION_SUB1 << 16)\
64
                                        |(__STM32F1xx_HAL_VERSION_SUB2 << 8 )\
64
                                        |(__STM32F1xx_HAL_VERSION_SUB2 << 8 )\
65
                                        |(__STM32F1xx_HAL_VERSION_RC))
65
                                        |(__STM32F1xx_HAL_VERSION_RC))
66
 
66
 
67
#define IDCODE_DEVID_MASK    0x00000FFFU
67
#define IDCODE_DEVID_MASK    0x00000FFFU
68
 
68
 
69
/**
69
/**
70
  * @}
70
  * @}
71
  */
71
  */
72
 
72
 
73
/* Private macro -------------------------------------------------------------*/
73
/* Private macro -------------------------------------------------------------*/
74
/* Private variables ---------------------------------------------------------*/
74
/* Private variables ---------------------------------------------------------*/
75
 
75
 
76
/** @defgroup HAL_Private_Variables HAL Private Variables
76
/** @defgroup HAL_Private_Variables HAL Private Variables
77
  * @{
77
  * @{
78
  */
78
  */
79
__IO uint32_t uwTick;
79
__IO uint32_t uwTick;
80
uint32_t uwTickPrio   = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
80
uint32_t uwTickPrio   = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
81
HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT;  /* 1KHz */
81
HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT;  /* 1KHz */
82
/**
82
/**
83
  * @}
83
  * @}
84
  */
84
  */
85
/* Private function prototypes -----------------------------------------------*/
85
/* Private function prototypes -----------------------------------------------*/
86
/* Exported functions ---------------------------------------------------------*/
86
/* Exported functions ---------------------------------------------------------*/
87
 
87
 
88
/** @defgroup HAL_Exported_Functions HAL Exported Functions
88
/** @defgroup HAL_Exported_Functions HAL Exported Functions
89
  * @{
89
  * @{
90
  */
90
  */
91
 
91
 
92
/** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions
92
/** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions
93
 *  @brief    Initialization and de-initialization functions
93
 *  @brief    Initialization and de-initialization functions
94
 *
94
 *
95
@verbatim
95
@verbatim
96
 ===============================================================================
96
 ===============================================================================
97
              ##### Initialization and de-initialization functions #####
97
              ##### Initialization and de-initialization functions #####
98
 ===============================================================================
98
 ===============================================================================
99
   [..]  This section provides functions allowing to:
99
   [..]  This section provides functions allowing to:
100
      (+) Initializes the Flash interface, the NVIC allocation and initial clock
100
      (+) Initializes the Flash interface, the NVIC allocation and initial clock
101
          configuration. It initializes the systick also when timeout is needed
101
          configuration. It initializes the systick also when timeout is needed
102
          and the backup domain when enabled.
102
          and the backup domain when enabled.
103
      (+) de-Initializes common part of the HAL.
103
      (+) de-Initializes common part of the HAL.
104
      (+) Configure The time base source to have 1ms time base with a dedicated
104
      (+) Configure The time base source to have 1ms time base with a dedicated
105
          Tick interrupt priority.
105
          Tick interrupt priority.
106
        (++) SysTick timer is used by default as source of time base, but user
106
        (++) SysTick timer is used by default as source of time base, but user
107
             can eventually implement his proper time base source (a general purpose
107
             can eventually implement his proper time base source (a general purpose
108
             timer for example or other time source), keeping in mind that Time base
108
             timer for example or other time source), keeping in mind that Time base
109
             duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
109
             duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
110
             handled in milliseconds basis.
110
             handled in milliseconds basis.
111
        (++) Time base configuration function (HAL_InitTick ()) is called automatically
111
        (++) Time base configuration function (HAL_InitTick ()) is called automatically
112
             at the beginning of the program after reset by HAL_Init() or at any time
112
             at the beginning of the program after reset by HAL_Init() or at any time
113
             when clock is configured, by HAL_RCC_ClockConfig().
113
             when clock is configured, by HAL_RCC_ClockConfig().
114
        (++) Source of time base is configured  to generate interrupts at regular
114
        (++) Source of time base is configured  to generate interrupts at regular
115
             time intervals. Care must be taken if HAL_Delay() is called from a
115
             time intervals. Care must be taken if HAL_Delay() is called from a
116
             peripheral ISR process, the Tick interrupt line must have higher priority
116
             peripheral ISR process, the Tick interrupt line must have higher priority
117
            (numerically lower) than the peripheral interrupt. Otherwise the caller
117
            (numerically lower) than the peripheral interrupt. Otherwise the caller
118
            ISR process will be blocked.
118
            ISR process will be blocked.
119
       (++) functions affecting time base configurations are declared as __weak
119
       (++) functions affecting time base configurations are declared as __weak
120
             to make  override possible  in case of other  implementations in user file.
120
             to make  override possible  in case of other  implementations in user file.
121
@endverbatim
121
@endverbatim
122
  * @{
122
  * @{
123
  */
123
  */
124
 
124
 
125
/**
125
/**
126
  * @brief  This function is used to initialize the HAL Library; it must be the first
126
  * @brief  This function is used to initialize the HAL Library; it must be the first
127
  *         instruction to be executed in the main program (before to call any other
127
  *         instruction to be executed in the main program (before to call any other
128
  *         HAL function), it performs the following:
128
  *         HAL function), it performs the following:
129
  *           Configure the Flash prefetch.
129
  *           Configure the Flash prefetch.
130
  *           Configures the SysTick to generate an interrupt each 1 millisecond,
130
  *           Configures the SysTick to generate an interrupt each 1 millisecond,
131
  *           which is clocked by the HSI (at this stage, the clock is not yet
131
  *           which is clocked by the HSI (at this stage, the clock is not yet
132
  *           configured and thus the system is running from the internal HSI at 16 MHz).
132
  *           configured and thus the system is running from the internal HSI at 16 MHz).
133
  *           Set NVIC Group Priority to 4.
133
  *           Set NVIC Group Priority to 4.
134
  *           Calls the HAL_MspInit() callback function defined in user file
134
  *           Calls the HAL_MspInit() callback function defined in user file
135
  *           "stm32f1xx_hal_msp.c" to do the global low level hardware initialization
135
  *           "stm32f1xx_hal_msp.c" to do the global low level hardware initialization
136
  *
136
  *
137
  * @note   SysTick is used as time base for the HAL_Delay() function, the application
137
  * @note   SysTick is used as time base for the HAL_Delay() function, the application
138
  *         need to ensure that the SysTick time base is always set to 1 millisecond
138
  *         need to ensure that the SysTick time base is always set to 1 millisecond
139
  *         to have correct HAL operation.
139
  *         to have correct HAL operation.
140
  * @retval HAL status
140
  * @retval HAL status
141
  */
141
  */
142
HAL_StatusTypeDef HAL_Init(void)
142
HAL_StatusTypeDef HAL_Init(void)
143
{
143
{
144
  /* Configure Flash prefetch */
144
  /* Configure Flash prefetch */
145
#if (PREFETCH_ENABLE != 0)
145
#if (PREFETCH_ENABLE != 0)
146
#if defined(STM32F101x6) || defined(STM32F101xB) || defined(STM32F101xE) || defined(STM32F101xG) || \
146
#if defined(STM32F101x6) || defined(STM32F101xB) || defined(STM32F101xE) || defined(STM32F101xG) || \
147
    defined(STM32F102x6) || defined(STM32F102xB) || \
147
    defined(STM32F102x6) || defined(STM32F102xB) || \
148
    defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || \
148
    defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || \
149
    defined(STM32F105xC) || defined(STM32F107xC)
149
    defined(STM32F105xC) || defined(STM32F107xC)
150
 
150
 
151
  /* Prefetch buffer is not available on value line devices */
151
  /* Prefetch buffer is not available on value line devices */
152
  __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
152
  __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
153
#endif
153
#endif
154
#endif /* PREFETCH_ENABLE */
154
#endif /* PREFETCH_ENABLE */
155
 
155
 
156
  /* Set Interrupt Group Priority */
156
  /* Set Interrupt Group Priority */
157
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
157
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
158
 
158
 
159
  /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */
159
  /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */
160
  HAL_InitTick(TICK_INT_PRIORITY);
160
  HAL_InitTick(TICK_INT_PRIORITY);
161
 
161
 
162
  /* Init the low level hardware */
162
  /* Init the low level hardware */
163
  HAL_MspInit();
163
  HAL_MspInit();
164
 
164
 
165
  /* Return function status */
165
  /* Return function status */
166
  return HAL_OK;
166
  return HAL_OK;
167
}
167
}
168
 
168
 
169
/**
169
/**
170
  * @brief This function de-Initializes common part of the HAL and stops the systick.
170
  * @brief This function de-Initializes common part of the HAL and stops the systick.
171
  *        of time base.
171
  *        of time base.
172
  * @note This function is optional.
172
  * @note This function is optional.
173
  * @retval HAL status
173
  * @retval HAL status
174
  */
174
  */
175
HAL_StatusTypeDef HAL_DeInit(void)
175
HAL_StatusTypeDef HAL_DeInit(void)
176
{
176
{
177
  /* Reset of all peripherals */
177
  /* Reset of all peripherals */
178
  __HAL_RCC_APB1_FORCE_RESET();
178
  __HAL_RCC_APB1_FORCE_RESET();
179
  __HAL_RCC_APB1_RELEASE_RESET();
179
  __HAL_RCC_APB1_RELEASE_RESET();
180
 
180
 
181
  __HAL_RCC_APB2_FORCE_RESET();
181
  __HAL_RCC_APB2_FORCE_RESET();
182
  __HAL_RCC_APB2_RELEASE_RESET();
182
  __HAL_RCC_APB2_RELEASE_RESET();
183
 
183
 
184
#if defined(STM32F105xC) || defined(STM32F107xC)
184
#if defined(STM32F105xC) || defined(STM32F107xC)
185
  __HAL_RCC_AHB_FORCE_RESET();
185
  __HAL_RCC_AHB_FORCE_RESET();
186
  __HAL_RCC_AHB_RELEASE_RESET();
186
  __HAL_RCC_AHB_RELEASE_RESET();
187
#endif
187
#endif
188
 
188
 
189
  /* De-Init the low level hardware */
189
  /* De-Init the low level hardware */
190
  HAL_MspDeInit();
190
  HAL_MspDeInit();
191
 
191
 
192
  /* Return function status */
192
  /* Return function status */
193
  return HAL_OK;
193
  return HAL_OK;
194
}
194
}
195
 
195
 
196
/**
196
/**
197
  * @brief  Initialize the MSP.
197
  * @brief  Initialize the MSP.
198
  * @retval None
198
  * @retval None
199
  */
199
  */
200
__weak void HAL_MspInit(void)
200
__weak void HAL_MspInit(void)
201
{
201
{
202
  /* NOTE : This function should not be modified, when the callback is needed,
202
  /* NOTE : This function should not be modified, when the callback is needed,
203
            the HAL_MspInit could be implemented in the user file
203
            the HAL_MspInit could be implemented in the user file
204
   */
204
   */
205
}
205
}
206
 
206
 
207
/**
207
/**
208
  * @brief  DeInitializes the MSP.
208
  * @brief  DeInitializes the MSP.
209
  * @retval None
209
  * @retval None
210
  */
210
  */
211
__weak void HAL_MspDeInit(void)
211
__weak void HAL_MspDeInit(void)
212
{
212
{
213
  /* NOTE : This function should not be modified, when the callback is needed,
213
  /* NOTE : This function should not be modified, when the callback is needed,
214
            the HAL_MspDeInit could be implemented in the user file
214
            the HAL_MspDeInit could be implemented in the user file
215
   */
215
   */
216
}
216
}
217
 
217
 
218
/**
218
/**
219
  * @brief This function configures the source of the time base.
219
  * @brief This function configures the source of the time base.
220
  *        The time source is configured  to have 1ms time base with a dedicated
220
  *        The time source is configured  to have 1ms time base with a dedicated
221
  *        Tick interrupt priority.
221
  *        Tick interrupt priority.
222
  * @note This function is called  automatically at the beginning of program after
222
  * @note This function is called  automatically at the beginning of program after
223
  *       reset by HAL_Init() or at any time when clock is reconfigured  by HAL_RCC_ClockConfig().
223
  *       reset by HAL_Init() or at any time when clock is reconfigured  by HAL_RCC_ClockConfig().
224
  * @note In the default implementation, SysTick timer is the source of time base.
224
  * @note In the default implementation, SysTick timer is the source of time base.
225
  *       It is used to generate interrupts at regular time intervals.
225
  *       It is used to generate interrupts at regular time intervals.
226
  *       Care must be taken if HAL_Delay() is called from a peripheral ISR process,
226
  *       Care must be taken if HAL_Delay() is called from a peripheral ISR process,
227
  *       The SysTick interrupt must have higher priority (numerically lower)
227
  *       The SysTick interrupt must have higher priority (numerically lower)
228
  *       than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
228
  *       than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
229
  *       The function is declared as __weak  to be overwritten  in case of other
229
  *       The function is declared as __weak  to be overwritten  in case of other
230
  *       implementation  in user file.
230
  *       implementation  in user file.
231
  * @param TickPriority Tick interrupt priority.
231
  * @param TickPriority Tick interrupt priority.
232
  * @retval HAL status
232
  * @retval HAL status
233
  */
233
  */
234
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
234
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
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
    return HAL_ERROR;
239
    return HAL_ERROR;
240
  }
240
  }
241
 
241
 
242
  /* Configure the SysTick IRQ priority */
242
  /* Configure the SysTick IRQ priority */
243
  if (TickPriority < (1UL << __NVIC_PRIO_BITS))
243
  if (TickPriority < (1UL << __NVIC_PRIO_BITS))
244
  {
244
  {
245
    HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
245
    HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
246
    uwTickPrio = TickPriority;
246
    uwTickPrio = TickPriority;
247
  }
247
  }
248
  else
248
  else
249
  {
249
  {
250
    return HAL_ERROR;
250
    return HAL_ERROR;
251
  }
251
  }
252
 
252
 
253
  /* Return function status */
253
  /* Return function status */
254
  return HAL_OK;
254
  return HAL_OK;
255
}
255
}
256
 
256
 
257
/**
257
/**
258
  * @}
258
  * @}
259
  */
259
  */
260
 
260
 
261
/** @defgroup HAL_Exported_Functions_Group2 HAL Control functions
261
/** @defgroup HAL_Exported_Functions_Group2 HAL Control functions
262
  *  @brief    HAL Control functions
262
  *  @brief    HAL Control functions
263
  *
263
  *
264
@verbatim
264
@verbatim
265
 ===============================================================================
265
 ===============================================================================
266
                      ##### HAL Control functions #####
266
                      ##### HAL Control functions #####
267
 ===============================================================================
267
 ===============================================================================
268
    [..]  This section provides functions allowing to:
268
    [..]  This section provides functions allowing to:
269
      (+) Provide a tick value in millisecond
269
      (+) Provide a tick value in millisecond
270
      (+) Provide a blocking delay in millisecond
270
      (+) Provide a blocking delay in millisecond
271
      (+) Suspend the time base source interrupt
271
      (+) Suspend the time base source interrupt
272
      (+) Resume the time base source interrupt
272
      (+) Resume the time base source interrupt
273
      (+) Get the HAL API driver version
273
      (+) Get the HAL API driver version
274
      (+) Get the device identifier
274
      (+) Get the device identifier
275
      (+) Get the device revision identifier
275
      (+) Get the device revision identifier
276
      (+) Enable/Disable Debug module during SLEEP mode
276
      (+) Enable/Disable Debug module during SLEEP mode
277
      (+) Enable/Disable Debug module during STOP mode
277
      (+) Enable/Disable Debug module during STOP mode
278
      (+) Enable/Disable Debug module during STANDBY mode
278
      (+) Enable/Disable Debug module during STANDBY mode
279
 
279
 
280
@endverbatim
280
@endverbatim
281
  * @{
281
  * @{
282
  */
282
  */
283
 
283
 
284
/**
284
/**
285
  * @brief This function is called to increment  a global variable "uwTick"
285
  * @brief This function is called to increment  a global variable "uwTick"
286
  *        used as application time base.
286
  *        used as application time base.
287
  * @note In the default implementation, this variable is incremented each 1ms
287
  * @note In the default implementation, this variable is incremented each 1ms
288
  *       in SysTick ISR.
288
  *       in SysTick ISR.
289
  * @note This function is declared as __weak to be overwritten in case of other
289
  * @note This function is declared as __weak to be overwritten in case of other
290
  *      implementations in user file.
290
  *      implementations in user file.
291
  * @retval None
291
  * @retval None
292
  */
292
  */
293
__weak void HAL_IncTick(void)
293
__weak void HAL_IncTick(void)
294
{
294
{
295
  uwTick += uwTickFreq;
295
  uwTick += uwTickFreq;
296
}
296
}
297
 
297
 
298
/**
298
/**
299
  * @brief Provides a tick value in millisecond.
299
  * @brief Provides a tick value in millisecond.
300
  * @note  This function is declared as __weak to be overwritten in case of other
300
  * @note  This function is declared as __weak to be overwritten in case of other
301
  *       implementations in user file.
301
  *       implementations in user file.
302
  * @retval tick value
302
  * @retval tick value
303
  */
303
  */
304
__weak uint32_t HAL_GetTick(void)
304
__weak uint32_t HAL_GetTick(void)
305
{
305
{
306
  return uwTick;
306
  return uwTick;
307
}
307
}
308
 
308
 
309
/**
309
/**
310
  * @brief This function returns a tick priority.
310
  * @brief This function returns a tick priority.
311
  * @retval tick priority
311
  * @retval tick priority
312
  */
312
  */
313
uint32_t HAL_GetTickPrio(void)
313
uint32_t HAL_GetTickPrio(void)
314
{
314
{
315
  return uwTickPrio;
315
  return uwTickPrio;
316
}
316
}
317
 
317
 
318
/**
318
/**
319
  * @brief Set new tick Freq.
319
  * @brief Set new tick Freq.
320
  * @retval status
320
  * @retval status
321
  */
321
  */
322
HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
322
HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
323
{
323
{
324
  HAL_StatusTypeDef status  = HAL_OK;
324
  HAL_StatusTypeDef status  = HAL_OK;
325
  HAL_TickFreqTypeDef prevTickFreq;
325
  HAL_TickFreqTypeDef prevTickFreq;
326
 
326
 
327
  assert_param(IS_TICKFREQ(Freq));
327
  assert_param(IS_TICKFREQ(Freq));
328
 
328
 
329
  if (uwTickFreq != Freq)
329
  if (uwTickFreq != Freq)
330
  {
330
  {
331
    /* Back up uwTickFreq frequency */
331
    /* Back up uwTickFreq frequency */
332
    prevTickFreq = uwTickFreq;
332
    prevTickFreq = uwTickFreq;
333
 
333
 
334
    /* Update uwTickFreq global variable used by HAL_InitTick() */
334
    /* Update uwTickFreq global variable used by HAL_InitTick() */
335
    uwTickFreq = Freq;
335
    uwTickFreq = Freq;
336
 
336
 
337
    /* Apply the new tick Freq  */
337
    /* Apply the new tick Freq  */
338
    status = HAL_InitTick(uwTickPrio);
338
    status = HAL_InitTick(uwTickPrio);
339
 
339
 
340
    if (status != HAL_OK)
340
    if (status != HAL_OK)
341
    {
341
    {
342
      /* Restore previous tick frequency */
342
      /* Restore previous tick frequency */
343
      uwTickFreq = prevTickFreq;
343
      uwTickFreq = prevTickFreq;
344
    }
344
    }
345
  }
345
  }
346
 
346
 
347
  return status;
347
  return status;
348
}
348
}
349
 
349
 
350
/**
350
/**
351
  * @brief Return tick frequency.
351
  * @brief Return tick frequency.
352
  * @retval tick period in Hz
352
  * @retval Tick frequency.
353
  */
353
  *         Value of @ref HAL_TickFreqTypeDef.
354
HAL_TickFreqTypeDef HAL_GetTickFreq(void)
354
  */
355
{
355
HAL_TickFreqTypeDef HAL_GetTickFreq(void)
356
  return uwTickFreq;
356
{
357
}
357
  return uwTickFreq;
358
 
358
}
359
/**
359
 
360
  * @brief This function provides minimum delay (in milliseconds) based
360
/**
361
  *        on variable incremented.
361
  * @brief This function provides minimum delay (in milliseconds) based
362
  * @note In the default implementation , SysTick timer is the source of time base.
362
  *        on variable incremented.
363
  *       It is used to generate interrupts at regular time intervals where uwTick
363
  * @note In the default implementation , SysTick timer is the source of time base.
364
  *       is incremented.
364
  *       It is used to generate interrupts at regular time intervals where uwTick
365
  * @note This function is declared as __weak to be overwritten in case of other
365
  *       is incremented.
366
  *       implementations in user file.
366
  * @note This function is declared as __weak to be overwritten in case of other
367
  * @param Delay specifies the delay time length, in milliseconds.
367
  *       implementations in user file.
368
  * @retval None
368
  * @param Delay specifies the delay time length, in milliseconds.
369
  */
369
  * @retval None
370
__weak void HAL_Delay(uint32_t Delay)
370
  */
371
{
371
__weak void HAL_Delay(uint32_t Delay)
372
  uint32_t tickstart = HAL_GetTick();
372
{
373
  uint32_t wait = Delay;
373
  uint32_t tickstart = HAL_GetTick();
374
 
374
  uint32_t wait = Delay;
375
  /* Add a freq to guarantee minimum wait */
375
 
376
  if (wait < HAL_MAX_DELAY)
376
  /* Add a freq to guarantee minimum wait */
377
  {
377
  if (wait < HAL_MAX_DELAY)
378
    wait += (uint32_t)(uwTickFreq);
378
  {
379
  }
379
    wait += (uint32_t)(uwTickFreq);
380
 
380
  }
381
  while ((HAL_GetTick() - tickstart) < wait)
381
 
382
  {
382
  while ((HAL_GetTick() - tickstart) < wait)
383
  }
383
  {
384
}
384
  }
385
 
385
}
386
/**
386
 
387
  * @brief Suspend Tick increment.
387
/**
388
  * @note In the default implementation , SysTick timer is the source of time base. It is
388
  * @brief Suspend Tick increment.
389
  *       used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
389
  * @note In the default implementation , SysTick timer is the source of time base. It is
390
  *       is called, the SysTick interrupt will be disabled and so Tick increment
390
  *       used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
391
  *       is suspended.
391
  *       is called, the SysTick interrupt will be disabled and so Tick increment
392
  * @note This function is declared as __weak to be overwritten in case of other
392
  *       is suspended.
393
  *       implementations in user file.
393
  * @note This function is declared as __weak to be overwritten in case of other
394
  * @retval None
394
  *       implementations in user file.
395
  */
395
  * @retval None
396
__weak void HAL_SuspendTick(void)
396
  */
397
{
397
__weak void HAL_SuspendTick(void)
398
  /* Disable SysTick Interrupt */
398
{
399
  CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
399
  /* Disable SysTick Interrupt */
400
}
400
  CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
401
 
401
}
402
/**
402
 
403
  * @brief Resume Tick increment.
403
/**
404
  * @note In the default implementation , SysTick timer is the source of time base. It is
404
  * @brief Resume Tick increment.
405
  *       used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
405
  * @note In the default implementation , SysTick timer is the source of time base. It is
406
  *       is called, the SysTick interrupt will be enabled and so Tick increment
406
  *       used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
407
  *       is resumed.
407
  *       is called, the SysTick interrupt will be enabled and so Tick increment
408
  * @note This function is declared as __weak to be overwritten in case of other
408
  *       is resumed.
409
  *       implementations in user file.
409
  * @note This function is declared as __weak to be overwritten in case of other
410
  * @retval None
410
  *       implementations in user file.
411
  */
411
  * @retval None
412
__weak void HAL_ResumeTick(void)
412
  */
413
{
413
__weak void HAL_ResumeTick(void)
414
  /* Enable SysTick Interrupt */
414
{
415
  SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
415
  /* Enable SysTick Interrupt */
416
}
416
  SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
417
 
417
}
418
/**
418
 
419
  * @brief  Returns the HAL revision
419
/**
420
  * @retval version 0xXYZR (8bits for each decimal, R for RC)
420
  * @brief  Returns the HAL revision
421
  */
421
  * @retval version 0xXYZR (8bits for each decimal, R for RC)
422
uint32_t HAL_GetHalVersion(void)
422
  */
423
{
423
uint32_t HAL_GetHalVersion(void)
424
  return __STM32F1xx_HAL_VERSION;
424
{
425
}
425
  return __STM32F1xx_HAL_VERSION;
426
 
426
}
427
/**
427
 
428
  * @brief Returns the device revision identifier.
428
/**
429
  * Note: On devices STM32F10xx8 and STM32F10xxB,
429
  * @brief Returns the device revision identifier.
430
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
430
  * Note: On devices STM32F10xx8 and STM32F10xxB,
431
  *                  STM32F101xF/G and STM32F103xF/G
431
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
432
  *                  STM32F10xx4 and STM32F10xx6
432
  *                  STM32F101xF/G and STM32F103xF/G
433
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
433
  *                  STM32F10xx4 and STM32F10xx6
434
  *       debug mode (not accessible by the user software in normal mode).
434
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
435
  *       Refer to errata sheet of these devices for more details.
435
  *       debug mode (not accessible by the user software in normal mode).
436
  * @retval Device revision identifier
436
  *       Refer to errata sheet of these devices for more details.
437
  */
437
  * @retval Device revision identifier
438
uint32_t HAL_GetREVID(void)
438
  */
439
{
439
uint32_t HAL_GetREVID(void)
440
  return ((DBGMCU->IDCODE) >> DBGMCU_IDCODE_REV_ID_Pos);
440
{
441
}
441
  return ((DBGMCU->IDCODE) >> DBGMCU_IDCODE_REV_ID_Pos);
442
 
442
}
443
/**
443
 
444
  * @brief  Returns the device identifier.
444
/**
445
  * Note: On devices STM32F10xx8 and STM32F10xxB,
445
  * @brief  Returns the device identifier.
446
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
446
  * Note: On devices STM32F10xx8 and STM32F10xxB,
447
  *                  STM32F101xF/G and STM32F103xF/G
447
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
448
  *                  STM32F10xx4 and STM32F10xx6
448
  *                  STM32F101xF/G and STM32F103xF/G
449
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
449
  *                  STM32F10xx4 and STM32F10xx6
450
  *       debug mode (not accessible by the user software in normal mode).
450
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
451
  *       Refer to errata sheet of these devices for more details.
451
  *       debug mode (not accessible by the user software in normal mode).
452
  * @retval Device identifier
452
  *       Refer to errata sheet of these devices for more details.
453
  */
453
  * @retval Device identifier
454
uint32_t HAL_GetDEVID(void)
454
  */
455
{
455
uint32_t HAL_GetDEVID(void)
456
  return ((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
456
{
457
}
457
  return ((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
458
 
458
}
459
/**
459
 
460
  * @brief  Returns first word of the unique device identifier (UID based on 96 bits)
460
/**
461
  * @retval Device identifier
461
  * @brief  Returns first word of the unique device identifier (UID based on 96 bits)
462
  */
462
  * @retval Device identifier
463
uint32_t HAL_GetUIDw0(void)
463
  */
464
{
464
uint32_t HAL_GetUIDw0(void)
465
   return(READ_REG(*((uint32_t *)UID_BASE)));
465
{
466
}
466
   return(READ_REG(*((uint32_t *)UID_BASE)));
467
 
467
}
468
/**
468
 
469
  * @brief  Returns second word of the unique device identifier (UID based on 96 bits)
469
/**
470
  * @retval Device identifier
470
  * @brief  Returns second word of the unique device identifier (UID based on 96 bits)
471
  */
471
  * @retval Device identifier
472
uint32_t HAL_GetUIDw1(void)
472
  */
473
{
473
uint32_t HAL_GetUIDw1(void)
474
   return(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
474
{
475
}
475
   return(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
476
 
476
}
477
/**
477
 
478
  * @brief  Returns third word of the unique device identifier (UID based on 96 bits)
478
/**
479
  * @retval Device identifier
479
  * @brief  Returns third word of the unique device identifier (UID based on 96 bits)
480
  */
480
  * @retval Device identifier
481
uint32_t HAL_GetUIDw2(void)
481
  */
482
{
482
uint32_t HAL_GetUIDw2(void)
483
   return(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
483
{
484
}
484
   return(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
485
 
485
}
486
/**
486
 
487
  * @brief  Enable the Debug Module during SLEEP mode
487
/**
488
  * @retval None
488
  * @brief  Enable the Debug Module during SLEEP mode
489
  */
489
  * @retval None
490
void HAL_DBGMCU_EnableDBGSleepMode(void)
490
  */
491
{
491
void HAL_DBGMCU_EnableDBGSleepMode(void)
492
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
492
{
493
}
493
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
494
 
494
}
495
/**
495
 
496
  * @brief  Disable the Debug Module during SLEEP mode
496
/**
497
  * Note: On devices STM32F10xx8 and STM32F10xxB,
497
  * @brief  Disable the Debug Module during SLEEP mode
498
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
498
  * Note: On devices STM32F10xx8 and STM32F10xxB,
499
  *                  STM32F101xF/G and STM32F103xF/G
499
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
500
  *                  STM32F10xx4 and STM32F10xx6
500
  *                  STM32F101xF/G and STM32F103xF/G
501
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
501
  *                  STM32F10xx4 and STM32F10xx6
502
  *       debug mode (not accessible by the user software in normal mode).
502
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
503
  *       Refer to errata sheet of these devices for more details.
503
  *       debug mode (not accessible by the user software in normal mode).
504
  * @retval None
504
  *       Refer to errata sheet of these devices for more details.
505
  */
505
  * @retval None
506
void HAL_DBGMCU_DisableDBGSleepMode(void)
506
  */
507
{
507
void HAL_DBGMCU_DisableDBGSleepMode(void)
508
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
508
{
509
}
509
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
510
 
510
}
511
/**
511
 
512
  * @brief  Enable the Debug Module during STOP mode
512
/**
513
  * Note: On devices STM32F10xx8 and STM32F10xxB,
513
  * @brief  Enable the Debug Module during STOP mode
514
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
514
  * Note: On devices STM32F10xx8 and STM32F10xxB,
515
  *                  STM32F101xF/G and STM32F103xF/G
515
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
516
  *                  STM32F10xx4 and STM32F10xx6
516
  *                  STM32F101xF/G and STM32F103xF/G
517
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
517
  *                  STM32F10xx4 and STM32F10xx6
518
  *       debug mode (not accessible by the user software in normal mode).
518
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
519
  *       Refer to errata sheet of these devices for more details.
519
  *       debug mode (not accessible by the user software in normal mode).
520
  * Note: On all STM32F1 devices:
520
  *       Refer to errata sheet of these devices for more details.
521
  *       If the system tick timer interrupt is enabled during the Stop mode
521
  * Note: On all STM32F1 devices:
522
  *       debug (DBG_STOP bit set in the DBGMCU_CR register ), it will wakeup
522
  *       If the system tick timer interrupt is enabled during the Stop mode
523
  *       the system from Stop mode.
523
  *       debug (DBG_STOP bit set in the DBGMCU_CR register ), it will wakeup
524
  *       Workaround: To debug the Stop mode, disable the system tick timer
524
  *       the system from Stop mode.
525
  *       interrupt.
525
  *       Workaround: To debug the Stop mode, disable the system tick timer
526
  *       Refer to errata sheet of these devices for more details.
526
  *       interrupt.
527
  * Note: On all STM32F1 devices:
527
  *       Refer to errata sheet of these devices for more details.
528
  *       If the system tick timer interrupt is enabled during the Stop mode
528
  * Note: On all STM32F1 devices:
529
  *       debug (DBG_STOP bit set in the DBGMCU_CR register ), it will wakeup
529
  *       If the system tick timer interrupt is enabled during the Stop mode
530
  *       the system from Stop mode.
530
  *       debug (DBG_STOP bit set in the DBGMCU_CR register ), it will wakeup
531
  *       Workaround: To debug the Stop mode, disable the system tick timer
531
  *       the system from Stop mode.
532
  *       interrupt.
532
  *       Workaround: To debug the Stop mode, disable the system tick timer
533
  *       Refer to errata sheet of these devices for more details.
533
  *       interrupt.
534
  * @retval None
534
  *       Refer to errata sheet of these devices for more details.
535
  */
535
  * @retval None
536
void HAL_DBGMCU_EnableDBGStopMode(void)
536
  */
537
{
537
void HAL_DBGMCU_EnableDBGStopMode(void)
538
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
538
{
539
}
539
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
540
 
540
}
541
/**
541
 
542
  * @brief  Disable the Debug Module during STOP mode
542
/**
543
  * Note: On devices STM32F10xx8 and STM32F10xxB,
543
  * @brief  Disable the Debug Module during STOP mode
544
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
544
  * Note: On devices STM32F10xx8 and STM32F10xxB,
545
  *                  STM32F101xF/G and STM32F103xF/G
545
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
546
  *                  STM32F10xx4 and STM32F10xx6
546
  *                  STM32F101xF/G and STM32F103xF/G
547
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
547
  *                  STM32F10xx4 and STM32F10xx6
548
  *       debug mode (not accessible by the user software in normal mode).
548
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
549
  *       Refer to errata sheet of these devices for more details.
549
  *       debug mode (not accessible by the user software in normal mode).
550
  * @retval None
550
  *       Refer to errata sheet of these devices for more details.
551
  */
551
  * @retval None
552
void HAL_DBGMCU_DisableDBGStopMode(void)
552
  */
553
{
553
void HAL_DBGMCU_DisableDBGStopMode(void)
554
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
554
{
555
}
555
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
556
 
556
}
557
/**
557
 
558
  * @brief  Enable the Debug Module during STANDBY mode
558
/**
559
  * Note: On devices STM32F10xx8 and STM32F10xxB,
559
  * @brief  Enable the Debug Module during STANDBY mode
560
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
560
  * Note: On devices STM32F10xx8 and STM32F10xxB,
561
  *                  STM32F101xF/G and STM32F103xF/G
561
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
562
  *                  STM32F10xx4 and STM32F10xx6
562
  *                  STM32F101xF/G and STM32F103xF/G
563
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
563
  *                  STM32F10xx4 and STM32F10xx6
564
  *       debug mode (not accessible by the user software in normal mode).
564
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
565
  *       Refer to errata sheet of these devices for more details.
565
  *       debug mode (not accessible by the user software in normal mode).
566
  * @retval None
566
  *       Refer to errata sheet of these devices for more details.
567
  */
567
  * @retval None
568
void HAL_DBGMCU_EnableDBGStandbyMode(void)
568
  */
569
{
569
void HAL_DBGMCU_EnableDBGStandbyMode(void)
570
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
570
{
571
}
571
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
572
 
572
}
573
/**
573
 
574
  * @brief  Disable the Debug Module during STANDBY mode
574
/**
575
  * Note: On devices STM32F10xx8 and STM32F10xxB,
575
  * @brief  Disable the Debug Module during STANDBY mode
576
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
576
  * Note: On devices STM32F10xx8 and STM32F10xxB,
577
  *                  STM32F101xF/G and STM32F103xF/G
577
  *                  STM32F101xC/D/E and STM32F103xC/D/E,
578
  *                  STM32F10xx4 and STM32F10xx6
578
  *                  STM32F101xF/G and STM32F103xF/G
579
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
579
  *                  STM32F10xx4 and STM32F10xx6
580
  *       debug mode (not accessible by the user software in normal mode).
580
  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
581
  *       Refer to errata sheet of these devices for more details.
581
  *       debug mode (not accessible by the user software in normal mode).
582
  * @retval None
582
  *       Refer to errata sheet of these devices for more details.
583
  */
583
  * @retval None
584
void HAL_DBGMCU_DisableDBGStandbyMode(void)
584
  */
585
{
585
void HAL_DBGMCU_DisableDBGStandbyMode(void)
586
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
586
{
587
}
587
  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
588
 
588
}
589
/**
589
 
590
  * @}
590
/**
591
  */
591
  * @}
592
 
592
  */
593
/**
593
 
594
  * @}
594
/**
595
  */
595
  * @}
596
 
596
  */
597
#endif /* HAL_MODULE_ENABLED */
597
 
598
/**
598
#endif /* HAL_MODULE_ENABLED */
599
  * @}
599
/**
600
  */
600
  * @}
601
 
601
  */
602
/**
602
 
603
  * @}
603
/**
604
  */
604
  * @}
605
 
605
  */
606
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
606
 
-
 
607